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

[xenserver] add missing host operations (enable/disable, reboot, shutdown)

This commit is contained in:
Sergio Rubio 2013-01-06 16:12:38 +01:00
parent 9db7f34aa8
commit a3edb0a601
9 changed files with 216 additions and 0 deletions

View file

@ -63,6 +63,10 @@ module Fog
request :unplug_pbd
request :destroy_sr
request :create_sr
request :reboot_host
request :disable_host
request :enable_host
request :shutdown_host
class Real

View file

@ -45,6 +45,67 @@ module Fog
Fog::Compute::XenServer::HostMetrics.new(rec)
end
#
# Reboot the host disabling it first unless auto_disable is
# set to false
#
# This function can only be called if there are no currently running
# VMs on the host and it is disabled. If there are running VMs, it will
# raise an exception.
#
# @param [Boolean] auto_disable disable the host first
#
# @see http://docs.vmd.citrix.com/XenServer/6.0.0/1.0/en_gb/api/?c=host
#
def reboot(auto_disable = true)
disable if auto_disable
connection.reboot_host(reference)
end
#
# Puts the host into a state in which no new VMs can be started.
# Currently active VMs on the host continue to execute.
#
# @see http://docs.vmd.citrix.com/XenServer/6.0.0/1.0/en_gb/api/?c=host
#
def disable
connection.disable_host(reference)
end
#
# Puts the host into a state in which new VMs can be started.
#
# @see http://docs.vmd.citrix.com/XenServer/6.0.0/1.0/en_gb/api/?c=host
#
def enable
connection.enable_host(reference)
end
#
# Shutdown the host disabling it first unless auto_disable is
# set to false.
#
# This function can only be called if there are no currently running
# VMs on the host and it is disabled. If there are running VMs, it will
# raise an exception.
#
# @param [Boolean] auto_disable disable the host first
#
# @see http://docs.vmd.citrix.com/XenServer/6.0.0/1.0/en_gb/api/?c=host
#
def shutdown(auto_disable = true)
disable if auto_disable
connection.shutdown_host(reference)
end
def set_attribute(name, *val)
data = connection.set_attribute( 'host', reference, name, *val )
# Do not reload automatically for performance reasons
# We can set multiple attributes at the same time and
# then reload manually
#reload
end
end
end

View file

@ -0,0 +1,29 @@
module Fog
module Compute
class XenServer
class Real
#
# Puts the host into a state in which no new VMs can be started.
# Currently active VMs on the host continue to execute.
#
# @see http://docs.vmd.citrix.com/XenServer/6.0.0/1.0/en_gb/api/?c=host
#
def disable_host( ref )
@connection.request({:parser => Fog::Parsers::XenServer::Base.new, :method => "host.disable"}, ref)
end
end
class Mock
def disable_host( ref )
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -0,0 +1,28 @@
module Fog
module Compute
class XenServer
class Real
#
# Puts the host into a state in which VMs can be started.
#
# @see http://docs.vmd.citrix.com/XenServer/6.0.0/1.0/en_gb/api/?c=host
#
def enable_host( ref )
@connection.request({:parser => Fog::Parsers::XenServer::Base.new, :method => "host.enable"}, ref)
end
end
class Mock
def enable_host( ref )
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -0,0 +1,23 @@
module Fog
module Compute
class XenServer
class Real
def reboot_host( ref )
@connection.request({:parser => Fog::Parsers::XenServer::Base.new, :method => "host.reboot"}, ref)
end
end
class Mock
def reboot_host( ref )
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -0,0 +1,23 @@
module Fog
module Compute
class XenServer
class Real
def shutdown_host( ref )
@connection.request({:parser => Fog::Parsers::XenServer::Base.new, :method => "host.shutdown"}, ref)
end
end
class Mock
def shutdown_host( ref )
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -7,6 +7,9 @@ Shindo.tests('Fog::Compute[:xenserver] | host model', ['xenserver']) do
tests('The host model should') do
tests('have the action') do
test('reload') { host.respond_to? 'reload' }
test('shutdown') { host.respond_to? 'shutdown' }
test('disable') { host.respond_to? 'disable' }
test('reboot') { host.respond_to? 'reboot' }
end
tests('have attributes') do
@ -65,6 +68,19 @@ Shindo.tests('Fog::Compute[:xenserver] | host model', ['xenserver']) do
test("object") { host.metrics.kind_of? Fog::Compute::XenServer::HostMetrics }
end
tests('be able to be') do
test('disable') do
host.disable
host.reload
host.enabled == false
end
test('enabled') do
host.enable
host.reload
host.enabled
end
end
end

View file

@ -0,0 +1,16 @@
Shindo.tests('Fog::Compute[:xenserver] | disable_host request', ['xenserver']) do
compute = Fog::Compute[:xenserver]
host = compute.hosts.first
tests('#disable_host') do
test('disables the host') do
compute.disable_host host.reference
host.reload
!host.enabled
end
end
# Cleanup
host.enable
end

View file

@ -0,0 +1,16 @@
Shindo.tests('Fog::Compute[:xenserver] | enable_host request', ['xenserver']) do
compute = Fog::Compute[:xenserver]
host = compute.hosts.first
tests('#enable_host') do
test('enables the host') do
compute.enable_host host.reference
host.reload
host.enabled
end
end
# Cleanup
host.enable
end