2010-03-19 21:29:42 -04:00
|
|
|
module Fog
|
|
|
|
module Rackspace
|
2010-09-08 16:50:23 -04:00
|
|
|
class Compute
|
2010-03-19 21:29:42 -04:00
|
|
|
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
|
2009-11-02 21:48:49 -05:00
|
|
|
# * response<~Excon::Response>:
|
2009-10-14 01:36:35 -04:00
|
|
|
# * body<~Hash>:
|
2009-10-18 21:11:19 -04:00
|
|
|
# * 'server'<~Hash>:
|
2009-10-14 01:36:35 -04:00
|
|
|
# * 'addresses'<~Hash>:
|
|
|
|
# * 'public'<~Array> - public address strings
|
|
|
|
# * 'private'<~Array> - private address strings
|
2009-10-18 21:11:19 -04:00
|
|
|
# * '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
|
2009-10-18 21:11:19 -04:00
|
|
|
# * 'name<~String> - Name of server
|
|
|
|
# * 'progress'<~Integer> - Progress through current status
|
|
|
|
# * 'status'<~String> - Current server status
|
2010-05-02 22:45:40 -04:00
|
|
|
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
|
|
|
|
|
2010-03-19 21:29:42 -04:00
|
|
|
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,
|
2011-01-04 14:38:14 -05:00
|
|
|
'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'
|
|
|
|
}
|
2010-03-19 21:29:42 -04:00
|
|
|
@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
|