From a8eab805fddba0b77793b153b4cac7dfd553669a Mon Sep 17 00:00:00 2001 From: xuweibj Date: Mon, 7 Jan 2019 21:55:16 -0500 Subject: [PATCH] modify depending on discussion and comments --- .../hwctl/{executor => openbmc}/__init__.py | 0 .../{executor => openbmc}/openbmc_beacon.py | 0 .../openbmc_bmcconfig.py | 0 .../{executor => openbmc}/openbmc_eventlog.py | 0 .../{executor => openbmc}/openbmc_flash.py | 0 .../openbmc_inventory.py | 0 .../{executor => openbmc}/openbmc_power.py | 0 .../{executor => openbmc}/openbmc_sensor.py | 0 .../{executor => openbmc}/openbmc_setboot.py | 0 .../python/agent/hwctl/redfish/__init__.py | 0 .../{executor => redfish}/redfish_power.py | 0 .../lib/python/agent/hwctl/redfish_client.py | 16 +++-- .../lib/python/agent/xcatagent/openbmc.py | 14 ++-- .../lib/python/agent/xcatagent/redfish.py | 3 +- xCAT-server/lib/perl/xCAT/AGENT.pm | 71 +++++++++++++++++++ xCAT-server/lib/xcat/plugins/openbmc2.pm | 70 +----------------- xCAT-server/lib/xcat/plugins/redfish.pm | 71 +------------------ 17 files changed, 91 insertions(+), 154 deletions(-) rename xCAT-openbmc-py/lib/python/agent/hwctl/{executor => openbmc}/__init__.py (100%) rename xCAT-openbmc-py/lib/python/agent/hwctl/{executor => openbmc}/openbmc_beacon.py (100%) rename xCAT-openbmc-py/lib/python/agent/hwctl/{executor => openbmc}/openbmc_bmcconfig.py (100%) rename xCAT-openbmc-py/lib/python/agent/hwctl/{executor => openbmc}/openbmc_eventlog.py (100%) rename xCAT-openbmc-py/lib/python/agent/hwctl/{executor => openbmc}/openbmc_flash.py (100%) rename xCAT-openbmc-py/lib/python/agent/hwctl/{executor => openbmc}/openbmc_inventory.py (100%) rename xCAT-openbmc-py/lib/python/agent/hwctl/{executor => openbmc}/openbmc_power.py (100%) rename xCAT-openbmc-py/lib/python/agent/hwctl/{executor => openbmc}/openbmc_sensor.py (100%) rename xCAT-openbmc-py/lib/python/agent/hwctl/{executor => openbmc}/openbmc_setboot.py (100%) create mode 100644 xCAT-openbmc-py/lib/python/agent/hwctl/redfish/__init__.py rename xCAT-openbmc-py/lib/python/agent/hwctl/{executor => redfish}/redfish_power.py (100%) diff --git a/xCAT-openbmc-py/lib/python/agent/hwctl/executor/__init__.py b/xCAT-openbmc-py/lib/python/agent/hwctl/openbmc/__init__.py similarity index 100% rename from xCAT-openbmc-py/lib/python/agent/hwctl/executor/__init__.py rename to xCAT-openbmc-py/lib/python/agent/hwctl/openbmc/__init__.py diff --git a/xCAT-openbmc-py/lib/python/agent/hwctl/executor/openbmc_beacon.py b/xCAT-openbmc-py/lib/python/agent/hwctl/openbmc/openbmc_beacon.py similarity index 100% rename from xCAT-openbmc-py/lib/python/agent/hwctl/executor/openbmc_beacon.py rename to xCAT-openbmc-py/lib/python/agent/hwctl/openbmc/openbmc_beacon.py diff --git a/xCAT-openbmc-py/lib/python/agent/hwctl/executor/openbmc_bmcconfig.py b/xCAT-openbmc-py/lib/python/agent/hwctl/openbmc/openbmc_bmcconfig.py similarity index 100% rename from xCAT-openbmc-py/lib/python/agent/hwctl/executor/openbmc_bmcconfig.py rename to xCAT-openbmc-py/lib/python/agent/hwctl/openbmc/openbmc_bmcconfig.py diff --git a/xCAT-openbmc-py/lib/python/agent/hwctl/executor/openbmc_eventlog.py b/xCAT-openbmc-py/lib/python/agent/hwctl/openbmc/openbmc_eventlog.py similarity index 100% rename from xCAT-openbmc-py/lib/python/agent/hwctl/executor/openbmc_eventlog.py rename to xCAT-openbmc-py/lib/python/agent/hwctl/openbmc/openbmc_eventlog.py diff --git a/xCAT-openbmc-py/lib/python/agent/hwctl/executor/openbmc_flash.py b/xCAT-openbmc-py/lib/python/agent/hwctl/openbmc/openbmc_flash.py similarity index 100% rename from xCAT-openbmc-py/lib/python/agent/hwctl/executor/openbmc_flash.py rename to xCAT-openbmc-py/lib/python/agent/hwctl/openbmc/openbmc_flash.py diff --git a/xCAT-openbmc-py/lib/python/agent/hwctl/executor/openbmc_inventory.py b/xCAT-openbmc-py/lib/python/agent/hwctl/openbmc/openbmc_inventory.py similarity index 100% rename from xCAT-openbmc-py/lib/python/agent/hwctl/executor/openbmc_inventory.py rename to xCAT-openbmc-py/lib/python/agent/hwctl/openbmc/openbmc_inventory.py diff --git a/xCAT-openbmc-py/lib/python/agent/hwctl/executor/openbmc_power.py b/xCAT-openbmc-py/lib/python/agent/hwctl/openbmc/openbmc_power.py similarity index 100% rename from xCAT-openbmc-py/lib/python/agent/hwctl/executor/openbmc_power.py rename to xCAT-openbmc-py/lib/python/agent/hwctl/openbmc/openbmc_power.py diff --git a/xCAT-openbmc-py/lib/python/agent/hwctl/executor/openbmc_sensor.py b/xCAT-openbmc-py/lib/python/agent/hwctl/openbmc/openbmc_sensor.py similarity index 100% rename from xCAT-openbmc-py/lib/python/agent/hwctl/executor/openbmc_sensor.py rename to xCAT-openbmc-py/lib/python/agent/hwctl/openbmc/openbmc_sensor.py diff --git a/xCAT-openbmc-py/lib/python/agent/hwctl/executor/openbmc_setboot.py b/xCAT-openbmc-py/lib/python/agent/hwctl/openbmc/openbmc_setboot.py similarity index 100% rename from xCAT-openbmc-py/lib/python/agent/hwctl/executor/openbmc_setboot.py rename to xCAT-openbmc-py/lib/python/agent/hwctl/openbmc/openbmc_setboot.py diff --git a/xCAT-openbmc-py/lib/python/agent/hwctl/redfish/__init__.py b/xCAT-openbmc-py/lib/python/agent/hwctl/redfish/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/xCAT-openbmc-py/lib/python/agent/hwctl/executor/redfish_power.py b/xCAT-openbmc-py/lib/python/agent/hwctl/redfish/redfish_power.py similarity index 100% rename from xCAT-openbmc-py/lib/python/agent/hwctl/executor/redfish_power.py rename to xCAT-openbmc-py/lib/python/agent/hwctl/redfish/redfish_power.py diff --git a/xCAT-openbmc-py/lib/python/agent/hwctl/redfish_client.py b/xCAT-openbmc-py/lib/python/agent/hwctl/redfish_client.py index cb1d21f60..b8321d07b 100644 --- a/xCAT-openbmc-py/lib/python/agent/hwctl/redfish_client.py +++ b/xCAT-openbmc-py/lib/python/agent/hwctl/redfish_client.py @@ -32,6 +32,10 @@ POWER_RESET_TYPE = { 'on' : 'ForceOn', } +manager_reset_string = '#Manager.Reset' +system_reset_string = '#ComputerSystem.Reset' +reset_type_string = 'ResetType@Redfish.AllowableValues' + class RedfishRest(object): headers = {'Content-Type': 'application/json'} @@ -185,8 +189,8 @@ class RedfishRest(object): target_url = members[0]['@odata.id'] data = self.request('GET', target_url, cmd='get_bmc_actions') try: - actions = data['Actions']['#Manager.Reset']['ResetType@Redfish.AllowableValues'] - target_url = data['Actions']['#Manager.Reset']['target'] + actions = data['Actions'][manager_reset_string][reset_type_string] + target_url = data['Actions'][manager_reset_string]['target'] except KeyError as e: raise SelfServerException('Get KeyError %s' % e.message) @@ -196,7 +200,7 @@ class RedfishRest(object): target_url, actions = self._get_bmc_actions() if BMC_RESET_TYPE not in actions: - raise SelfClientException('Unsupport option: %s' % BMC_RESET_TYPE) + raise SelfClientException('Unsupported option: %s' % BMC_RESET_TYPE) data = { "ResetType": BMC_RESET_TYPE } return self.request('POST', target_url, payload=data, cmd='set_bmc_state') @@ -207,8 +211,8 @@ class RedfishRest(object): target_url = members[0]['@odata.id'] data = self.request('GET', target_url, cmd='get_power_actions') try: - actions = data['Actions']['#ComputerSystem.Reset']['ResetType@Redfish.AllowableValues'] - target_url = data['Actions']['#ComputerSystem.Reset']['target'] + actions = data['Actions'][system_reset_string][reset_type_string] + target_url = data['Actions'][system_reset_string]['target'] except KeyError as e: raise SelfServerException('Get KeyError %s' % e.message) @@ -218,7 +222,7 @@ class RedfishRest(object): target_url, actions = self._get_power_actions() if POWER_RESET_TYPE[state] not in actions: - raise SelfClientException('Unsupport option: %s' % state) + raise SelfClientException('Unsupported option: %s' % state) data = { "ResetType": POWER_RESET_TYPE[state] } return self.request('POST', target_url, payload=data, cmd='set_power_state') diff --git a/xCAT-openbmc-py/lib/python/agent/xcatagent/openbmc.py b/xCAT-openbmc-py/lib/python/agent/xcatagent/openbmc.py index 080ddef5e..3b96dca62 100644 --- a/xCAT-openbmc-py/lib/python/agent/xcatagent/openbmc.py +++ b/xCAT-openbmc-py/lib/python/agent/xcatagent/openbmc.py @@ -14,13 +14,13 @@ from docopt import docopt,DocoptExit from common import utils from common import exceptions as xcat_exception -from hwctl.executor.openbmc_beacon import OpenBMCBeaconTask -from hwctl.executor.openbmc_setboot import OpenBMCBootTask -from hwctl.executor.openbmc_flash import OpenBMCFlashTask -from hwctl.executor.openbmc_inventory import OpenBMCInventoryTask -from hwctl.executor.openbmc_power import OpenBMCPowerTask -from hwctl.executor.openbmc_sensor import OpenBMCSensorTask -from hwctl.executor.openbmc_eventlog import OpenBMCEventlogTask +from hwctl.openbmc.openbmc_beacon import OpenBMCBeaconTask +from hwctl.openbmc.openbmc_setboot import OpenBMCBootTask +from hwctl.openbmc.openbmc_flash import OpenBMCFlashTask +from hwctl.openbmc.openbmc_inventory import OpenBMCInventoryTask +from hwctl.openbmc.openbmc_power import OpenBMCPowerTask +from hwctl.openbmc.openbmc_sensor import OpenBMCSensorTask +from hwctl.openbmc.openbmc_eventlog import OpenBMCEventlogTask from hwctl.beacon import DefaultBeaconManager from hwctl.setboot import DefaultBootManager from hwctl.flash import DefaultFlashManager diff --git a/xCAT-openbmc-py/lib/python/agent/xcatagent/redfish.py b/xCAT-openbmc-py/lib/python/agent/xcatagent/redfish.py index 7bbc81381..322f651cc 100644 --- a/xCAT-openbmc-py/lib/python/agent/xcatagent/redfish.py +++ b/xCAT-openbmc-py/lib/python/agent/xcatagent/redfish.py @@ -13,9 +13,8 @@ from docopt import docopt,DocoptExit from common import utils from common import exceptions as xcat_exception -from hwctl.executor.redfish_power import RedfishPowerTask +from hwctl.redfish.redfish_power import RedfishPowerTask from hwctl.power import DefaultPowerManager -from hwctl.setboot import DefaultBootManager from xcatagent import base import logging diff --git a/xCAT-server/lib/perl/xCAT/AGENT.pm b/xCAT-server/lib/perl/xCAT/AGENT.pm index aee201cbe..c44ea71d7 100644 --- a/xCAT-server/lib/perl/xCAT/AGENT.pm +++ b/xCAT-server/lib/perl/xCAT/AGENT.pm @@ -33,6 +33,77 @@ my %module_type = ( "redfish" => "Redfish", ); +#------------------------------------------------------- + +=head3 parse_node_info + + Parse the node information: bmc, bmcip, username, password + +=cut + +#------------------------------------------------------- +sub parse_node_info { + my $noderange = shift; + my $module = shift; + my $node_info_ref = shift; + my $callback = shift; + my $rst = 0; + + my $passwd_table = xCAT::Table->new('passwd'); + my $passwd_hash = $passwd_table->getAttribs({ 'key' => $module }, qw(username password)); + + my $openbmc_table = xCAT::Table->new('openbmc'); + my $openbmc_hash = $openbmc_table->getNodesAttribs(\@$noderange, ['bmc', 'username', 'password']); + + foreach my $node (@$noderange) { + if (defined($openbmc_hash->{$node}->[0])) { + if ($openbmc_hash->{$node}->[0]->{'bmc'}) { + $node_info_ref->{$node}->{bmc} = $openbmc_hash->{$node}->[0]->{'bmc'}; + $node_info_ref->{$node}->{bmcip} = xCAT::NetworkUtils::getNodeIPaddress($openbmc_hash->{$node}->[0]->{'bmc'}); + } + unless($node_info_ref->{$node}->{bmc}) { + xCAT::SvrUtils::sendmsg("Error: Unable to get attribute bmc", $callback, $node); + delete $node_info_ref->{$node}; + $rst = 1; + next; + } + unless($node_info_ref->{$node}->{bmcip}) { + xCAT::SvrUtils::sendmsg("Error: Unable to resolve ip address for bmc: $node_info_ref->{$node}->{bmc}", $callback, $node); + delete $node_info_ref->{$node}; + $rst = 1; + next; + } + if ($openbmc_hash->{$node}->[0]->{'username'}) { + $node_info_ref->{$node}->{username} = $openbmc_hash->{$node}->[0]->{'username'}; + } elsif ($passwd_hash and $passwd_hash->{username}) { + $node_info_ref->{$node}->{username} = $passwd_hash->{username}; + } else { + xCAT::SvrUtils::sendmsg("Error: Unable to get attribute username", $callback, $node); + delete $node_info_ref->{$node}; + $rst = 1; + next; + } + + if ($openbmc_hash->{$node}->[0]->{'password'}) { + $node_info_ref->{$node}->{password} = $openbmc_hash->{$node}->[0]->{'password'}; + } elsif ($passwd_hash and $passwd_hash->{password}) { + $node_info_ref->{$node}->{password} = $passwd_hash->{password}; + } else { + xCAT::SvrUtils::sendmsg("Error: Unable to get attribute password", $callback, $node); + delete $node_info_ref->{$node}; + $rst = 1; + next; + } + } else { + xCAT::SvrUtils::sendmsg("Error: Unable to get information from openbmc table", $callback, $node); + $rst = 1; + next; + } + } + + return $rst; +} + sub acquire_lock { my $ppid = shift; $ppid = shift if (($ppid) && ($ppid =~ /AGENT/)); diff --git a/xCAT-server/lib/xcat/plugins/openbmc2.pm b/xCAT-server/lib/xcat/plugins/openbmc2.pm index a70a2f5ee..4a73fdcfb 100644 --- a/xCAT-server/lib/xcat/plugins/openbmc2.pm +++ b/xCAT-server/lib/xcat/plugins/openbmc2.pm @@ -141,7 +141,7 @@ sub process_request { } my $noderange = $request->{node}; - my $check = parse_node_info($noderange); + my $check = xCAT::AGENT::parse_node_info($noderange, "openbmc", \%node_info, $callback); if (&refactor_args($request)) { xCAT::MsgUtils->message("E", { data => ["Failed to refactor arguments"] }, $callback); return; @@ -418,74 +418,6 @@ sub parse_args { #------------------------------------------------------- -=head3 parse_node_info - - Parse the node information: bmc, bmcip, username, password - -=cut - -#------------------------------------------------------- -sub parse_node_info { - my $noderange = shift; - my $rst = 0; - - my $passwd_table = xCAT::Table->new('passwd'); - my $passwd_hash = $passwd_table->getAttribs({ 'key' => 'openbmc' }, qw(username password)); - - my $openbmc_table = xCAT::Table->new('openbmc'); - my $openbmc_hash = $openbmc_table->getNodesAttribs(\@$noderange, ['bmc', 'username', 'password']); - - foreach my $node (@$noderange) { - if (defined($openbmc_hash->{$node}->[0])) { - if ($openbmc_hash->{$node}->[0]->{'bmc'}) { - $node_info{$node}{bmc} = $openbmc_hash->{$node}->[0]->{'bmc'}; - $node_info{$node}{bmcip} = xCAT::NetworkUtils::getNodeIPaddress($openbmc_hash->{$node}->[0]->{'bmc'}); - } - unless($node_info{$node}{bmc}) { - xCAT::SvrUtils::sendmsg("Error: Unable to get attribute bmc", $callback, $node); - delete $node_info{$node}; - $rst = 1; - next; - } - unless($node_info{$node}{bmcip}) { - xCAT::SvrUtils::sendmsg("Error: Unable to resolve ip address for bmc: $node_info{$node}{bmc}", $callback, $node); - delete $node_info{$node}; - $rst = 1; - next; - } - if ($openbmc_hash->{$node}->[0]->{'username'}) { - $node_info{$node}{username} = $openbmc_hash->{$node}->[0]->{'username'}; - } elsif ($passwd_hash and $passwd_hash->{username}) { - $node_info{$node}{username} = $passwd_hash->{username}; - } else { - xCAT::SvrUtils::sendmsg("Error: Unable to get attribute username", $callback, $node); - delete $node_info{$node}; - $rst = 1; - next; - } - - if ($openbmc_hash->{$node}->[0]->{'password'}) { - $node_info{$node}{password} = $openbmc_hash->{$node}->[0]->{'password'}; - } elsif ($passwd_hash and $passwd_hash->{password}) { - $node_info{$node}{password} = $passwd_hash->{password}; - } else { - xCAT::SvrUtils::sendmsg("Error: Unable to get attribute password", $callback, $node); - delete $node_info{$node}; - $rst = 1; - next; - } - } else { - xCAT::SvrUtils::sendmsg("Error: Unable to get information from openbmc table", $callback, $node); - $rst = 1; - next; - } - } - - return $rst; -} - -#------------------------------------------------------- - =head3 refactor_args refractor args to be easily dealt by python client diff --git a/xCAT-server/lib/xcat/plugins/redfish.pm b/xCAT-server/lib/xcat/plugins/redfish.pm index 984860e79..491512a7d 100644 --- a/xCAT-server/lib/xcat/plugins/redfish.pm +++ b/xCAT-server/lib/xcat/plugins/redfish.pm @@ -117,7 +117,7 @@ sub process_request { } my $noderange = $request->{node}; - my $check = parse_node_info($noderange); + my $check = xCAT::AGENT::parse_node_info($noderange, "redfish", \%node_info, $callback); $callback->({ errorcode => [$check] }) if ($check); return unless(%node_info); @@ -170,73 +170,4 @@ sub parse_args { } } -#------------------------------------------------------- - -=head3 parse_node_info - - Parse the node information: bmc, bmcip, username, password - -=cut - -#------------------------------------------------------- - -sub parse_node_info { - my $noderange = shift; - my $rst = 0; - - my $passwd_table = xCAT::Table->new('passwd'); - my $passwd_hash = $passwd_table->getAttribs({ 'key' => 'redfish' }, qw(username password)); - - my $my_table = xCAT::Table->new('openbmc'); - my $my_hash = $my_table->getNodesAttribs(\@$noderange, ['bmc', 'username', 'password']); - - foreach my $node (@$noderange) { - if (defined($my_hash->{$node}->[0])) { - if ($my_hash->{$node}->[0]->{'bmc'}) { - $node_info{$node}{bmc} = $my_hash->{$node}->[0]->{'bmc'}; - $node_info{$node}{bmcip} = xCAT::NetworkUtils::getNodeIPaddress($my_hash->{$node}->[0]->{'bmc'}); - } - unless($node_info{$node}{bmc}) { - xCAT::SvrUtils::sendmsg("Error: Unable to get attribute bmc", $callback, $node); - delete $node_info{$node}; - $rst = 1; - next; - } - unless($node_info{$node}{bmcip}) { - xCAT::SvrUtils::sendmsg("Error: Unable to resolve ip address for bmc: $node_info{$node}{bmc}", $callback, $node); - delete $node_info{$node}; - $rst = 1; - next; - } - if ($my_hash->{$node}->[0]->{'username'}) { - $node_info{$node}{username} = $my_hash->{$node}->[0]->{'username'}; - } elsif ($passwd_hash and $passwd_hash->{username}) { - $node_info{$node}{username} = $passwd_hash->{username}; - } else { - xCAT::SvrUtils::sendmsg("Error: Unable to get attribute username", $callback, $node); - delete $node_info{$node}; - $rst = 1; - next; - } - - if ($my_hash->{$node}->[0]->{'password'}) { - $node_info{$node}{password} = $my_hash->{$node}->[0]->{'password'}; - } elsif ($passwd_hash and $passwd_hash->{password}) { - $node_info{$node}{password} = $passwd_hash->{password}; - } else { - xCAT::SvrUtils::sendmsg("Error: Unable to get attribute password", $callback, $node); - delete $node_info{$node}; - $rst = 1; - next; - } - } else { - xCAT::SvrUtils::sendmsg("Error: Unable to get information from openbmc table", $callback, $node); - $rst = 1; - next; - } - } - - return $rst; -} - 1;