1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Add implementation for #server_action, #reboot_server, #resize_server, #confirm_resized_server and #revert_resized services.

This commit is contained in:
Rupak Ganguly 2011-06-23 19:25:25 -04:00
parent f1dff717aa
commit 71c42f80e5
5 changed files with 163 additions and 0 deletions

View file

@ -0,0 +1,34 @@
module Fog
module HP
class Compute
class Real
# Confirm resizing
#
# ==== Parameters
# * server_id<~Integer> - Id of server to confirm
#
def confirm_resized_server(server_id)
body = { 'confirmResize' => nil }
server_action(server_id, body, 204)
end
end
class Mock
def confirm_resized_server(server_id)
response = Excon::Response.new
response.status = 204
self.data[:servers][server_id].delete('old_flavorId')
self.data[:last_modified][:servers][server_id] = Time.now
self.data[:servers][server_id]['status'] = 'ACTIVE'
response
end
end
end
end
end

View file

@ -0,0 +1,30 @@
module Fog
module HP
class Compute
class Real
# Reboot an existing server
#
# ==== Parameters
# * server_id<~Integer> - Id of server to reboot
# * type<~String> - Type of reboot, must be in ['HARD', 'SOFT']
#
def reboot_server(server_id, type = 'SOFT')
body = { 'reboot' => { 'type' => type }}
server_action(server_id, body)
end
end
class Mock
def reboot_server(server_id, type = 'SOFT')
response = Excon::Response.new
response.status = 202
response
end
end
end
end
end

View file

@ -0,0 +1,39 @@
module Fog
module HP
class Compute
class Real
# Reboot an existing server
#
# ==== Parameters
# * server_id<~Integer> - Id of server to resize
# * size<~String> - new size. call list_flavors to get available flavors
#
def resize_server(server_id, flavor_id)
body = { 'resize' => { 'flavorRef' => flavor_id }}
server_action(server_id, body)
end
end
class Mock
# FIXME: should probably transition instead of skipping to VERIFY_RESIZE
def resize_server(server_id, flavor_id)
response = Excon::Response.new
response.status = 202
# keep track of this for reverts
self.data[:servers][server_id]['old_flavorId'] = self.data[:servers][server_id]['flavorId']
self.data[:servers][server_id]['flavorId'] = flavor_id
self.data[:last_modified][:servers][server_id] = Time.now
self.data[:servers][server_id]['status'] = 'VERIFY_RESIZE'
response
end
end
end
end
end

View file

@ -0,0 +1,35 @@
module Fog
module HP
class Compute
class Real
# Revert resizing
#
# ==== Parameters
# * server_id<~Integer> - Id of server to revert
#
def revert_resized_server(server_id)
body = { 'revertResize' => nil }
server_action(server_id, body)
end
end
class Mock
def revert_resized_server(server_id)
response = Excon::Response.new
response.status = 202
self.data[:servers][server_id]['flavorId'] = self.data[:servers][server_id]['old_flavorId']
self.data[:servers][server_id].delete('old_flavorId')
self.data[:last_modified][:servers][server_id] = Time.now
self.data[:servers][server_id]['status'] = 'ACTIVE'
response
end
end
end
end
end

View file

@ -0,0 +1,25 @@
module Fog
module HP
class Compute
class Real
# Reboot an existing server
#
# ==== Parameters
# * server_id<~Integer> - Id of server to reboot
# * body<~.to_json object> - Body of the request, describes the action (see reboot_server as an example)
# * expect<~Integer> - expected return, 202 except for confirm resize (204)
#
def server_action(server_id, body, expects=202)
request(
:body => body.to_json,
:expects => expects,
:method => 'POST',
:path => "servers/#{server_id}/action.json"
)
end
end
end
end
end