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:
parent
a83c5eca4b
commit
a1f0dbf428
6 changed files with 144 additions and 0 deletions
|
@ -66,6 +66,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
|
||||
|
||||
|
|
|
@ -451,6 +451,45 @@ 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)
|
||||
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
|
||||
# @param [String] password The administrator password.
|
||||
# @return [Boolean] returns true if operation was scheduled
|
||||
|
|
41
lib/fog/rackspace/requests/compute_v2/rescue_server.rb
Normal file
41
lib/fog/rackspace/requests/compute_v2/rescue_server.rb
Normal 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
|
40
lib/fog/rackspace/requests/compute_v2/unrescue_server.rb
Normal file
40
lib/fog/rackspace/requests/compute_v2/unrescue_server.rb
Normal 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
|
|
@ -139,6 +139,18 @@ Shindo.tests('Fog::Compute::RackspaceV2 | server', ['rackspace']) do
|
|||
@instance.revert_resize
|
||||
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? }
|
||||
tests('#change_admin_password').succeeds do
|
||||
@instance.change_admin_password('somerandompassword')
|
||||
|
|
|
@ -124,6 +124,16 @@ Shindo.tests('Fog::Compute::RackspaceV2 | server_tests', ['rackspace']) do
|
|||
end
|
||||
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
|
||||
service.delete_server(server_id)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue