-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from xlab-si/power-ops
Add power operations to physical server
- Loading branch information
Showing
11 changed files
with
1,088 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
app/models/manageiq/providers/redfish/physical_infra_manager/operations.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
65 changes: 65 additions & 0 deletions
65
app/models/manageiq/providers/redfish/physical_infra_manager/operations/power.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
48 changes: 48 additions & 0 deletions
48
spec/models/manageiq/providers/redfish/physical_infra_manager/operations/power_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
191 changes: 191 additions & 0 deletions
191
...ttes/ManageIQ_Providers_Redfish_PhysicalInfraManager/_power_off/powers_off_the_system.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.