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

Implement rescue mode support for Rackspace

Create real and mock rescue and unrescue methods for Rackspace compute V2
Create tests for rescue and unrescue methods
This commit is contained in:
Chris Wuest 2013-04-13 22:53:26 -05:00
parent a83c5eca4b
commit a1f0dbf428
6 changed files with 144 additions and 0 deletions

View file

@ -66,6 +66,8 @@ module Fog
request :resize_server request :resize_server
request :confirm_resize_server request :confirm_resize_server
request :revert_resize_server request :revert_resize_server
request :rescue_server
request :unrescue_server
request :list_addresses request :list_addresses
request :list_addresses_by_network request :list_addresses_by_network

View file

@ -451,6 +451,45 @@ module Fog
true true
end end
# Place existing server into rescue mode, allowing for offline editing of configuration. The original server's disk is attached to a new instance of the same base image for a period of time to facilitate working within rescue mode. The original server will be automatically restored after 90 minutes.
# @return [Boolean] returns true if call to put server in rescue mode reports success
# @raise [Fog::Rackspace::Errors::NotFound] - HTTP 404
# @raise [Fog::Rackspace::Errors::BadRequest] - HTTP 400
# @raise [Fog::Rackspace::Errors::InternalServerError] - HTTP 500
# @raise [Fog::Rackspace::Errors::ServiceError]
# @note Rescue mode is only guaranteed to be active for 90 minutes.
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/rescue_mode.html
# @see #unrescue
#
# * Status Transition:
# * ACTIVE -> PREP_RESCUE -> RESCUE
def rescue
requires :identity
data = service.rescue_server(identity)
merge_attributes(data.body)
self.state = RESCUE
true
end
# Remove existing server from rescue mode.
# @return [Boolean] returns true if call to remove server from rescue mode reports success
# @raise [Fog::Rackspace::Errors::NotFound] - HTTP 404
# @raise [Fog::Rackspace::Errors::BadRequest] - HTTP 400
# @raise [Fog::Rackspace::Errors::InternalServerError] - HTTP 500
# @raise [Fog::Rackspace::Errors::ServiceError]
# @note Rescue mode is only guaranteed to be active for 90 minutes.
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/exit_rescue_mode.html
# @see #rescue
#
# * Status Transition:
# * PREP_UNRESCUE -> ACTIVE
def unrescue
requires :identity
service.unrescue_server(identity)
self.state = ACTIVE
true
end
# Change admin password # Change admin password
# @param [String] password The administrator password. # @param [String] password The administrator password.
# @return [Boolean] returns true if operation was scheduled # @return [Boolean] returns true if operation was scheduled

View file

@ -0,0 +1,41 @@
module Fog
module Compute
class RackspaceV2
class Real
# Puts server into rescue mode
# @param [String] server_id id of server to rescue
# @return [Excon::Response] response
# @raise [Fog::Rackspace::Errors::NotFound] - HTTP 404
# @raise [Fog::Rackspace::Errors::BadRequest] - HTTP 400
# @raise [Fog::Rackspace::Errors::InternalServerError] - HTTP 500
# @raise [Fog::Rackspace::Errors::ServiceError]
# @note Rescue mode is only guaranteed to be active for 90 minutes
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/rescue_mode.html
#
# * Status Transition:
# * PREP_RESCUE -> RESCUE
# * PREP_RESCUE -> ACTIVE (on error)
def rescue_server(server_id)
data = {
'rescue' => nil
}
request(
:body => Fog::JSON.encode(data),
:expects => [200],
:method => 'POST',
:path => "servers/#{server_id}/action"
)
end
end
class Mock
def rescue_server(server_id)
server = self.data[:servers][server_id]
server["status"] = "RESCUE"
response(:status => 200)
end
end
end
end
end

View file

@ -0,0 +1,40 @@
module Fog
module Compute
class RackspaceV2
class Real
# Take server out of rescue mode
# @param [String] server_id id of server
# @return [Excon::Response] response
# @raise [Fog::Rackspace::Errors::NotFound] - HTTP 404
# @raise [Fog::Rackspace::Errors::BadRequest] - HTTP 400
# @raise [Fog::Rackspace::Errors::InternalServerError] - HTTP 500
# @raise [Fog::Rackspace::Errors::ServiceError]
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/exit_rescue_mode.html
#
# * Status Transition:
# * RESCUE -> PREP_UNRESCUE -> ACTIVE
# * RESCUE -> ERROR (on error)
def unrescue_server(server_id)
data = {
'unrescue' => nil
}
request(
:body => Fog::JSON.encode(data),
:expects => [202],
:method => 'POST',
:path => "servers/#{server_id}/action"
)
end
end
class Mock
def unrescue_server(server_id)
server = self.data[:servers][server_id]
server["status"] = "ACTIVE"
response(:status => 202)
end
end
end
end
end

View file

@ -139,6 +139,18 @@ Shindo.tests('Fog::Compute::RackspaceV2 | server', ['rackspace']) do
@instance.revert_resize @instance.revert_resize
end end
@instance.wait_for(timeout=1500) { ready? }
tests('#rescue').succeeds do
@instance.rescue
returns('RESCUE') { @instance.state }
end
@instance.wait_for(timeout=1500) { ready?('RESCUE') }
sleep 60 unless Fog.mocking?
tests('#unrescue').succeeds do
@instance.unrescue
end
@instance.wait_for(timeout=1500) { ready? } @instance.wait_for(timeout=1500) { ready? }
tests('#change_admin_password').succeeds do tests('#change_admin_password').succeeds do
@instance.change_admin_password('somerandompassword') @instance.change_admin_password('somerandompassword')

View file

@ -124,6 +124,16 @@ Shindo.tests('Fog::Compute::RackspaceV2 | server_tests', ['rackspace']) do
end end
wait_for_server_state(service, server_id, 'ACTIVE', 'ERROR') wait_for_server_state(service, server_id, 'ACTIVE', 'ERROR')
tests('#rescue_server').succeeds do
service.rescue_server(server_id)
end
wait_for_server_state(service, server_id, 'RESCUE', 'ACTIVE')
tests('#unrescue_server').succeeds do
service.unrescue_server(server_id)
end
wait_for_server_state(service, server_id, 'ACTIVE', 'ERROR')
tests('#delete_server').succeeds do tests('#delete_server').succeeds do
service.delete_server(server_id) service.delete_server(server_id)
end end