2012-07-30 18:22:16 -04:00
|
|
|
module Fog
|
|
|
|
module Compute
|
|
|
|
class RackspaceV2
|
|
|
|
class Real
|
2013-01-30 10:05:10 -05:00
|
|
|
# Create server
|
|
|
|
# @param [String] name name of server
|
2013-03-11 11:05:23 -04:00
|
|
|
# @param [String] image_id of the image used to create server
|
2013-01-30 10:05:10 -05:00
|
|
|
# @param [String] flavor_id id of the flavor of the image
|
|
|
|
# @param [String] min_count
|
|
|
|
# @param [String] max_count
|
|
|
|
# @param [Hash] options
|
|
|
|
# @option options [Hash] metadata key value pairs of server metadata
|
|
|
|
# @option options [String] OS-DCF:diskConfig The disk configuration value. (AUTO or MANUAL)
|
|
|
|
# @option options [Hash] personality Hash containing data to inject into the file system of the cloud server instance during server creation.
|
2013-07-24 07:28:29 -04:00
|
|
|
# @option options [String] keypair Name of the kay-pair to associate with this server.
|
2013-01-30 10:05:10 -05:00
|
|
|
# @return [Excon::Response] response:
|
|
|
|
# * body [Hash]:
|
|
|
|
# * server [Hash]:
|
|
|
|
# * name [String] - name of server
|
|
|
|
# * imageRef [String] - id of image used to create server
|
2013-07-24 07:28:29 -04:00
|
|
|
# * flavorRef [String] - id of flavor used to create server
|
2013-01-30 10:05:10 -05:00
|
|
|
# * OS-DCF:diskConfig [String] - The disk configuration value.
|
|
|
|
# * name [String] - name of server
|
|
|
|
# * metadata [Hash] - Metadata key and value pairs.
|
|
|
|
# * personality [Array]:
|
2013-03-27 10:50:30 -04:00
|
|
|
# * [Hash]:
|
|
|
|
# * path - path of the file created
|
|
|
|
# * contents - Base 64 encoded file contents
|
2013-01-30 10:05:10 -05:00
|
|
|
# * networks [Array]:
|
|
|
|
# * [Hash]:
|
2013-03-27 10:50:30 -04:00
|
|
|
# * uuid [String] - uuid of attached network
|
2013-04-15 14:12:14 -04:00
|
|
|
# @raise [Fog::Compute::RackspaceV2::NotFound] - HTTP 404
|
|
|
|
# @raise [Fog::Compute::RackspaceV2::BadRequest] - HTTP 400
|
|
|
|
# @raise [Fog::Compute::RackspaceV2::InternalServerError] - HTTP 500
|
|
|
|
# @raise [Fog::Compute::RackspaceV2::ServiceError]
|
2013-01-30 10:05:10 -05:00
|
|
|
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/CreateServers.html
|
|
|
|
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Server_Metadata-d1e2529.html
|
|
|
|
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Server_Personality-d1e2543.html
|
|
|
|
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/ch_extensions.html#diskconfig_attribute
|
|
|
|
#
|
|
|
|
# * State Transitions
|
|
|
|
# * BUILD -> ACTIVE
|
|
|
|
# * BUILD -> ERROR (on error)
|
2012-07-30 18:22:16 -04:00
|
|
|
def create_server(name, image_id, flavor_id, min_count, max_count, options = {})
|
|
|
|
data = {
|
|
|
|
'server' => {
|
2013-07-17 03:18:27 -04:00
|
|
|
'name' => name,
|
|
|
|
'imageRef' => image_id,
|
2012-07-30 18:22:16 -04:00
|
|
|
'flavorRef' => flavor_id,
|
2013-07-17 03:18:27 -04:00
|
|
|
'minCount' => min_count,
|
|
|
|
'maxCount' => max_count
|
2012-07-30 18:22:16 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-08 18:16:41 -04:00
|
|
|
data['server']['OS-DCF:diskConfig'] = options[:disk_config] unless options[:disk_config].nil?
|
2012-09-11 12:45:14 -04:00
|
|
|
data['server']['metadata'] = options[:metadata] unless options[:metadata].nil?
|
|
|
|
data['server']['personality'] = options[:personality] unless options[:personality].nil?
|
2013-01-31 22:33:08 -05:00
|
|
|
data['server']['networks'] = options[:networks] || [
|
|
|
|
{ :uuid => '00000000-0000-0000-0000-000000000000' },
|
|
|
|
{ :uuid => '11111111-1111-1111-1111-111111111111' }
|
|
|
|
]
|
2013-07-24 07:28:29 -04:00
|
|
|
data['server']['key_name'] = options[:keypair] unless options[:keypair].nil?
|
2012-07-30 18:22:16 -04:00
|
|
|
|
|
|
|
request(
|
2013-07-17 03:18:27 -04:00
|
|
|
:body => Fog::JSON.encode(data),
|
2012-07-30 18:22:16 -04:00
|
|
|
:expects => [202],
|
2013-07-17 03:18:27 -04:00
|
|
|
:method => 'POST',
|
|
|
|
:path => "servers"
|
2012-07-30 18:22:16 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2013-01-11 16:06:58 -05:00
|
|
|
|
|
|
|
class Mock
|
|
|
|
def create_server(name, image_id, flavor_id, min_count, max_count, options={})
|
2013-01-14 10:03:37 -05:00
|
|
|
server_id = Fog::Rackspace::MockData.uuid
|
|
|
|
public_ip4 = Fog::Rackspace::MockData.ipv4_address
|
|
|
|
public_ip6 = Fog::Rackspace::MockData.ipv6_address
|
|
|
|
private_ip4 = Fog::Rackspace::MockData.ipv4_address
|
|
|
|
private_ip6 = Fog::Rackspace::MockData.ipv6_address
|
2013-01-11 16:06:58 -05:00
|
|
|
admin_pass = Fog::Mock.random_letters(12)
|
|
|
|
|
|
|
|
flavor = self.data[:flavors][flavor_id]
|
|
|
|
image = self.data[:images][image_id]
|
|
|
|
|
|
|
|
server = {
|
|
|
|
"OS-DCF:diskConfig" => "AUTO",
|
|
|
|
"OS-EXT-STS:power_state" => 1,
|
|
|
|
"OS-EXT-STS:task_state" => nil,
|
|
|
|
"OS-EXT-STS:vm_state" => "active",
|
|
|
|
"accessIPv4" => public_ip4,
|
|
|
|
"accessIPv6" => public_ip6,
|
|
|
|
"addresses" => {
|
|
|
|
"private" => [
|
|
|
|
{
|
|
|
|
"addr" => private_ip4,
|
|
|
|
"version" => 4
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"public" => [
|
|
|
|
{
|
|
|
|
"addr" => public_ip4,
|
|
|
|
"version" => 4
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"addr" => public_ip6,
|
|
|
|
"version" => 6
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
"created" => "2012-07-28T15:32:25Z",
|
2013-01-14 10:03:37 -05:00
|
|
|
"flavor" => Fog::Rackspace::MockData.keep(flavor, "id", "links"),
|
2013-01-11 16:06:58 -05:00
|
|
|
"hostId" => Fog::Mock.random_hex(56),
|
|
|
|
"id" => server_id,
|
2013-01-14 10:03:37 -05:00
|
|
|
"image" => Fog::Rackspace::MockData.keep(image, "id", "links"),
|
2013-01-11 16:06:58 -05:00
|
|
|
"links" => [
|
|
|
|
{
|
|
|
|
"href" => "https://dfw.servers.api.rackspacecloud.com/v2/010101/servers/#{server_id}",
|
|
|
|
"rel" => "self",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"href" => "https://dfw.servers.api.rackspacecloud.com/010101/servers/#{server_id}",
|
|
|
|
"rel" => "bookmark",
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"metadata" => {},
|
|
|
|
"name" => name,
|
|
|
|
"progress" => 100,
|
|
|
|
"rax-bandwidth:bandwidth" => [
|
|
|
|
{
|
|
|
|
"audit_period_end" => "2012-08-16T14:12:00Z",
|
|
|
|
"audit_period_start" => "2012-08-16T06:00:00Z",
|
|
|
|
"bandwidth_inbound" => 39147845,
|
|
|
|
"bandwidth_outbound" => 13390651,
|
|
|
|
"interface" => "public",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"audit_period_end" => "2012-08-16T14:12:00Z",
|
|
|
|
"audit_period_start" => "2012-08-16T06:00:00Z",
|
|
|
|
"bandwidth_inbound" => 24229191,
|
|
|
|
"bandwidth_outbound" => 84,
|
|
|
|
"interface" => "private",
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"status" => "ACTIVE",
|
|
|
|
"tenant_id" => "010101",
|
|
|
|
"updated" => "2012-07-28T15:37:09Z",
|
|
|
|
"user_id" => "170454",
|
|
|
|
:volume_ids => [],
|
|
|
|
}
|
|
|
|
|
2013-04-19 10:53:55 -04:00
|
|
|
# add in additional networks
|
2013-04-19 08:59:33 -04:00
|
|
|
if options[:networks]
|
|
|
|
options[:networks].each do |network|
|
|
|
|
net_label = self.data[:networks][network[:uuid]]["label"]
|
|
|
|
server["addresses"] = { net_label => []}
|
|
|
|
end
|
2013-04-18 16:18:26 -04:00
|
|
|
end
|
2013-01-11 16:06:58 -05:00
|
|
|
self.data[:servers][server_id] = server
|
|
|
|
|
|
|
|
response = {
|
|
|
|
"server" => {
|
|
|
|
"OS-DCF:diskConfig" => "AUTO",
|
|
|
|
"adminPass" => admin_pass,
|
|
|
|
"id" => server_id,
|
|
|
|
"links" => [
|
|
|
|
{
|
|
|
|
"href" => "https://dfw.servers.api.rackspacecloud.com/v2/010101/servers/#{server_id}",
|
|
|
|
"rel" => "self"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"href" => "https://dfw.servers.api.rackspacecloud.com/010101/servers/#{server_id}",
|
|
|
|
"rel" => "bookmark"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
response(:body => response)
|
|
|
|
end
|
|
|
|
end
|
2012-07-30 18:22:16 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|