mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge pull request #3571 from tzumainn/openstack-node-functions
[openstack|baremetal] added support for setting node states
This commit is contained in:
commit
181c8588fb
5 changed files with 95 additions and 2 deletions
|
@ -34,6 +34,8 @@ module Fog
|
|||
request :list_nodes
|
||||
request :list_nodes_detailed
|
||||
request :patch_node
|
||||
request :set_node_power_state
|
||||
request :set_node_provision_state
|
||||
|
||||
# Chassis requests
|
||||
request :create_chassis
|
||||
|
@ -69,8 +71,6 @@ module Fog
|
|||
# request :set_boot_device
|
||||
# request :list_supported_boot_devices
|
||||
# request :list_node_states
|
||||
# request :set_power_state
|
||||
# request :provision_node
|
||||
# request :get_console_info
|
||||
# request :change_console_state
|
||||
# request :get_vendor_passthru_methods
|
||||
|
|
|
@ -79,6 +79,16 @@ module Fog
|
|||
requires :uuid
|
||||
service.get_node(self.uuid).headers
|
||||
end
|
||||
|
||||
def set_power_state(power_state)
|
||||
requires :uuid
|
||||
service.set_node_power_state(self.uuid, power_state)
|
||||
end
|
||||
|
||||
def set_provision_state(provision_state)
|
||||
requires :uuid
|
||||
service.set_node_provision_state(self.uuid, provision_state)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
35
lib/fog/openstack/requests/baremetal/set_node_power_state.rb
Normal file
35
lib/fog/openstack/requests/baremetal/set_node_power_state.rb
Normal file
|
@ -0,0 +1,35 @@
|
|||
module Fog
|
||||
module Baremetal
|
||||
class OpenStack
|
||||
class Real
|
||||
def set_node_power_state(node_id, power_state)
|
||||
data = {
|
||||
'target' => power_state
|
||||
}
|
||||
|
||||
request(
|
||||
:body => Fog::JSON.encode(data),
|
||||
:expects => 202,
|
||||
:method => 'PUT',
|
||||
:path => "nodes/#{node_id}/states/power"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def set_node_power_state(node_id, power_state)
|
||||
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.body = self.data[:nodes].first
|
||||
response
|
||||
end
|
||||
end # mock
|
||||
end # openstack
|
||||
end # baremetal
|
||||
end # fog
|
|
@ -0,0 +1,38 @@
|
|||
module Fog
|
||||
module Baremetal
|
||||
class OpenStack
|
||||
class Real
|
||||
def set_node_provision_state(node_id, provision_state)
|
||||
data = {
|
||||
'target' => provision_state
|
||||
}
|
||||
|
||||
request(
|
||||
:body => Fog::JSON.encode(data),
|
||||
:expects => 202,
|
||||
:method => 'PUT',
|
||||
:path => "nodes/#{node_id}/states/provision",
|
||||
:headers => {
|
||||
:'X-OpenStack-Ironic-API-Version' => 'latest'
|
||||
}
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def set_node_provision_state(node_id, provision_state)
|
||||
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.body = self.data[:nodes].first
|
||||
response
|
||||
end
|
||||
end # mock
|
||||
end # openstack
|
||||
end # baremetal
|
||||
end # fog
|
|
@ -58,6 +58,16 @@ Shindo.tests('Fog::Baremetal[:openstack] | Baremetal node requests', ['openstack
|
|||
[{'op' => 'replace', 'path' => '/driver', 'value' => 'pxe_ssh'}]).body
|
||||
end
|
||||
|
||||
tests('#set_node_power_state').data_matches_schema(@detailed_node_format) do
|
||||
Fog::Baremetal[:openstack].set_node_power_state(
|
||||
@instance['uuid'], 'power off').body
|
||||
end
|
||||
|
||||
tests('#set_node_provision_state').data_matches_schema(@detailed_node_format) do
|
||||
Fog::Baremetal[:openstack].set_node_provision_state(
|
||||
@instance['uuid'], 'manage').body
|
||||
end
|
||||
|
||||
tests('#delete_node').succeeds do
|
||||
Fog::Baremetal[:openstack].delete_node(@instance['uuid'])
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue