diff --git a/lib/fog/xenserver/compute.rb b/lib/fog/xenserver/compute.rb index 492676324..26017bd63 100644 --- a/lib/fog/xenserver/compute.rb +++ b/lib/fog/xenserver/compute.rb @@ -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 diff --git a/lib/fog/xenserver/models/compute/host.rb b/lib/fog/xenserver/models/compute/host.rb index 11365ff27..9dbde6a56 100644 --- a/lib/fog/xenserver/models/compute/host.rb +++ b/lib/fog/xenserver/models/compute/host.rb @@ -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 diff --git a/lib/fog/xenserver/requests/compute/disable_host.rb b/lib/fog/xenserver/requests/compute/disable_host.rb new file mode 100644 index 000000000..595e399b9 --- /dev/null +++ b/lib/fog/xenserver/requests/compute/disable_host.rb @@ -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 diff --git a/lib/fog/xenserver/requests/compute/enable_host.rb b/lib/fog/xenserver/requests/compute/enable_host.rb new file mode 100644 index 000000000..3da734524 --- /dev/null +++ b/lib/fog/xenserver/requests/compute/enable_host.rb @@ -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 diff --git a/lib/fog/xenserver/requests/compute/reboot_host.rb b/lib/fog/xenserver/requests/compute/reboot_host.rb new file mode 100644 index 000000000..31ff248f2 --- /dev/null +++ b/lib/fog/xenserver/requests/compute/reboot_host.rb @@ -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 diff --git a/lib/fog/xenserver/requests/compute/shutdown_host.rb b/lib/fog/xenserver/requests/compute/shutdown_host.rb new file mode 100644 index 000000000..b566b2800 --- /dev/null +++ b/lib/fog/xenserver/requests/compute/shutdown_host.rb @@ -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 diff --git a/tests/xenserver/models/compute/host_tests.rb b/tests/xenserver/models/compute/host_tests.rb index cff171fce..8abddbdf6 100644 --- a/tests/xenserver/models/compute/host_tests.rb +++ b/tests/xenserver/models/compute/host_tests.rb @@ -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 diff --git a/tests/xenserver/requests/compute/disable_host_tests.rb b/tests/xenserver/requests/compute/disable_host_tests.rb new file mode 100644 index 000000000..914d98d23 --- /dev/null +++ b/tests/xenserver/requests/compute/disable_host_tests.rb @@ -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 diff --git a/tests/xenserver/requests/compute/enable_host_tests.rb b/tests/xenserver/requests/compute/enable_host_tests.rb new file mode 100644 index 000000000..aa6d6e470 --- /dev/null +++ b/tests/xenserver/requests/compute/enable_host_tests.rb @@ -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