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:
parent
f1dff717aa
commit
71c42f80e5
5 changed files with 163 additions and 0 deletions
34
lib/fog/compute/requests/hp/confirm_resized_server.rb
Normal file
34
lib/fog/compute/requests/hp/confirm_resized_server.rb
Normal 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
|
30
lib/fog/compute/requests/hp/reboot_server.rb
Normal file
30
lib/fog/compute/requests/hp/reboot_server.rb
Normal 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
|
39
lib/fog/compute/requests/hp/resize_server.rb
Normal file
39
lib/fog/compute/requests/hp/resize_server.rb
Normal 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
|
35
lib/fog/compute/requests/hp/revert_resized_server.rb
Normal file
35
lib/fog/compute/requests/hp/revert_resized_server.rb
Normal 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
|
25
lib/fog/compute/requests/hp/server_action.rb
Normal file
25
lib/fog/compute/requests/hp/server_action.rb
Normal 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
|
Loading…
Reference in a new issue