Skip to content

Commit

Permalink
Adding physical switch power operations
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasgabriel committed May 24, 2018
1 parent 9f987c8 commit 7c5d32e
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module ManageIQ::Providers
class Lenovo::PhysicalInfraManager::PhysicalSwitch < ::PhysicalSwitch
include_concern 'Operations'
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#
# Has the Power Operation methods for Physical Switches
#
module ManageIQ::Providers::Lenovo::PhysicalInfraManager::PhysicalSwitch::Operations
extend ActiveSupport::Concern

#
# Restarts the physical switch.
# it does the `power_cycle_soft` operation.
#
def restart
change_resource_state(:power_cycle_soft_switch)
end

private

#
# Sends the power operation for a Switch.
#
# @param [symbol] verb - the operation that must be sent
#
# @return the LXCA response
#
def change_resource_state(verb)
$lenovo_log.info("The :#{verb} for Physical Switch with uuid: #{uid_ems} is in progress")

ems = ExtManagementSystem.find(ems_id)
response = ems.connect.send(verb, uid_ems)

$lenovo_log.info("The :#{verb} for Physical Switch with uuid: #{uid_ems} is completed")

response
end
end
4 changes: 4 additions & 0 deletions spec/factories/physical_switch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FactoryGirl.define do
factory :lenovo_physical_switch, :class => ManageIQ::Providers::Lenovo::PhysicalInfraManager::PhysicalSwitch do
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
describe ManageIQ::Providers::Lenovo::PhysicalInfraManager::PhysicalSwitch do
context 'power operations' do
let(:physical_switch) do
physical_infra_manager = FactoryGirl.create(
:physical_infra,
:name => "LXCA",
:hostname => "10.243.9.123",
:port => "443",
:ipaddress => "https://10.243.9.123"
)

auth = FactoryGirl.create(
:authentication,
:userid => "admin",
:password => "password",
:authtype => "default"
)

physical_infra_manager.authentications = [auth]

FactoryGirl.create(
:lenovo_physical_switch,
:name => "Physical_Switch",
:uid_ems => "27997dba5dba11e89c2dfa7ae01bbebc",
:ext_management_system => physical_infra_manager
)
end

it 'should restart the physical switch' do
VCR.use_cassette("#{described_class.name.underscore}_restart") do
response = physical_switch.restart
expect(response.status).to eq(200)
end
end
end
end

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

0 comments on commit 7c5d32e

Please sign in to comment.