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

Merge pull request #1753 from cwuest/master

[Rackspace | ComputeV2] Add calls to enter and exit rescue mode
This commit is contained in:
Brad Gignac 2013-04-22 13:47:19 -07:00
commit b58c0ab145
6 changed files with 146 additions and 0 deletions

View file

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

View file

@ -452,6 +452,44 @@ module Fog
true
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)
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
# @param [String] password The administrator password.
# @return [Boolean] returns true if operation was scheduled

View file

@ -0,0 +1,43 @@
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"
admin_pass = Fog::Mock.random_letters(12)
server_response = { 'adminPass' => admin_pass }
response(:status => 200, :body => server_response)
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

@ -148,6 +148,16 @@ Shindo.tests('Fog::Compute::RackspaceV2 | server', ['rackspace']) do
@instance.revert_resize
end
@instance.wait_for(timeout=1500) { ready? }
tests('#rescue').succeeds do
@instance.rescue
end
@instance.wait_for(timeout=1500) { ready?('RESCUE') }
tests('#unrescue').succeeds do
@instance.unrescue
end
@instance.wait_for(timeout=1500) { ready? }
tests('#change_admin_password').succeeds do
@instance.change_admin_password('somerandompassword')

View file

@ -54,6 +54,9 @@ Shindo.tests('Fog::Compute::RackspaceV2 | server_tests', ['rackspace']) do
}
}
rescue_server_format = {
'adminPass' => Fog::Nullable::String
}
tests('success') do
@ -124,6 +127,16 @@ Shindo.tests('Fog::Compute::RackspaceV2 | server_tests', ['rackspace']) do
end
wait_for_server_state(service, server_id, 'ACTIVE', 'ERROR')
tests('#rescue_server').formats(rescue_server_format, false) 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
service.delete_server(server_id)
end