Skip to content

Commit

Permalink
Merge pull request #5 from xlab-si/power-ops
Browse files Browse the repository at this point in the history
Add power operations to physical server
  • Loading branch information
agrare committed Jun 7, 2018
2 parents 4d52675 + caa1cd9 commit 43e583f
Show file tree
Hide file tree
Showing 11 changed files with 1,088 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class PhysicalInfraManager < ManageIQ::Providers::PhysicalInfraManager

include Vmdb::Logging
include ManagerMixin
include_concern "Operations"

has_many :physical_server_details,
:class_name => "AssetDetail",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module ManageIQ::Providers::Redfish
module PhysicalInfraManager::Operations
extend ActiveSupport::Concern

include_concern "Power"
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
module ManageIQ::Providers::Redfish
module PhysicalInfraManager::Operations::Power
# Keep this in sync with app/models/physical_server/operations/power.rb in
# core and ResetType enum in Redfish Resource type. Name of the method
# comes from the core and the action name used in the reset call from the
# ResetType enum.
#
# NOTE: Not all reset operations are implemented on all servers, so any of
# the methods listed here can fail. We need to find a way to let those
# failures bubble up to the user interface somehow or risk having a
# completely useless tool.

def power_on(server, _options)
reset_server(server, "On")
end

def power_off(server, _options)
reset_server(server, "GracefulShutdown")
end

def power_off_now(server, _options)
reset_server(server, "ForceOff")
end

def restart(server, _options)
reset_server(server, "GracefulRestart")
end

def restart_now(server, _options)
reset_server(server, "ForceRestart")
end

def restart_to_sys_setup(_args, _options)
$redfish_log.error("Restarting to system setup is not supported.")
end

def restart_mgmt_controller(_server, _options)
# TODO(tadeboro): This operation is not well defined, since server can
# (and usually is) managed by more that one manager.
$redfish_log.error("Restarting management controller is not supported.")
end

private

def reset_server(server, reset_type)
$redfish_log.info("Requesting #{reset_type} for #{server.ems_ref}.")
with_provider_connection do |client|
system = client.find(server.ems_ref)
if system.nil?
$redfish_log.error("#{server.ems_ref} does not exist anymore.")
return
end

response = system.Actions["#ComputerSystem.Reset"].post(
:field => "target", :payload => { "ResetType" => reset_type }
)
if [200, 202, 204].include?(response.status)
$redfish_log.info("#{reset_type} for #{server.ems_ref} started.")
else
$redfish_log.error("#{reset_type} for #{server.ems_ref} failed.")
end
end
end
end
end
3 changes: 3 additions & 0 deletions spec/factories/ext_management_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
end

trait :vcr do
security_protocol "ssl"
port 8889

hostname do
# Keep in sync with filter_sensitive_data in spec/spec_helper.rb!
Rails.application.secrets.redfish.try(:[], "host") || "redfishhost"
Expand Down
9 changes: 9 additions & 0 deletions spec/factories/physical_server.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FactoryGirl.define do
factory :redfish_physical_server,
:class => ManageIQ::Providers::Redfish::PhysicalInfraManager::PhysicalServer,
:parent => :physical_server do
trait :vcr do
ems_ref "/redfish/v1/Systems/System.Embedded.1"
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
describe ManageIQ::Providers::Redfish::PhysicalInfraManager do
let(:server) { FactoryGirl.create(:redfish_physical_server, :vcr) }
subject(:ems) do
FactoryGirl.create(:ems_redfish_physical_infra, :vcr)
end

describe "#power_on", :vcr do
it "powers on the system" do
ems.power_on(server, nil)
end
end

describe "#power_off", :vcr do
it "powers off the system" do
ems.power_off(server, nil)
end
end

describe "#power_off_now", :vcr do
it "powers off the system immediately" do
ems.power_off_now(server, nil)
end
end

describe "#restart", :vcr do
it "restarts the system" do
ems.restart(server, nil)
end
end

describe "#restart_now", :vcr do
it "restarts the system immediately" do
ems.restart_now(server, nil)
end
end

describe "#restart_to_sys_setup", :vcr do
it "restarts to system setup" do
ems.restart_to_sys_setup(server, nil)
end
end

describe "#restart_mgmt_controller", :vcr do
it "restarts management controller" do
ems.restart_mgmt_controller(server, nil)
end
end
end

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 43e583f

Please sign in to comment.