mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[slicehost] add reboot support
This commit is contained in:
parent
5187883bae
commit
9351fb2bdd
8 changed files with 112 additions and 9 deletions
|
@ -10,7 +10,7 @@ unless Fog.mocking?
|
|||
# * server_id<~Integer> - Id of server to reboot
|
||||
# * type<~String> - Type of reboot, must be in ['HARD', 'SOFT']
|
||||
#
|
||||
def reboot_server(server_id, type)
|
||||
def reboot_server(server_id, type = 'SOFT')
|
||||
request(
|
||||
:body => { 'reboot' => { 'type' => type }}.to_json,
|
||||
:expects => 202,
|
||||
|
|
|
@ -28,6 +28,7 @@ module Fog
|
|||
load "fog/slicehost/requests/get_images.rb"
|
||||
load "fog/slicehost/requests/get_slice.rb"
|
||||
load "fog/slicehost/requests/get_slices.rb"
|
||||
load "fog/slicehost/requests/reboot_slice.rb"
|
||||
|
||||
if Fog.mocking?
|
||||
reset_data
|
||||
|
|
|
@ -36,11 +36,11 @@ module Fog
|
|||
@status == 'active'
|
||||
end
|
||||
|
||||
# def reboot(type = 'SOFT')
|
||||
# requires :id
|
||||
# connection.reboot_server(@id, type)
|
||||
# true
|
||||
# end
|
||||
def reboot(type = 'SOFT')
|
||||
requires :id
|
||||
connection.reboot_server(@id, type)
|
||||
true
|
||||
end
|
||||
|
||||
def save
|
||||
requires :flavor_id, :image_id, :name
|
||||
|
|
|
@ -4,6 +4,8 @@ unless Fog.mocking?
|
|||
class Slicehost
|
||||
|
||||
# Get details of slice
|
||||
# ==== Parameters
|
||||
# * slice_id<~Integer> - Id of slice to lookup
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
|
@ -18,12 +20,12 @@ unless Fog.mocking?
|
|||
# * 'name'<~String> - Name of the slice
|
||||
# * 'progress'<~Integer> - Progress of current action, in percentage
|
||||
# * 'status'<~String> - Current status of the slice
|
||||
def get_slice(id)
|
||||
def get_slice(slice_id)
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:parser => Fog::Parsers::Slicehost::GetSlice.new,
|
||||
:path => "/slices/#{id}.xml"
|
||||
:path => "/slices/#{slice_id}.xml"
|
||||
)
|
||||
end
|
||||
|
||||
|
|
49
lib/fog/slicehost/requests/reboot_slice.rb
Normal file
49
lib/fog/slicehost/requests/reboot_slice.rb
Normal file
|
@ -0,0 +1,49 @@
|
|||
unless Fog.mocking?
|
||||
|
||||
module Fog
|
||||
class Slicehost
|
||||
|
||||
# Reboot slice
|
||||
# ==== Parameters
|
||||
# * slice_id<~Integer> - Id of server to reboot
|
||||
# * type<~String> - Type of reboot, must be in ['HARD', 'SOFT']
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'addresses'<~Array> - Ip addresses for the slice
|
||||
# * 'backup-id'<~Integer> - Id of backup slice was booted from
|
||||
# * 'bw-in'<~Float> - Incoming bandwidth total for current billing cycle, in Gigabytes
|
||||
# * 'bw-out'<~Float> - Outgoing bandwidth total for current billing cycle, in Gigabytes
|
||||
# * 'flavor_id'<~Integer> - Id of flavor slice was booted from
|
||||
# * 'id'<~Integer> - Id of the slice
|
||||
# * 'image-id'<~Integer> - Id of image slice was booted from
|
||||
# * 'name'<~String> - Name of the slice
|
||||
# * 'progress'<~Integer> - Progress of current action, in percentage
|
||||
# * 'status'<~String> - Current status of the slice
|
||||
def reboot_slice(slice_id, type = 'SOFT')
|
||||
request(
|
||||
:body => '', # Gives a 411 Length Required without this
|
||||
:expects => 200,
|
||||
:method => 'PUT',
|
||||
:parser => Fog::Parsers::Slicehost::GetSlice.new,
|
||||
:path => "/slices/#{slice_id}/#{'hard_' if type == 'HARD'}reboot.xml"
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
module Fog
|
||||
class Slicehost
|
||||
|
||||
def get_slice(id)
|
||||
raise MockNotImplemented.new("Contributions welcome!")
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -1,6 +1,6 @@
|
|||
require File.dirname(__FILE__) + '/../../spec_helper'
|
||||
|
||||
describe 'Slicehost.get_slices' do
|
||||
describe 'Slicehost.get_slice' do
|
||||
describe 'success' do
|
||||
|
||||
before(:each) do
|
||||
|
|
41
spec/slicehost/requests/reboot_slice_spec.rb
Normal file
41
spec/slicehost/requests/reboot_slice_spec.rb
Normal file
|
@ -0,0 +1,41 @@
|
|||
require File.dirname(__FILE__) + '/../../spec_helper'
|
||||
|
||||
describe 'Slicehost.reboot_slice' do
|
||||
describe 'success' do
|
||||
|
||||
before(:each) do
|
||||
# flavor_id 1: 256 ram, image_id 3: Gentoo 2008.0
|
||||
@slice_id = Slicehost[:slices].create_slice(1, 3, 'fog_create_slice').body['id']
|
||||
wait_for { Slicehost[:slices].get_slice(@slice_id).body['status'] == 'active' }
|
||||
end
|
||||
|
||||
after(:each) do
|
||||
wait_for { Slicehost[:slices].get_slice(@slice_id).body['status'] == 'active' }
|
||||
Slicehost[:slices].delete_slice(@slice_id)
|
||||
end
|
||||
|
||||
it "should return proper attributes" do
|
||||
actual = Slicehost[:slices].reboot_slice(@slice_id).body
|
||||
actual['addresses'].should be_a(Array)
|
||||
# actual['backup-id'].should be_an(Integer)
|
||||
actual['bw-in'].should be_a(Float)
|
||||
actual['bw-out'].should be_a(Float)
|
||||
actual['flavor-id'].should be_an(Integer)
|
||||
actual['id'].should be_an(Integer)
|
||||
actual['image-id'].should be_an(Integer)
|
||||
actual['name'].should be_an(String)
|
||||
actual['progress'].should be_an(Integer)
|
||||
actual['status'].should be_an(String)
|
||||
end
|
||||
|
||||
end
|
||||
describe 'failure' do
|
||||
|
||||
it "should raise a Forbidden error if the server does not exist" do
|
||||
lambda {
|
||||
Slicehost[:slices].reboot_slice(0)
|
||||
}.should raise_error(Excon::Errors::Forbidden)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -100,6 +100,16 @@ def eventually(max_delay = 16, &block)
|
|||
end
|
||||
end
|
||||
|
||||
def wait_for(timeout = 600, &block)
|
||||
start = Time.now
|
||||
until instance_eval(&block)
|
||||
if Time.now - start > timeout
|
||||
break
|
||||
end
|
||||
sleep(1)
|
||||
end
|
||||
end
|
||||
|
||||
unless defined?(GENTOO_AMI)
|
||||
GENTOO_AMI = 'ami-5ee70037'
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue