mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[ninefold|compute] Core model functionality.
This commit is contained in:
parent
0b3630f124
commit
c42a272fc0
7 changed files with 345 additions and 7 deletions
29
lib/fog/compute/models/ninefold/flavor.rb
Normal file
29
lib/fog/compute/models/ninefold/flavor.rb
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
require 'fog/core/model'
|
||||||
|
|
||||||
|
module Fog
|
||||||
|
module Ninefold
|
||||||
|
class Compute
|
||||||
|
|
||||||
|
class Flavor < Fog::Model
|
||||||
|
|
||||||
|
identity :id
|
||||||
|
|
||||||
|
attribute :cpunumber
|
||||||
|
attribute :cpuspeed
|
||||||
|
attribute :created, :type => :time
|
||||||
|
attribute :displaytext
|
||||||
|
attribute :domain
|
||||||
|
attribute :domainid
|
||||||
|
attribute :hosttags
|
||||||
|
attribute :memory
|
||||||
|
attribute :name
|
||||||
|
attribute :offerha
|
||||||
|
attribute :storagetype
|
||||||
|
attribute :tags
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
30
lib/fog/compute/models/ninefold/flavors.rb
Normal file
30
lib/fog/compute/models/ninefold/flavors.rb
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
require 'fog/core/collection'
|
||||||
|
require 'fog/compute/models/ninefold/flavor'
|
||||||
|
|
||||||
|
module Fog
|
||||||
|
module Ninefold
|
||||||
|
class Compute
|
||||||
|
|
||||||
|
class Flavors < Fog::Collection
|
||||||
|
|
||||||
|
model Fog::Ninefold::Compute::Flavor
|
||||||
|
|
||||||
|
def all
|
||||||
|
data = connection.list_service_offerings
|
||||||
|
load(data)
|
||||||
|
end
|
||||||
|
|
||||||
|
def get(identifier)
|
||||||
|
data = connection.list_service_offerings(:id => identifier)
|
||||||
|
if data.empty?
|
||||||
|
nil
|
||||||
|
else
|
||||||
|
new(data[0])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
42
lib/fog/compute/models/ninefold/image.rb
Normal file
42
lib/fog/compute/models/ninefold/image.rb
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
require 'fog/core/model'
|
||||||
|
|
||||||
|
module Fog
|
||||||
|
module Ninefold
|
||||||
|
class Compute
|
||||||
|
|
||||||
|
class Image < Fog::Model
|
||||||
|
|
||||||
|
identity :id
|
||||||
|
|
||||||
|
attribute :account
|
||||||
|
attribute :accountid
|
||||||
|
attribute :bootable
|
||||||
|
attribute :created, :type => :time
|
||||||
|
attribute :crossZones
|
||||||
|
attribute :displaytext
|
||||||
|
attribute :domain
|
||||||
|
attribute :domainid
|
||||||
|
attribute :format
|
||||||
|
attribute :hypervisor
|
||||||
|
attribute :isextractable
|
||||||
|
attribute :isfeatured
|
||||||
|
attribute :ispublic
|
||||||
|
attribute :isready
|
||||||
|
attribute :jobid
|
||||||
|
attribute :jobstatus
|
||||||
|
attribute :name
|
||||||
|
attribute :ostypeid
|
||||||
|
attribute :ostypename
|
||||||
|
attribute :passwordenabled
|
||||||
|
attribute :removed
|
||||||
|
attribute :size
|
||||||
|
attribute :status
|
||||||
|
attribute :templatetype
|
||||||
|
attribute :zoneid
|
||||||
|
attribute :zonename
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
30
lib/fog/compute/models/ninefold/images.rb
Normal file
30
lib/fog/compute/models/ninefold/images.rb
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
require 'fog/core/collection'
|
||||||
|
require 'fog/compute/models/ninefold/image'
|
||||||
|
|
||||||
|
module Fog
|
||||||
|
module Ninefold
|
||||||
|
class Compute
|
||||||
|
|
||||||
|
class Images < Fog::Collection
|
||||||
|
|
||||||
|
model Fog::Ninefold::Compute::Image
|
||||||
|
|
||||||
|
def all(offering = 'executable')
|
||||||
|
data = connection.list_templates(:templatefilter => offering)
|
||||||
|
load(data)
|
||||||
|
end
|
||||||
|
|
||||||
|
def get(identifier, offering = 'executable')
|
||||||
|
data = connection.list_templates(:templatefilter => offering, :id => identifier)
|
||||||
|
if data.empty?
|
||||||
|
nil
|
||||||
|
else
|
||||||
|
new(data[0])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
177
lib/fog/compute/models/ninefold/server.rb
Normal file
177
lib/fog/compute/models/ninefold/server.rb
Normal file
|
@ -0,0 +1,177 @@
|
||||||
|
require 'fog/core/model'
|
||||||
|
|
||||||
|
module Fog
|
||||||
|
module Ninefold
|
||||||
|
class Compute
|
||||||
|
|
||||||
|
class Server < Fog::Model
|
||||||
|
|
||||||
|
identity :id
|
||||||
|
|
||||||
|
attribute :account
|
||||||
|
attribute :cpunumber
|
||||||
|
attribute :cpuspeed
|
||||||
|
|
||||||
|
attribute :cpuused
|
||||||
|
attribute :created, :type => :time
|
||||||
|
attribute :displayname
|
||||||
|
attribute :domain
|
||||||
|
attribute :domainid
|
||||||
|
attribute :forvirtualnetwork
|
||||||
|
attribute :group
|
||||||
|
attribute :groupid
|
||||||
|
attribute :guestosid
|
||||||
|
attribute :haenable
|
||||||
|
attribute :hostid
|
||||||
|
attribute :hostname
|
||||||
|
attribute :hypervisor
|
||||||
|
#attribute :ipaddress
|
||||||
|
attribute :isodisplaytext
|
||||||
|
attribute :isoid
|
||||||
|
attribute :isoname
|
||||||
|
attribute :jobid
|
||||||
|
attribute :jobstatus
|
||||||
|
attribute :memory
|
||||||
|
attribute :name
|
||||||
|
attribute :networkkbsread
|
||||||
|
attribute :networkkbswrite
|
||||||
|
attribute :password
|
||||||
|
attribute :passwordenabled
|
||||||
|
attribute :rootdeviceid
|
||||||
|
attribute :rootdevicetype
|
||||||
|
attribute :serviceofferingid
|
||||||
|
attribute :serviceofferingname
|
||||||
|
attribute :state
|
||||||
|
attribute :templatedisplaytext
|
||||||
|
attribute :templateid
|
||||||
|
attribute :templatename
|
||||||
|
attribute :zoneid
|
||||||
|
attribute :zonename
|
||||||
|
attribute :nic
|
||||||
|
attribute :securitygroup
|
||||||
|
|
||||||
|
# used for creation only.
|
||||||
|
attribute :networkids
|
||||||
|
attribute :diskofferingid
|
||||||
|
attribute :keypair
|
||||||
|
attribute :securitygroupids
|
||||||
|
attribute :size
|
||||||
|
attribute :userdata
|
||||||
|
|
||||||
|
#attribute :account_id, :aliases => "account", :squash => "id"
|
||||||
|
#attribute :image_id, :aliases => "image", :squash => "id"
|
||||||
|
#attribute :flavor_id, :aliases => "server_type", :squash => "id"
|
||||||
|
#attribute :zone_id, :aliases => "zone", :squash => "id"
|
||||||
|
|
||||||
|
|
||||||
|
def initialize(attributes={})
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
|
# This is temporary - we need to model nics.
|
||||||
|
def ipaddress
|
||||||
|
nic[0] ? nic[0]['ipaddress'] : nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def reboot
|
||||||
|
requires :identity
|
||||||
|
self.jobid = extract_job_id(connection.reboot_virtual_machine(:id => identity))
|
||||||
|
puts "jobid: " + jobid.to_s
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
def start
|
||||||
|
requires :identity
|
||||||
|
self.jobid = extract_job_id(connection.start_virtual_machine(:id => identity))
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
def stop
|
||||||
|
requires :identity
|
||||||
|
self.jobid = extract_job_id(connection.stop_virtual_machine(:id => identity))
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
requires :identity
|
||||||
|
self.jobid = extract_job_id(connection.destroy_virtual_machine(:id => identity))
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
def flavor
|
||||||
|
requires :serviceofferingid
|
||||||
|
connection.flavors.get(serviceofferingid)
|
||||||
|
end
|
||||||
|
|
||||||
|
def image
|
||||||
|
requires :templateid
|
||||||
|
connection.images.get(templateid)
|
||||||
|
end
|
||||||
|
|
||||||
|
def ready?
|
||||||
|
if jobid
|
||||||
|
# we do this by polling the last job id status.
|
||||||
|
res = connection.query_async_job_result(:jobid => jobid)
|
||||||
|
if res['jobstatus'] == 0
|
||||||
|
false
|
||||||
|
else
|
||||||
|
# update with new values.
|
||||||
|
merge_attributes(res['jobresult']['virtualmachine'])
|
||||||
|
end
|
||||||
|
else # No running job, we are ready. Refresh data.
|
||||||
|
reload
|
||||||
|
true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def save
|
||||||
|
requires :serviceofferingid
|
||||||
|
requires :templateid
|
||||||
|
requires :zoneid
|
||||||
|
|
||||||
|
unless networkids
|
||||||
|
# No network specified, use first in this zone.
|
||||||
|
networks = connection.list_networks(:zoneid => zoneid)
|
||||||
|
if networks.empty?
|
||||||
|
raise "No networks. Please create one, or specify a network ID"
|
||||||
|
else
|
||||||
|
networkids = networks[0]['id']
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
options = {
|
||||||
|
:serviceofferingid => serviceofferingid,
|
||||||
|
:templateid => templateid,
|
||||||
|
:name => name,
|
||||||
|
:zoneid => zoneid,
|
||||||
|
:networkids => networkids,
|
||||||
|
:account => account,
|
||||||
|
:diskofferingid => diskofferingid,
|
||||||
|
:displayname => displayname,
|
||||||
|
:domainid => domainid,
|
||||||
|
:group => group,
|
||||||
|
:hypervisor => hypervisor,
|
||||||
|
:keypair => keypair,
|
||||||
|
:securitygroupids => securitygroupids,
|
||||||
|
:size => size,
|
||||||
|
:userdata => userdata
|
||||||
|
}.delete_if {|k,v| v.nil? || v == "" }
|
||||||
|
data = connection.deploy_virtual_machine(options)
|
||||||
|
merge_attributes(data)
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def extract_job_id(job)
|
||||||
|
if job.kind_of? Integer
|
||||||
|
job
|
||||||
|
else
|
||||||
|
job['jobid'] || job['id']
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
31
lib/fog/compute/models/ninefold/servers.rb
Normal file
31
lib/fog/compute/models/ninefold/servers.rb
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
require 'fog/core/collection'
|
||||||
|
require 'fog/compute/models/ninefold/server'
|
||||||
|
|
||||||
|
module Fog
|
||||||
|
module Ninefold
|
||||||
|
class Compute
|
||||||
|
|
||||||
|
class Servers < Fog::Collection
|
||||||
|
|
||||||
|
model Fog::Ninefold::Compute::Server
|
||||||
|
|
||||||
|
def all
|
||||||
|
data = connection.list_virtual_machines
|
||||||
|
load(data)
|
||||||
|
end
|
||||||
|
|
||||||
|
def get(identifier)
|
||||||
|
return nil if identifier.nil? || identifier == ""
|
||||||
|
data = connection.list_virtual_machines(:id => identifier)
|
||||||
|
if data.empty?
|
||||||
|
nil
|
||||||
|
else
|
||||||
|
new(data[0])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -5,16 +5,15 @@ module Fog
|
||||||
API_URL = "http://api.ninefold.com/compute/v1.0/"
|
API_URL = "http://api.ninefold.com/compute/v1.0/"
|
||||||
|
|
||||||
requires :ninefold_compute_key, :ninefold_compute_secret
|
requires :ninefold_compute_key, :ninefold_compute_secret
|
||||||
#recognizes :brightbox_auth_url, :brightbox_api_url
|
|
||||||
recognizes :provider # remove post deprecation
|
recognizes :provider # remove post deprecation
|
||||||
|
|
||||||
model_path 'fog/compute/models/ninefold'
|
model_path 'fog/compute/models/ninefold'
|
||||||
#collection :servers
|
model :server
|
||||||
#model :server
|
collection :servers
|
||||||
#collection :flavors
|
model :flavor
|
||||||
#model :flavor
|
collection :flavors
|
||||||
#collection :images
|
model :image
|
||||||
#model :image
|
collection :images
|
||||||
#collection :load_balancers
|
#collection :load_balancers
|
||||||
#model :load_balancer
|
#model :load_balancer
|
||||||
#collection :zones
|
#collection :zones
|
||||||
|
|
Loading…
Add table
Reference in a new issue