diff --git a/lib/fog/compute/models/ninefold/flavor.rb b/lib/fog/compute/models/ninefold/flavor.rb new file mode 100644 index 000000000..e95a6223c --- /dev/null +++ b/lib/fog/compute/models/ninefold/flavor.rb @@ -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 diff --git a/lib/fog/compute/models/ninefold/flavors.rb b/lib/fog/compute/models/ninefold/flavors.rb new file mode 100644 index 000000000..7e60ecbb1 --- /dev/null +++ b/lib/fog/compute/models/ninefold/flavors.rb @@ -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 diff --git a/lib/fog/compute/models/ninefold/image.rb b/lib/fog/compute/models/ninefold/image.rb new file mode 100644 index 000000000..e6a1b66ae --- /dev/null +++ b/lib/fog/compute/models/ninefold/image.rb @@ -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 diff --git a/lib/fog/compute/models/ninefold/images.rb b/lib/fog/compute/models/ninefold/images.rb new file mode 100644 index 000000000..021ac5371 --- /dev/null +++ b/lib/fog/compute/models/ninefold/images.rb @@ -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 diff --git a/lib/fog/compute/models/ninefold/server.rb b/lib/fog/compute/models/ninefold/server.rb new file mode 100644 index 000000000..9bf945dd4 --- /dev/null +++ b/lib/fog/compute/models/ninefold/server.rb @@ -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 diff --git a/lib/fog/compute/models/ninefold/servers.rb b/lib/fog/compute/models/ninefold/servers.rb new file mode 100644 index 000000000..6aa98afca --- /dev/null +++ b/lib/fog/compute/models/ninefold/servers.rb @@ -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 diff --git a/lib/fog/compute/ninefold.rb b/lib/fog/compute/ninefold.rb index 1262cbfee..a08acb89d 100644 --- a/lib/fog/compute/ninefold.rb +++ b/lib/fog/compute/ninefold.rb @@ -5,16 +5,15 @@ module Fog API_URL = "http://api.ninefold.com/compute/v1.0/" requires :ninefold_compute_key, :ninefold_compute_secret - #recognizes :brightbox_auth_url, :brightbox_api_url recognizes :provider # remove post deprecation model_path 'fog/compute/models/ninefold' - #collection :servers - #model :server - #collection :flavors - #model :flavor - #collection :images - #model :image + model :server + collection :servers + model :flavor + collection :flavors + model :image + collection :images #collection :load_balancers #model :load_balancer #collection :zones