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

resize requests for rackspace

This commit is contained in:
gilles 2010-11-29 10:36:10 -08:00 committed by geemus
parent c5773c08da
commit f74164b3fb
6 changed files with 181 additions and 8 deletions

View file

@ -29,8 +29,10 @@ module Fog
request :list_images_detail request :list_images_detail
request :list_servers request :list_servers
request :list_servers_detail request :list_servers_detail
request :reboot_server
request :update_server request :update_server
request :action
request :reboot_server
request :resize_server
class Mock class Mock

View file

@ -0,0 +1,33 @@
module Fog
module Rackspace
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 action(server_id, body, expects=202)
request(
:body => body.to_json,
:expects => expects,
:method => 'POST',
:path => "servers/#{server_id}/action.json"
)
end
end
class Mock
def action(server_id, body)
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -10,12 +10,8 @@ module Fog
# * type<~String> - Type of reboot, must be in ['HARD', 'SOFT'] # * type<~String> - Type of reboot, must be in ['HARD', 'SOFT']
# #
def reboot_server(server_id, type = 'SOFT') def reboot_server(server_id, type = 'SOFT')
request( body = { 'reboot' => { 'type' => type }}
:body => { 'reboot' => { 'type' => type }}.to_json, action(server_id, body)
:expects => 202,
:method => 'POST',
:path => "servers/#{server_id}/action.json"
)
end end
end end
@ -23,7 +19,9 @@ module Fog
class Mock class Mock
def reboot_server(server_id, type = 'SOFT') def reboot_server(server_id, type = 'SOFT')
Fog::Mock.not_implemented response = Excon::Response.new
response.status = 202
response
end end
end end

View file

@ -0,0 +1,80 @@
module Fog
module Rackspace
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' => { 'flavorId' => flavor_id }}
action(server_id, body)
end
# Confirm resizing
#
# ==== Parameters
# * server_id<~Integer> - Id of server to confirm
#
def confirm_resize(server_id)
body = { 'confirmResize' => nil }
action(server_id, body, 204)
end
# Revert resizing
#
# ==== Parameters
# * server_id<~Integer> - Id of server to revert
#
def revert_resize(server_id)
body = { 'revertResize' => nil }
action(server_id, body)
end
end
class Mock
def resize_server(server_id, flavor_id)
response = Excon::Response.new
response.status = 202
#I know this is weird... but I got to keep track of it
@data[:servers][server_id]['old_flavorId'] = @data[:servers][server_id]['flavorId']
@data[:servers][server_id]['flavorId'] = flavor_id
@data[:last_modified][:servers][server_id] = Time.now
@data[:servers][server_id]['status'] = 'VERIFY_RESIZE'
response
end
def confirm_resize(server_id)
response = Excon::Response.new
response.status = 204
@data[:last_modified][:servers][server_id] = Time.now
@data[:servers][server_id]['status'] = 'ACTIVE'
response
end
def revert_resize(server_id)
response = Excon::Response.new
response.status = 202
@data[:servers][server_id]['flavorId'] = @data[:servers][server_id]['old_flavorId']
@data[:servers][server_id].delete('old_flavorId')
@data[:last_modified][:servers][server_id] = Time.now
@data[:servers][server_id]['status'] = 'ACTIVE'
response
end
end
end
end
end

View file

@ -0,0 +1,17 @@
Shindo.tests('Rackspace::Compute | reboot request', ['rackspace']) do
tests('success') do
@server = Rackspace[:compute].servers.create(:flavor_id => 1, :image_id => 19, :name => 'fogactions')
@server.wait_for { ready? }
tests("#reboot_server(#{@server.id})") do
returns(Rackspace[:compute].reboot_server(@server.id).status) { 202 }
end
@server.destroy
end
end

View file

@ -0,0 +1,43 @@
Shindo.tests('Rackspace::Compute | resize request', ['rackspace']) do
tests('success_confirm') do
@server = Rackspace[:compute].servers.create(:flavor_id => 1, :image_id => 19, :name => 'fogresize')
@server.wait_for { ready? }
tests("#resize_server(#{@server.id}, 2)") do
returns(Rackspace[:compute].resize_server(@server.id, 2).status) { 202 }
returns(Rackspace[:compute].get_server_details(@server.id).body['server']['status']) { 'VERIFY_RESIZE' }
end
tests("#confirm_resize(#{@server.id})") do
returns(Rackspace[:compute].confirm_resize(@server.id).status) { 204 }
returns(Rackspace[:compute].get_server_details(@server.id).body['server']['status']) { 'ACTIVE' }
end
@server.destroy
end
tests('success_revert') do
@server = Rackspace[:compute].servers.create(:flavor_id => 1, :image_id => 19, :name => 'fogresize')
@server.wait_for { ready? }
tests("#resize_server(#{@server.id}, 2)") do
returns(Rackspace[:compute].resize_server(@server.id, 2).status) { 202 }
returns(Rackspace[:compute].get_server_details(@server.id).body['server']['status']) { 'VERIFY_RESIZE' }
end
tests("#revert_resize(#{@server.id})") do
returns(Rackspace[:compute].revert_resize(@server.id).status) { 202 }
returns(Rackspace[:compute].get_server_details(@server.id).body['server']['status']) { 'ACTIVE' }
end
@server.destroy
end
end