diff --git a/lib/fog/openstack/baremetal.rb b/lib/fog/openstack/baremetal.rb index dc22d9576..ee71ad013 100644 --- a/lib/fog/openstack/baremetal.rb +++ b/lib/fog/openstack/baremetal.rb @@ -36,6 +36,8 @@ module Fog request :patch_node request :set_node_power_state request :set_node_provision_state + request :set_node_maintenance + request :unset_node_maintenance # Chassis requests request :create_chassis @@ -65,8 +67,6 @@ module Fog ## Node requests # request :validate_node - # request :set_maintenance - # request :unset_maintenance # request :get_boot_device # request :set_boot_device # request :list_supported_boot_devices diff --git a/lib/fog/openstack/models/baremetal/node.rb b/lib/fog/openstack/models/baremetal/node.rb index 1cb89941f..916597d03 100644 --- a/lib/fog/openstack/models/baremetal/node.rb +++ b/lib/fog/openstack/models/baremetal/node.rb @@ -75,6 +75,18 @@ module Fog service.list_ports_detailed({:node_uuid => self.uuid}).body['ports'] end + def set_node_maintenance(parameters=nil) + requires :uuid + service.set_node_maintenance(uuid, parameters) + true + end + + def unset_node_maintenance(parameters=nil) + requires :uuid + service.unset_node_maintenance(uuid, parameters) + true + end + def metadata requires :uuid service.get_node(self.uuid).headers diff --git a/lib/fog/openstack/requests/baremetal/set_node_maintenance.rb b/lib/fog/openstack/requests/baremetal/set_node_maintenance.rb new file mode 100644 index 000000000..eb9cf4be5 --- /dev/null +++ b/lib/fog/openstack/requests/baremetal/set_node_maintenance.rb @@ -0,0 +1,36 @@ +module Fog + module Baremetal + class OpenStack + class Real + def set_node_maintenance(node_uuid, parameters=nil) + if parameters + query = parameters.each { |k, v| parameters[k] = URI::encode(v) } + else + query = {} + end + + request( + :expects => [200, 202, 204], + :method => 'PUT', + :path => "nodes/#{node_uuid}/maintenance", + :query => query + ) + end + end + + class Mock + def set_node_maintenance(node_uuid, parameters=nil) + response = Excon::Response.new + response.status = 202 + response.headers = { + "X-Compute-Request-Id" => "req-fdc6f99e-55a2-4ab1-8904-0892753828cf", + "Content-Type" => "application/json", + "Content-Length" => "356", + "Date" => Date.new + } + response + end + end # mock + end # openstack + end # baremetal +end # fog diff --git a/lib/fog/openstack/requests/baremetal/unset_node_maintenance.rb b/lib/fog/openstack/requests/baremetal/unset_node_maintenance.rb new file mode 100644 index 000000000..efd09fce3 --- /dev/null +++ b/lib/fog/openstack/requests/baremetal/unset_node_maintenance.rb @@ -0,0 +1,36 @@ +module Fog + module Baremetal + class OpenStack + class Real + def unset_node_maintenance(node_uuid, parameters=nil) + if parameters + query = parameters.each { |k, v| parameters[k] = URI::encode(v) } + else + query = {} + end + + request( + :expects => [200, 202, 204], + :method => 'DELETE', + :path => "nodes/#{node_uuid}/maintenance", + :query => query + ) + end + end + + class Mock + def unset_node_maintenance(node_uuid, parameters=nil) + response = Excon::Response.new + response.status = 202 + response.headers = { + "X-Compute-Request-Id" => "req-fdc6f99e-55a2-4ab1-8904-0892753828cf", + "Content-Type" => "application/json", + "Content-Length" => "356", + "Date" => Date.new + } + response + end + end # mock + end # openstack + end # baremetal +end # fog diff --git a/tests/openstack/requests/baremetal/node_tests.rb b/tests/openstack/requests/baremetal/node_tests.rb index 9a8e362db..382afa967 100644 --- a/tests/openstack/requests/baremetal/node_tests.rb +++ b/tests/openstack/requests/baremetal/node_tests.rb @@ -68,6 +68,14 @@ Shindo.tests('Fog::Baremetal[:openstack] | Baremetal node requests', ['openstack @instance['uuid'], 'manage').body end + tests('#set_node_maintenance').succeeds do + Fog::Baremetal[:openstack].set_node_maintenance(@instance['uuid']) + end + + tests('#unset_node_maintenance').succeeds do + Fog::Baremetal[:openstack].unset_node_maintenance(@instance['uuid']) + end + tests('#delete_node').succeeds do Fog::Baremetal[:openstack].delete_node(@instance['uuid']) end