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/compute/requests/rackspace/create_server.rb

95 lines
3.3 KiB
Ruby
Raw Normal View History

module Fog
module Rackspace
class Compute
class Real
2009-10-14 01:36:35 -04:00
# Create a new server
#
# ==== Parameters
# * flavor_id<~Integer> - Id of flavor for server
# * image_id<~Integer> - Id of image for server
# * name<~String> - Name of server
# * options<~Hash>:
# * 'metadata'<~Hash> - Up to 5 key value pairs containing 255 bytes of info
# * 'name'<~String> - Name of server, defaults to "slice#{id}"
# * 'personality'<~Array>: Up to 5 files to customize server
# * file<~Hash>:
# * 'contents'<~String> - Contents of file (10kb total of contents)
# * 'path'<~String> - Path to file (255 bytes total of path strings)
#
# ==== Returns
# * response<~Excon::Response>:
2009-10-14 01:36:35 -04:00
# * body<~Hash>:
# * 'server'<~Hash>:
2009-10-14 01:36:35 -04:00
# * 'addresses'<~Hash>:
# * 'public'<~Array> - public address strings
# * 'private'<~Array> - private address strings
# * 'adminPass'<~String> - Admin password for server
# * 'flavorId'<~Integer> - Id of servers current flavor
# * 'hostId'<~String>
# * 'id'<~Integer> - Id of server
# * 'imageId'<~Integer> - Id of image used to boot server
2009-10-14 01:36:35 -04:00
# * 'metadata'<~Hash> - metadata
# * 'name<~String> - Name of server
# * 'progress'<~Integer> - Progress through current status
# * 'status'<~String> - Current server status
def create_server(flavor_id, image_id, options = {})
2009-10-14 01:36:35 -04:00
data = {
'server' => {
'flavorId' => flavor_id,
'imageId' => image_id
}
}
if options['metadata']
data['server']['metadata'] = options['metadata']
end
if options['name']
data['server']['name'] = options['name']
end
if options['personality']
data['server']['personality'] = []
for file in options['personality']
data['server']['personality'] << {
'contents' => Base64.encode64(file['contents']),
'path' => file['path']
}
end
end
request(
:body => data.to_json,
:expects => 202,
:method => 'POST',
:path => 'servers.json'
)
end
end
class Mock
2009-10-14 01:36:35 -04:00
2010-05-31 11:37:26 -04:00
def create_server(flavor_id, image_id, options = {})
2009-11-20 14:08:08 -05:00
response = Excon::Response.new
2009-11-08 01:29:25 -05:00
response.status = 202
data = {
'addresses' => { 'private' => ['0.0.0.0'], 'public' => ['0.0.0.0'] },
'flavorId' => flavor_id,
'id' => Fog::Mock.random_numbers(6).to_i,
2009-11-08 01:29:25 -05:00
'imageId' => image_id,
'hostId' => "123456789ABCDEF01234567890ABCDEF",
2010-05-31 11:37:26 -04:00
'metadata' => options['metadata'] || {},
'name' => options['name'] || "server_#{rand(999)}",
2009-11-08 01:29:25 -05:00
'progress' => 0,
'status' => 'BUILD'
}
@data[:last_modified][:servers][data['id']] = Time.now
@data[:servers][data['id']] = data
2010-05-31 11:37:26 -04:00
response.body = { 'server' => data.merge({'adminPass' => 'password'}) }
2009-11-08 01:29:25 -05:00
response
2009-10-14 01:36:35 -04:00
end
end
end
end
end