1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/ibm/requests/compute/create_instance.rb

79 lines
3.5 KiB
Ruby

module Fog
module Compute
class IBM
class Real
# Requests a new Instance to be created.
#
# ==== Parameters
# * name<~String> - The alias to use to reference this instance
# * image_id<~String> - The id of the image to create this instance from
# * instance_type<~String> - The instance type to use for this instance
# * location<~String> - The id of the Location where this instance will be created
# * options<~Hash>:
# * :key_name<~String> - The public key to use for accessing the created instance
# * :ip<~String> - The ID of a static IP address to associate with this instance
# * :volume_id<~String> - The ID of a storage volume to associate with this instance
# * :vlan_id<~String> - The ID of a Vlan offering to associate with this instance.
# * :secondary_ip<~String> - The ID of a static IP address to associate with this instance as secondary IP
# * :is_mini_ephermal<~Boolean> - Whether or not the instance should be provisioned with the root segment only
# * :configuration_data<~Hash> - Arbitrary name/value pairs defined by the image being created
# * :anti_collocation_instance<~String> - The ID of an existing anti-collocated instance.
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'name'<~String>: instance name
# * 'location'<~String>: instance location id
# * 'keyName'<~String>: instance assigned keypair
# * 'primaryIP'<~Hash>: assigned ip address, type, and hostname
# * 'productCodes'<~Array>: associated product codes
# * 'requestId'<~String>:
# * 'imageId'<~String>:
# * 'launchTime'<~Integer>: epoch time in ms representing when the instance was launched
def create_instance(name, image_id, instance_type, location, options={})
request(
:method => 'POST',
:expects => 200,
:path => '/instances',
:body => {
'name' => name,
'imageID' => image_id,
'instanceType' => instance_type,
'location' => location,
'publicKey' => options[:key_name],
'ip' => options[:ip],
'volumeID' => options[:volume_id],
'vlanID' => options[:vlan_id],
'SecondaryIP' => options[:secondary_ip],
'isMiniEphemermal' => options[:is_mini_ephemeral],
'Configuration Data' => options[:configuration_data],
'antiCollocationInstance' => options[:anti_collocation_instance],
}
)
end
end
class Mock
def create_instance(name, image_id, instance_type, location, options={})
response = Excon::Response.new
# Since we want to test error conditions, we have a little regex that traps specially formed
# instance type strings.
case name
when /FAIL:\ (\d{3})/
response.status = $1
else
instance = Fog::IBM::Mock.create_instance(name, image_id, instance_type, location, options)
self.data[:instances][instance['id']] = instance
response.status = 200
response.body = {"instances" => [ instance ]}
end
response
end
end
end
end
end