mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Add implementation for #create_server service.
This commit is contained in:
parent
6cf4498fd2
commit
8687c2ebc6
1 changed files with 94 additions and 0 deletions
94
lib/fog/compute/requests/hp/create_server.rb
Normal file
94
lib/fog/compute/requests/hp/create_server.rb
Normal file
|
@ -0,0 +1,94 @@
|
|||
module Fog
|
||||
module HP
|
||||
class Compute
|
||||
class Real
|
||||
|
||||
# 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>:
|
||||
# * body<~Hash>:
|
||||
# * 'server'<~Hash>:
|
||||
# * '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
|
||||
# * '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 = {})
|
||||
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
|
||||
|
||||
def create_server(flavor_id, image_id, options = {})
|
||||
response = Excon::Response.new
|
||||
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,
|
||||
'imageId' => image_id,
|
||||
'hostId' => "123456789ABCDEF01234567890ABCDEF",
|
||||
'metadata' => options['metadata'] || {},
|
||||
'name' => options['name'] || "server_#{rand(999)}",
|
||||
'progress' => 0,
|
||||
'status' => 'BUILD'
|
||||
}
|
||||
self.data[:last_modified][:servers][data['id']] = Time.now
|
||||
self.data[:servers][data['id']] = data
|
||||
response.body = { 'server' => data.merge({'adminPass' => 'password'}) }
|
||||
response
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue