mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[cloudstack|compute] zones,flavors,images,address
This commit is contained in:
parent
e470e6cc66
commit
5e68a7e204
15 changed files with 404 additions and 63 deletions
|
@ -18,8 +18,15 @@ module Fog
|
||||||
|
|
||||||
|
|
||||||
model_path 'fog/cloudstack/models/compute'
|
model_path 'fog/cloudstack/models/compute'
|
||||||
|
model :address
|
||||||
model :server
|
model :server
|
||||||
collection :servers
|
collection :servers
|
||||||
|
model :image
|
||||||
|
collection :images
|
||||||
|
model :flavor
|
||||||
|
collection :flavors
|
||||||
|
model :zone
|
||||||
|
collection :zones
|
||||||
|
|
||||||
request :acquire_ip_address
|
request :acquire_ip_address
|
||||||
request :assign_to_load_balancer_rule
|
request :assign_to_load_balancer_rule
|
||||||
|
@ -45,6 +52,7 @@ module Fog
|
||||||
request :delete_ssh_key_pair
|
request :delete_ssh_key_pair
|
||||||
request :delete_snapshot
|
request :delete_snapshot
|
||||||
request :delete_snapshot_policies
|
request :delete_snapshot_policies
|
||||||
|
request :delete_template
|
||||||
request :delete_user
|
request :delete_user
|
||||||
request :delete_volume
|
request :delete_volume
|
||||||
request :detach_volume
|
request :detach_volume
|
||||||
|
@ -259,8 +267,8 @@ module Fog
|
||||||
@data ||= begin
|
@data ||= begin
|
||||||
rc_options = Fog.credentials[:cloudstack] || {}
|
rc_options = Fog.credentials[:cloudstack] || {}
|
||||||
zone_id = rc_options[:zone_id] ||"c554c592-e09c-9df5-7688-4a32754a4305"
|
zone_id = rc_options[:zone_id] ||"c554c592-e09c-9df5-7688-4a32754a4305"
|
||||||
template_id = rc_options[:template_id] || "8a31cf9c-f248-0588-256e-9dbf58785216"
|
image_id = rc_options[:image_id] || "8a31cf9c-f248-0588-256e-9dbf58785216"
|
||||||
service_offering_id = rc_options[:service_offering_id] || "4437ac6c-9fe3-477a-57ec-60a5a45896a4"
|
flavor_id = rc_options[:flavor_id] || "4437ac6c-9fe3-477a-57ec-60a5a45896a4"
|
||||||
account_id = "8bec6f15-e2b8-44fc-a8f3-a022b2873440"
|
account_id = "8bec6f15-e2b8-44fc-a8f3-a022b2873440"
|
||||||
user_id = Fog::Cloudstack.uuid
|
user_id = Fog::Cloudstack.uuid
|
||||||
domain_id = Fog::Cloudstack.uuid
|
domain_id = Fog::Cloudstack.uuid
|
||||||
|
@ -325,8 +333,8 @@ module Fog
|
||||||
"allocationstate" => "Enabled",
|
"allocationstate" => "Enabled",
|
||||||
"zonetoken" => Fog::Cloudstack.uuid,
|
"zonetoken" => Fog::Cloudstack.uuid,
|
||||||
"dhcpprovider" => "VirtualRouter"}},
|
"dhcpprovider" => "VirtualRouter"}},
|
||||||
:templates => { template_id => {
|
:images => { image_id => {
|
||||||
"id" => template_id,
|
"id" => image_id,
|
||||||
"name" => "CentOS 5.6(64-bit) no GUI (XenServer)",
|
"name" => "CentOS 5.6(64-bit) no GUI (XenServer)",
|
||||||
"displaytext" => "CentOS 5.6(64-bit) no GUI (XenServer)",
|
"displaytext" => "CentOS 5.6(64-bit) no GUI (XenServer)",
|
||||||
"ispublic" => true,
|
"ispublic" => true,
|
||||||
|
@ -348,8 +356,8 @@ module Fog
|
||||||
"domainid" => "6023b6fe-5bef-4358-bc76-9f4e75afa52f",
|
"domainid" => "6023b6fe-5bef-4358-bc76-9f4e75afa52f",
|
||||||
"isextractable" => true,
|
"isextractable" => true,
|
||||||
"checksum" => "905cec879afd9c9d22ecc8036131a180"}},
|
"checksum" => "905cec879afd9c9d22ecc8036131a180"}},
|
||||||
:service_offerings => { service_offering_id => {
|
:flavors => { flavor_id => {
|
||||||
"id" => service_offering_id,
|
"id" => flavor_id,
|
||||||
"name" => "Medium Instance",
|
"name" => "Medium Instance",
|
||||||
"displaytext" => "Medium Instance",
|
"displaytext" => "Medium Instance",
|
||||||
"cpunumber" => 1,
|
"cpunumber" => 1,
|
||||||
|
|
17
lib/fog/cloudstack/models/compute/address.rb
Normal file
17
lib/fog/cloudstack/models/compute/address.rb
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
module Fog
|
||||||
|
module Compute
|
||||||
|
class Cloudstack
|
||||||
|
class Address < Fog::Model
|
||||||
|
identity :id, :aliases => 'id'
|
||||||
|
attribute :network_id, :aliases => 'networkid'
|
||||||
|
attribute :ip_address, :aliases => 'ipaddress'
|
||||||
|
attribute :traffic_type, :aliases => 'traffictype'
|
||||||
|
attribute :is_default, :aliases => 'isdefault'
|
||||||
|
attribute :mac_address, :aliases => 'macaddress'
|
||||||
|
attribute :netmask
|
||||||
|
attribute :gateway
|
||||||
|
attribute :type
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
33
lib/fog/cloudstack/models/compute/flavor.rb
Normal file
33
lib/fog/cloudstack/models/compute/flavor.rb
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
module Fog
|
||||||
|
module Compute
|
||||||
|
class Cloudstack
|
||||||
|
class Flavor < Fog::Model
|
||||||
|
identity :id, :aliases => 'id'
|
||||||
|
attribute :cpu_number, :aliases => 'cpunumber'
|
||||||
|
attribute :cpu_speed, :aliases => 'cpuspeed'
|
||||||
|
attribute :created
|
||||||
|
attribute :default_use, :aliases => 'defaultuse'
|
||||||
|
attribute :display_text, :aliases => 'display_text'
|
||||||
|
attribute :domain
|
||||||
|
attribute :host_tags, :aliases => 'host_tags'
|
||||||
|
attribute :is_system, :aliases => 'is_system'
|
||||||
|
attribute :limit_cpu_use, :aliases => 'limitcpuuse'
|
||||||
|
attribute :tags
|
||||||
|
attribute :system_vm_type, :aliases => 'systemvm'
|
||||||
|
attribute :storage_type, :aliases => 'storagetype'
|
||||||
|
attribute :offer_ha, :aliases => 'offerha'
|
||||||
|
attribute :network_rate, :aliases => 'networkrate'
|
||||||
|
attribute :name
|
||||||
|
attribute :memory
|
||||||
|
|
||||||
|
def save
|
||||||
|
raise Fog::Errors::Error.new('Creating a flavor is not supported')
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
raise Fog::Errors::Error.new('Destroying a flavor is not supported')
|
||||||
|
end
|
||||||
|
end # Server
|
||||||
|
end # Cloudstack
|
||||||
|
end # Compute
|
||||||
|
end # Fog
|
28
lib/fog/cloudstack/models/compute/flavors.rb
Normal file
28
lib/fog/cloudstack/models/compute/flavors.rb
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
require 'fog/core/collection'
|
||||||
|
require 'fog/cloudstack/models/compute/flavor'
|
||||||
|
|
||||||
|
module Fog
|
||||||
|
module Compute
|
||||||
|
class Cloudstack
|
||||||
|
|
||||||
|
class Flavors < Fog::Collection
|
||||||
|
|
||||||
|
model Fog::Compute::Cloudstack::Flavor
|
||||||
|
|
||||||
|
def all
|
||||||
|
data = connection.list_service_offerings["listserviceofferingsresponse"]["serviceoffering"] || []
|
||||||
|
load(data)
|
||||||
|
end
|
||||||
|
|
||||||
|
def get(flavor_id)
|
||||||
|
if flavor = connection.list_service_offerings('id' => flavor_id)["listserviceofferingsresponse"]["serviceoffering"].first
|
||||||
|
new(flavor)
|
||||||
|
end
|
||||||
|
rescue Fog::Compute::Cloudstack::BadRequest
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
72
lib/fog/cloudstack/models/compute/image.rb
Normal file
72
lib/fog/cloudstack/models/compute/image.rb
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
module Fog
|
||||||
|
module Compute
|
||||||
|
class Cloudstack
|
||||||
|
class Image < Fog::Model
|
||||||
|
identity :id, :aliases => 'id'
|
||||||
|
attribute :account
|
||||||
|
attribute :account_id, :aliases => 'accountid'
|
||||||
|
attribute :bootable
|
||||||
|
attribute :checksum
|
||||||
|
attribute :created
|
||||||
|
attribute :cross_zones, :aliases => 'crossZones'
|
||||||
|
attribute :details
|
||||||
|
attribute :display_text, :aliases => 'displaytext'
|
||||||
|
attribute :domain
|
||||||
|
attribute :domain_id, :aliases => 'domainid'
|
||||||
|
attribute :format
|
||||||
|
attribute :host_id, :aliases => 'hostid'
|
||||||
|
attribute :host_name, :aliases => 'hostname'
|
||||||
|
attribute :hypervisor
|
||||||
|
attribute :job_id, :aliases => 'jobid'
|
||||||
|
attribute :job_status, :aliases => 'jobstatus'
|
||||||
|
attribute :is_extractable, :aliases => 'isextractable'
|
||||||
|
attribute :is_featured, :aliases => 'isfeatured'
|
||||||
|
attribute :is_public, :aliases => 'ispublic'
|
||||||
|
attribute :is_ready, :aliases => 'isready'
|
||||||
|
attribute :name
|
||||||
|
attribute :os_type_id, :aliases => 'ostypeid'
|
||||||
|
attribute :os_type_name, :aliases => 'ostypename'
|
||||||
|
attribute :password_enabled, :aliases => 'ostypename'
|
||||||
|
attribute :project
|
||||||
|
attribute :project_id, :aliases => 'projectid'
|
||||||
|
attribute :removed
|
||||||
|
attribute :size
|
||||||
|
attribute :source_template_id, :aliases => 'sourcetemplateid'
|
||||||
|
attribute :status
|
||||||
|
attribute :template_tag, :aliases => 'templatetag'
|
||||||
|
attribute :template_type, :aliases => 'templatetype'
|
||||||
|
attribute :zone_id, :aliases => 'zoneid'
|
||||||
|
attribute :zone_name, :aliases => 'zonename'
|
||||||
|
|
||||||
|
attr_accessor :bits, :requires_hvm, :snapshot_id, :url, :virtual_machine_id, :volume_id
|
||||||
|
|
||||||
|
def save
|
||||||
|
options = {
|
||||||
|
'displaytext' => display_text,
|
||||||
|
'name' => name,
|
||||||
|
'ostypeid' => os_type_id,
|
||||||
|
'bits' => bits,
|
||||||
|
'details' => details,
|
||||||
|
'isfeatured' => is_featured,
|
||||||
|
'ispublic' => is_public,
|
||||||
|
'passwordenabled' => password_enabled,
|
||||||
|
'requireshvm' => requires_hvm,
|
||||||
|
'snapshotid' => snapshot_id,
|
||||||
|
'templatetag' => template_tag,
|
||||||
|
'url' => url,
|
||||||
|
'virtualmachineid' => virtual_machine_id,
|
||||||
|
'volumeid' => volume_id
|
||||||
|
}
|
||||||
|
data = connection.create_template(options)
|
||||||
|
merge_attributes(data['createtemplateresponse'])
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
requires :id
|
||||||
|
connection.delete_template('id' => self.id)
|
||||||
|
true
|
||||||
|
end
|
||||||
|
end # Server
|
||||||
|
end # Cloudstack
|
||||||
|
end # Compute
|
||||||
|
end # Fog
|
32
lib/fog/cloudstack/models/compute/images.rb
Normal file
32
lib/fog/cloudstack/models/compute/images.rb
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
require 'fog/core/collection'
|
||||||
|
require 'fog/cloudstack/models/compute/image'
|
||||||
|
|
||||||
|
module Fog
|
||||||
|
module Compute
|
||||||
|
class Cloudstack
|
||||||
|
|
||||||
|
class Images < Fog::Collection
|
||||||
|
|
||||||
|
model Fog::Compute::Cloudstack::Image
|
||||||
|
|
||||||
|
def all(filters={})
|
||||||
|
options = {
|
||||||
|
'templatefilter' => 'self'
|
||||||
|
}.merge(filters)
|
||||||
|
|
||||||
|
data = connection.list_templates(options)["listtemplatesresponse"]["template"] || []
|
||||||
|
load(data)
|
||||||
|
end
|
||||||
|
|
||||||
|
def get(template_id)
|
||||||
|
if template = connection.list_templates('id' => template_id)["listtemplatesresponse"]["template"].first
|
||||||
|
new(template)
|
||||||
|
end
|
||||||
|
rescue Fog::Compute::Cloudstack::BadRequest
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -4,27 +4,29 @@ module Fog
|
||||||
module Compute
|
module Compute
|
||||||
class Cloudstack
|
class Cloudstack
|
||||||
class Server < Fog::Compute::Server
|
class Server < Fog::Compute::Server
|
||||||
extend Fog::Deprecation
|
|
||||||
identity :id, :aliases => 'id'
|
identity :id, :aliases => 'id'
|
||||||
attribute :name
|
attribute :name
|
||||||
attribute :display_name, :aliases => 'displayname'
|
|
||||||
attribute :account
|
attribute :account
|
||||||
attribute :domain_id, :aliases => 'domainid'
|
|
||||||
attribute :domain
|
attribute :domain
|
||||||
attribute :created
|
attribute :created
|
||||||
attribute :state
|
attribute :state
|
||||||
attribute :haenable
|
attribute :haenable
|
||||||
|
attribute :memory
|
||||||
|
attribute :display_name, :aliases => 'displayname'
|
||||||
|
attribute :domain_id, :aliases => 'domainid'
|
||||||
|
attribute :host_id, :aliases => 'hostid'
|
||||||
|
attribute :host_name, :aliases => 'hostname'
|
||||||
|
attribute :project_id, :aliases => 'projectid'
|
||||||
attribute :zone_id, :aliases => 'zoneid'
|
attribute :zone_id, :aliases => 'zoneid'
|
||||||
attribute :zone_name, :aliases => 'zonename'
|
attribute :zone_name, :aliases => 'zonename'
|
||||||
attribute :template_id, :aliases => 'templateid'
|
attribute :image_id, :aliases => ['templateid', :template_id]
|
||||||
attribute :template_name, :aliases => 'templatename'
|
attribute :image_name, :aliases => ['templatename', :template_name]
|
||||||
attribute :templated_display_text, :aliases => 'templatedisplaytext'
|
attribute :templated_display_text, :aliases => 'templatedisplaytext'
|
||||||
attribute :password_enabled, :aliases => 'passwordenabled'
|
attribute :password_enabled, :aliases => 'passwordenabled'
|
||||||
attribute :service_offering_id, :aliases => 'serviceofferingid'
|
attribute :flavor_id, :aliases => ['serviceofferingid', :service_offering_id]
|
||||||
attribute :service_offering_name, :aliases => 'serviceofferingname'
|
attribute :flavor_name, :aliases => ['serviceofferingname', :service_offering_name]
|
||||||
attribute :cpu_number, :aliases => 'cpunumber'
|
attribute :cpu_number, :aliases => 'cpunumber'
|
||||||
attribute :cpu_speed, :aliases => 'cpuspeed'
|
attribute :cpu_speed, :aliases => 'cpuspeed'
|
||||||
attribute :memory
|
|
||||||
attribute :cpu_used, :aliases => 'cpuused'
|
attribute :cpu_used, :aliases => 'cpuused'
|
||||||
attribute :network_kbs_read, :aliases => 'networkkbsread'
|
attribute :network_kbs_read, :aliases => 'networkkbsread'
|
||||||
attribute :network_kbs_write, :aliases => 'networkkbswrite'
|
attribute :network_kbs_write, :aliases => 'networkkbswrite'
|
||||||
|
@ -34,23 +36,43 @@ module Fog
|
||||||
attribute :security_group, :aliases => 'securitygroup'
|
attribute :security_group, :aliases => 'securitygroup'
|
||||||
attribute :nics, :aliases => 'nic'
|
attribute :nics, :aliases => 'nic'
|
||||||
|
|
||||||
attr_accessor :network_ids
|
attr_accessor :network_ids, :disk_offering_id, :ip_address, :ip_to_network_list
|
||||||
|
|
||||||
def ready?
|
def ready?
|
||||||
true
|
state == 'Running'
|
||||||
end
|
end
|
||||||
|
|
||||||
def save
|
def save
|
||||||
requires :template_id, :service_offering_id, :zone_id
|
requires :image_id, :flavor_id, :zone_id
|
||||||
data = connection.deploy_virtual_machine(
|
|
||||||
:template_id => template_id,
|
options = {
|
||||||
:service_offering_id => service_offering_id,
|
'templateid' => image_id,
|
||||||
:zone_id => zone_id,
|
'serviceofferingid' => flavor_id,
|
||||||
:network_ids => network_ids
|
'zoneid' => zone_id,
|
||||||
)
|
'networkids' => network_ids,
|
||||||
|
'diskofferingid' => disk_offering_id,
|
||||||
|
'displayname' => display_name,
|
||||||
|
'domainid' => domain_id,
|
||||||
|
'hostid' => host_id,
|
||||||
|
'ipaddress' => ip_address,
|
||||||
|
'iptonetworklist' => ip_to_network_list,
|
||||||
|
'projectid' => project_id
|
||||||
|
}
|
||||||
|
|
||||||
|
options.merge!('networkids' => network_ids) if network_ids
|
||||||
|
|
||||||
|
data = connection.deploy_virtual_machine(options)
|
||||||
merge_attributes(data['deployvirtualmachineresponse'])
|
merge_attributes(data['deployvirtualmachineresponse'])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def addresses
|
||||||
|
nics.map{|nic| Address.new(nic)}
|
||||||
|
end
|
||||||
|
|
||||||
|
def flavor
|
||||||
|
connection.flavors.get(self.flavor_id)
|
||||||
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
requires :id
|
requires :id
|
||||||
connection.destroy_virtual_machine(:id => id)
|
connection.destroy_virtual_machine(:id => id)
|
||||||
|
|
|
@ -17,7 +17,6 @@ module Fog
|
||||||
def bootstrap(new_attributes = {})
|
def bootstrap(new_attributes = {})
|
||||||
server = create(new_attributes)
|
server = create(new_attributes)
|
||||||
server.wait_for { ready? }
|
server.wait_for { ready? }
|
||||||
server.setup(:password => server.password)
|
|
||||||
server
|
server
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
39
lib/fog/cloudstack/models/compute/zone.rb
Normal file
39
lib/fog/cloudstack/models/compute/zone.rb
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
module Fog
|
||||||
|
module Compute
|
||||||
|
class Cloudstack
|
||||||
|
class Zone < Fog::Model
|
||||||
|
identity :id, :aliases => 'id'
|
||||||
|
attribute :name
|
||||||
|
attribute :domain_id, :aliases => 'domainid'
|
||||||
|
attribute :domain_name, :aliases => ['domainname', 'domain']
|
||||||
|
attribute :network_type, :aliases => 'networktype'
|
||||||
|
attribute :security_groups_enabled, :aliases => ['securitygroupsenabled', 'securitygroupenabled']
|
||||||
|
attribute :allocation_state, :aliases => 'allocationstate'
|
||||||
|
attribute :zone_token, :aliases => 'zonetoken'
|
||||||
|
attribute :dhcp_provider, :aliases => 'dhcpprovider'
|
||||||
|
|
||||||
|
attr_accessor :dns1, :dns2, :internaldns1, :internaldns2, :guest_cidr_address
|
||||||
|
|
||||||
|
def save
|
||||||
|
options = {
|
||||||
|
'dns1' => dns1,
|
||||||
|
'internaldns1' => internaldns1,
|
||||||
|
'name' => name,
|
||||||
|
'networktype' => network_type,
|
||||||
|
'allocationstate' => allocation_state,
|
||||||
|
'dns2' => dns2,
|
||||||
|
'domain' => domain_name,
|
||||||
|
'domainid' => domain_id,
|
||||||
|
'guestcidraddress' => guest_cidr_address,
|
||||||
|
'internaldns2' => internaldns2,
|
||||||
|
'securitygroupenabled' => security_group_enabled,
|
||||||
|
}
|
||||||
|
data = connection.create_zone(options)
|
||||||
|
merge_attributes(data['createzoneresponse'])
|
||||||
|
end
|
||||||
|
|
||||||
|
end # Zone
|
||||||
|
end # Cloudstack
|
||||||
|
end # Compute
|
||||||
|
end # Fog
|
||||||
|
|
33
lib/fog/cloudstack/models/compute/zones.rb
Normal file
33
lib/fog/cloudstack/models/compute/zones.rb
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
require 'fog/core/collection'
|
||||||
|
require 'fog/cloudstack/models/compute/zone'
|
||||||
|
|
||||||
|
module Fog
|
||||||
|
module Compute
|
||||||
|
class Cloudstack
|
||||||
|
|
||||||
|
class Zones < Fog::Collection
|
||||||
|
|
||||||
|
model Fog::Compute::Cloudstack::Zone
|
||||||
|
|
||||||
|
def all(filters={})
|
||||||
|
options = {
|
||||||
|
'templatefilter' => 'self'
|
||||||
|
}.merge(filters)
|
||||||
|
|
||||||
|
data = connection.list_zones(options)["listzonesresponse"]["zone"] || []
|
||||||
|
load(data)
|
||||||
|
end
|
||||||
|
|
||||||
|
def get(zone_id)
|
||||||
|
if zone = connection.list_zones('id' => zone_id)["listzonesresponse"]["zone"].first
|
||||||
|
new(zone)
|
||||||
|
end
|
||||||
|
rescue Fog::Compute::Cloudstack::BadRequest
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
20
lib/fog/cloudstack/requests/compute/delete_template.rb
Normal file
20
lib/fog/cloudstack/requests/compute/delete_template.rb
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
module Fog
|
||||||
|
module Compute
|
||||||
|
class Cloudstack
|
||||||
|
class Real
|
||||||
|
|
||||||
|
# Deletes a specified template.
|
||||||
|
#
|
||||||
|
# {CloudStack API Reference}[http://http://download.cloud.com/releases/3.0.0/api_3.0.0/user/deleteTemplate.html]
|
||||||
|
def delete_template(options={})
|
||||||
|
options.merge!(
|
||||||
|
'command' => 'deleteTemplate'
|
||||||
|
)
|
||||||
|
|
||||||
|
request(options)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -11,25 +11,18 @@ module Fog
|
||||||
'command' => 'deployVirtualMachine'
|
'command' => 'deployVirtualMachine'
|
||||||
)
|
)
|
||||||
|
|
||||||
security_group_ids = options.delete(:security_group_ids)
|
if security_group_ids = options.delete('securitygroupids')
|
||||||
if security_group_ids
|
|
||||||
options.merge!('securitygroupids' => Array(security_group_ids).join(','))
|
options.merge!('securitygroupids' => Array(security_group_ids).join(','))
|
||||||
end
|
end
|
||||||
|
|
||||||
security_group_names = options.delete(:security_group_names)
|
if security_group_names = options.delete('securitygroupnames')
|
||||||
if security_group_names
|
|
||||||
options.merge!('securitygroupnames' => Array(security_group_names).join(','))
|
options.merge!('securitygroupnames' => Array(security_group_names).join(','))
|
||||||
end
|
end
|
||||||
|
|
||||||
network_ids = options.delete(:network_ids)
|
if network_ids = options.delete('networkids')
|
||||||
if network_ids
|
|
||||||
options.merge!('networkids' => Array(network_ids).join(','))
|
options.merge!('networkids' => Array(network_ids).join(','))
|
||||||
end
|
end
|
||||||
|
|
||||||
options["zoneid"]= options.delete(:zone_id) if options.key?(:zone_id)
|
|
||||||
options["templateid"]= options.delete(:template_id) if options.key?(:template_id)
|
|
||||||
options["serviceofferingid"]= options.delete(:service_offering_id) if options.key?(:service_offering_id)
|
|
||||||
|
|
||||||
request(options)
|
request(options)
|
||||||
end
|
end
|
||||||
end # Real
|
end # Real
|
||||||
|
@ -37,24 +30,24 @@ module Fog
|
||||||
class Mock
|
class Mock
|
||||||
|
|
||||||
def deploy_virtual_machine(options={})
|
def deploy_virtual_machine(options={})
|
||||||
zone_id = options[:zone_id]
|
zone_id = options['zoneid']
|
||||||
unless zone_id
|
unless zone_id
|
||||||
raise Fog::Compute::Cloudstack::BadRequest.new('Unable to execute API command deployvirtualmachine due to missing parameter zoneid')
|
raise Fog::Compute::Cloudstack::BadRequest.new('Unable to execute API command deployvirtualmachine due to missing parameter zoneid')
|
||||||
end
|
end
|
||||||
unless zone = self.data[:zones][zone_id]
|
unless zone = self.data[:zones][zone_id]
|
||||||
raise Fog::Compute::Cloudstack::BadRequest.new("Unable to execute API command deployvirtualmachine due to invalid value. Object networks(uuid: #{zone_id}) does not exist.")
|
raise Fog::Compute::Cloudstack::BadRequest.new("Unable to execute API command deployvirtualmachine due to invalid value. Object zone(uuid: #{zone_id}) does not exist.")
|
||||||
end
|
end
|
||||||
zone_name = zone[:name]
|
zone_name = zone[:name]
|
||||||
|
|
||||||
template_id = options[:template_id]
|
template_id = options['templateid']
|
||||||
unless template = self.data[:templates][options[:template_id]]
|
unless template = self.data[:images][template_id]
|
||||||
raise Fog::Compute::Cloudstack::BadRequest.new('Unable to execute API command deployvirtualmachine due to missing parameter templateid')
|
raise Fog::Compute::Cloudstack::BadRequest.new('Unable to execute API command deployvirtualmachine due to missing parameter templateid')
|
||||||
end
|
end
|
||||||
template_name = template[:name]
|
template_name = template[:name]
|
||||||
template_display_text = template[:display_text]
|
template_display_text = template[:display_text]
|
||||||
|
|
||||||
service_offering_id = options[:service_offering_id]
|
service_offering_id = options['serviceofferingid']
|
||||||
unless service_offering = self.data[:service_offerings][options[:service_offering_id]]
|
unless service_offering = self.data[:flavors][service_offering_id]
|
||||||
raise Fog::Compute::Cloudstack::BadRequest.new('Unable to execute API command deployvirtualmachine due to missing parameter serviceofferingid')
|
raise Fog::Compute::Cloudstack::BadRequest.new('Unable to execute API command deployvirtualmachine due to missing parameter serviceofferingid')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -64,11 +57,11 @@ module Fog
|
||||||
service_offering_memory = service_offering[:cpumemory]
|
service_offering_memory = service_offering[:cpumemory]
|
||||||
|
|
||||||
identity = Fog::Cloudstack.uuid
|
identity = Fog::Cloudstack.uuid
|
||||||
name = options[:name] || Fog::Cloudstack.uuid
|
name = options['name'] || Fog::Cloudstack.uuid
|
||||||
display_name = options[:display_name] || name
|
display_name = options['displayname'] || name
|
||||||
account_name = options[:account] || self.data[:accounts].first[1]["name"]
|
account_name = options['account'] || self.data[:accounts].first[1]["name"]
|
||||||
|
|
||||||
domain = options[:domain_id] ? self.data[:domains][options[:domain_id]] : self.data[:domains].first[1]
|
domain = options['domainid'] ? self.data[:domains][options['domainid']] : self.data[:domains].first[1]
|
||||||
domain_id = domain[:id]
|
domain_id = domain[:id]
|
||||||
domain_name = domain[:name]
|
domain_name = domain[:name]
|
||||||
|
|
||||||
|
@ -78,9 +71,9 @@ module Fog
|
||||||
|
|
||||||
guest_os_id = Fog::Cloudstack.uuid
|
guest_os_id = Fog::Cloudstack.uuid
|
||||||
|
|
||||||
security_group_ids = options[:security_group_ids] || [] # TODO: for now
|
security_group_ids = options['securitygroupids'] || [] # TODO: for now
|
||||||
|
|
||||||
network_ids = Array(options[:network_ids]) || [self.data[:networks].first[1]["id"]]
|
network_ids = Array(options['networkids']) || [self.data[:networks].first[1]["id"]]
|
||||||
networks = network_ids.map{|nid| self.data[:networks][nid]}
|
networks = network_ids.map{|nid| self.data[:networks][nid]}
|
||||||
nic = networks.map do |network|
|
nic = networks.map do |network|
|
||||||
{
|
{
|
||||||
|
@ -126,6 +119,7 @@ module Fog
|
||||||
"securitygroup" => security_group_ids, # TODO: mayhaps?
|
"securitygroup" => security_group_ids, # TODO: mayhaps?
|
||||||
"nic" => nic
|
"nic" => nic
|
||||||
}
|
}
|
||||||
|
|
||||||
self.data[:servers][identity]= virtual_machine
|
self.data[:servers][identity]= virtual_machine
|
||||||
{'deployvirtualmachineresponse' => virtual_machine}
|
{'deployvirtualmachineresponse' => virtual_machine}
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,7 +14,22 @@ module Fog
|
||||||
request(options)
|
request(options)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end # Real
|
||||||
end
|
|
||||||
end
|
class Mock
|
||||||
end
|
|
||||||
|
def list_service_offerings(options={})
|
||||||
|
flavors = self.data[:flavors].values
|
||||||
|
|
||||||
|
{
|
||||||
|
"listserviceofferingsresponse" =>
|
||||||
|
{
|
||||||
|
"count" => flavors.size,
|
||||||
|
"serviceoffering"=> flavors
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end # Mock
|
||||||
|
end # Cloudstack
|
||||||
|
end # Compute
|
||||||
|
end # Fog
|
||||||
|
|
|
@ -14,7 +14,22 @@ module Fog
|
||||||
request(options)
|
request(options)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end # Real
|
||||||
end
|
|
||||||
end
|
class Mock
|
||||||
end
|
|
||||||
|
def list_templates(options={})
|
||||||
|
templates = self.data[:images].values
|
||||||
|
|
||||||
|
{
|
||||||
|
"listtemplatesresponse" =>
|
||||||
|
{
|
||||||
|
"count" => templates.size,
|
||||||
|
"template"=> templates
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end # Mock
|
||||||
|
end # Cloudstack
|
||||||
|
end # Compute
|
||||||
|
end # Fog
|
||||||
|
|
|
@ -14,7 +14,21 @@ module Fog
|
||||||
request(options)
|
request(options)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end # Real
|
||||||
end
|
|
||||||
end
|
class Mock
|
||||||
end
|
def list_zones(options={})
|
||||||
|
zones = self.data[:zones].values
|
||||||
|
|
||||||
|
{
|
||||||
|
"listzonesresponse"=>
|
||||||
|
{
|
||||||
|
"count" => zones.size,
|
||||||
|
"zone" => zones
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end # Mock
|
||||||
|
end # Cloudstack
|
||||||
|
end # Compute
|
||||||
|
end # Fog
|
||||||
|
|
Loading…
Add table
Reference in a new issue