mirror of
https://github.com/xcat2/xcat-core.git
synced 2025-05-29 17:23:08 +00:00
code checkin for P8 energy support with CIM
This commit is contained in:
parent
35bbcafc43
commit
a9cc379b7f
@ -47,6 +47,7 @@ use Data::Dumper;
|
||||
Return:
|
||||
A hash reference. The valid key includes:
|
||||
rc - The return code. 0 - success. > 0 - fail.
|
||||
cim_rc - The return code from CIM server.
|
||||
msg - Output message.
|
||||
value - Array of instances, each instance is a hash contains lots of properties.
|
||||
=cut
|
||||
@ -146,7 +147,9 @@ sub enum_instance
|
||||
# check the error message from CIM
|
||||
my $error_node = $resp_doc->getElementsByTagName("ERROR");
|
||||
if ($error_node) {
|
||||
return ({rc => 1, cimcode => $error_node->[0]->getAttribute("CODE"), msg => $error_node->[0]->getAttribute("DESCRIPTION")});
|
||||
my $msg = $error_node->[0]->getAttribute("DESCRIPTION");
|
||||
my $errorcode = $error_node->[0]->getAttribute("CODE");
|
||||
return ({rc => 1, cim_rc => $errorcode, msg => $error_node->[0]->getAttribute("DESCRIPTION")." [cim return code: $errorcode]"});
|
||||
}
|
||||
|
||||
# get all the instance elements
|
||||
@ -283,7 +286,11 @@ sub send_http_request
|
||||
|
||||
# create a new HTTP User Agent Object
|
||||
my $ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => 0, SSL_verify_mode => 0});
|
||||
$ua->timeout(500);
|
||||
if ($http_params->{timeout}) {
|
||||
$ua->timeout($http_params->{timeout});
|
||||
} else {
|
||||
$ua->timeout(10); # the default timeout is 10s
|
||||
}
|
||||
|
||||
# send request and receive the response
|
||||
my $response = $ua->request($http_request);
|
||||
@ -291,10 +298,12 @@ sub send_http_request
|
||||
# check the http response
|
||||
if (defined ($response) && defined ($response->{_rc}) && defined ($response->{_msg})) {
|
||||
if ($response->{_rc} eq "200" && $response->{_msg} eq "OK") {
|
||||
return ({rc => 0, http_rc => $response->{_rc}, payload => $response->{_content}});
|
||||
return ({rc => 0, http_rc => $response->{_rc}, msg => "$response->{_msg} [http return code: $response->{_rc}]", payload => $response->{_content}});
|
||||
}
|
||||
}
|
||||
|
||||
return ({rc => 1, http_rc => $response->{_rc}, msg => $response->{_msg}});
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
@ -3298,13 +3298,68 @@ sub noderangecontainsMn
|
||||
return; # if no MN in the noderange, return nothing
|
||||
}
|
||||
|
||||
|
||||
# the MTM of P6 and P7 machine
|
||||
my %MTM_P6P7 = (
|
||||
# P6 systems
|
||||
'7998-60X' => 1,
|
||||
'7998-61X' => 1,
|
||||
'7778-23X' => 1,
|
||||
'8203-E4A' => 1,
|
||||
'8204-E8A' => 1,
|
||||
'8234-EMA' => 1,
|
||||
'9117-MMA' => 1,
|
||||
'9119-FHA' => 1,
|
||||
|
||||
# P7 systems
|
||||
'8406-70Y' => 1,
|
||||
'8406-71Y' => 1,
|
||||
'7891-73X' => 1,
|
||||
'7891-74X' => 1,
|
||||
'8231-E2B' => 1,
|
||||
'8202-E4B' => 1,
|
||||
'8231-E2B' => 1,
|
||||
'8205-E6B' => 1,
|
||||
'8233-E8B' => 1,
|
||||
'8236-E8C' => 1,
|
||||
'9117-MMB' => 1,
|
||||
'9179-MHB' => 1,
|
||||
'9119-FHB' => 1,
|
||||
);
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
=head3 isP6P7
|
||||
|
||||
Check whether a MTM is a P6 or P7 machine
|
||||
Parameter: MTM of Power machine
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
sub isP6P7
|
||||
{
|
||||
my $class = shift;
|
||||
my $mtm = shift;
|
||||
|
||||
if ($class !~ /Utils/) {
|
||||
$mtm = $class;
|
||||
}
|
||||
|
||||
if (defined $MTM_P6P7{$mtm} && $MTM_P6P7{$mtm} == 1) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
=head3 filter_nodes
|
||||
##########################################################################
|
||||
# Fliter the nodes to specific groups
|
||||
# For specific command, figure out the node lists which should be handled by blade.pm, fsp.pm or ipmi.pm
|
||||
# mp group: the nodes will be handled by blade.pm
|
||||
# fsp group: the nodes will be handled by fsp.pm
|
||||
# bmc group: the nodes will be handled by ipmi.pm
|
||||
# mp group (argument: $mpnodes): the nodes will be handled by blade.pm
|
||||
# fsp group (argument: $fspnodes): the nodes will be handled by fsp.pm
|
||||
# bmc group (argument: $bmcnodes): the nodes will be handled by ipmi.pm
|
||||
# For rspconfig network, the NGP ppc blade will be included in the group of mp, othewise in the fsp group
|
||||
# For getmacs -D, the NGP ppc blade will be included in the group of common fsp, otherwise in the mp group
|
||||
# For renergy command, NGP blade will be moved to mp group
|
||||
@ -3346,13 +3401,29 @@ sub filter_nodes{
|
||||
if ($ipmitab) {
|
||||
$ipmitabhash = $ipmitab->getNodesAttribs(\@nodes,['bmc']);
|
||||
}
|
||||
|
||||
# get the node attributes from the nodehm table
|
||||
my $nodehmhash;
|
||||
my $nodehmtab = xCAT::Table->new("nodehm");
|
||||
if ($nodehmtab) {
|
||||
$nodehmhash = $nodehmtab->getNodesAttribs(\@nodes,['mgt']);
|
||||
}
|
||||
|
||||
my (@mp, @ngpfsp, @ngpbmc, @commonfsp, @commonbmc, @unknow);
|
||||
# get the node attributes from the nodetype table
|
||||
my $nodetypehash;
|
||||
my $nodetypetab = xCAT::Table->new("nodetype");
|
||||
if ($nodetypetab) {
|
||||
$nodetypehash = $nodetypetab->getNodesAttribs(\@nodes, ['arch']);
|
||||
}
|
||||
|
||||
# get the node attributes from the vpd table
|
||||
my $vpdhash,
|
||||
my $vpdtab = xCAT::Table->new("vpd");
|
||||
if ($vpdtab) {
|
||||
$vpdhash = $vpdtab->getNodesAttribs(\@nodes, ['mtm']);
|
||||
}
|
||||
|
||||
my (@mp, @ngpfsp, @ngpbmc, @commonfsp, @commonbmc, @unknow, @nonppcle, @p6p7);
|
||||
|
||||
# if existing in both 'mpa' and 'ppc', a ngp power blade
|
||||
# if existing in both 'mpa' and 'ipmi', a ngp x86 blade
|
||||
@ -3386,9 +3457,21 @@ sub filter_nodes{
|
||||
} elsif (defined ($ppctabhash->{$_}->[0]) && defined ($ppctabhash->{$_}->[0]->{'hcp'})) {
|
||||
# common power node
|
||||
push @commonfsp, $_;
|
||||
# whether is a Power 8 or higher with FSP
|
||||
if (defined ($vpdhash->{$_}->[0]) && defined ($vpdhash->{$_}->[0]->{'mtm'})) {
|
||||
if (isP6P7($vpdhash->{$_}->[0]->{'mtm'})) {
|
||||
push @p6p7, $_;
|
||||
}
|
||||
}
|
||||
} elsif (defined ($ipmitabhash->{$_}->[0]) && defined ($ipmitabhash->{$_}->[0]->{'bmc'})) {
|
||||
# common bmc node
|
||||
push @commonbmc, $_;
|
||||
# whether is a Power 8 or higher with FSP
|
||||
if (defined ($nodetypehash->{$_}->[0]) && defined ($nodetypehash->{$_}->[0]->{'arch'})) {
|
||||
if ($nodetypehash->{$_}->[0]->{'arch'} ne "ppc64le") {
|
||||
push @nonppcle, $_;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
push @unknow, $_;
|
||||
}
|
||||
@ -3422,6 +3505,16 @@ sub filter_nodes{
|
||||
push @{$mpnodes}, @ngpfsp;
|
||||
}
|
||||
} elsif ($cmd eq "renergy") {
|
||||
# for renergy command, only the p6,p7 get to the general fsp.pm
|
||||
# P8 and higher will get in the energy.pm
|
||||
@{$fspnodes} = ();
|
||||
push @{$fspnodes}, @p6p7;
|
||||
|
||||
# for rnergy command, only the non-ppcle nodes get to the general ipmi.pm
|
||||
# ppcle of P8 and higher will get in the energy.pm
|
||||
@{$bmcnodes} = ();
|
||||
push @{$bmcnodes}, @nonppcle;
|
||||
|
||||
if (grep /^(relhistogram)/, @args) {
|
||||
push @{$bmcnodes}, @ngpbmc;
|
||||
} else {
|
||||
|
628
xCAT-server/lib/xcat/plugins/energy.pm
Normal file
628
xCAT-server/lib/xcat/plugins/energy.pm
Normal file
@ -0,0 +1,628 @@
|
||||
#!/usr/bin/perl
|
||||
# IBM(c) 2014 EPL license http://www.eclipse.org/legal/epl-v10.html
|
||||
|
||||
=head3 xCAT_plugin::energy
|
||||
|
||||
This plugin module is used to handle the renergy command for:
|
||||
FSP based Power 8 machine.
|
||||
1. mgt=fsp, mtm=(p8); 2. mgt=ipmi, arch=ppc64le;
|
||||
|
||||
=cut
|
||||
|
||||
package xCAT_plugin::energy;
|
||||
BEGIN
|
||||
{
|
||||
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat';
|
||||
}
|
||||
|
||||
use lib "$::XCATROOT/lib/perl";
|
||||
use strict;
|
||||
use warnings "all";
|
||||
use Getopt::Long;
|
||||
|
||||
use xCAT::Usage;
|
||||
use xCAT::CIMUtils;
|
||||
use xCAT::MsgUtils;
|
||||
use xCAT::Table;
|
||||
use xCAT::FSPUtils;
|
||||
|
||||
sub handled_commands {
|
||||
return {
|
||||
renergy => 'nodehm:mgt=ipmi|fsp',
|
||||
}
|
||||
}
|
||||
|
||||
# The hash includes all valid attribute for quering
|
||||
my %QUERY_ATTRS = (
|
||||
'savingstatus' => 1,
|
||||
'dsavingstatus' => 1,
|
||||
'cappingstatus' => 1,
|
||||
'cappingmaxmin' => 1,
|
||||
'cappingvalue' => 1,
|
||||
'cappingsoftmin' => 1,
|
||||
'averageAC' => 1,
|
||||
'averageDC' => 1,
|
||||
'ambienttemp' => 1,
|
||||
'exhausttemp' => 1,
|
||||
'CPUspeed' => 1,
|
||||
'syssbpower' => 1,
|
||||
'sysIPLtime' => 1,
|
||||
# for FFO, only supported when communicating to fsp directly
|
||||
'ffoMin' => 1,
|
||||
'ffoVmin' => 1,
|
||||
'ffoTurbo' => 1,
|
||||
'ffoNorm' => 1,
|
||||
'fsavingstatus' => 1,
|
||||
'ffovalue' => 1,
|
||||
);
|
||||
|
||||
# The hash includes all valid attribute for writting
|
||||
my %SET_ATTRS = (
|
||||
'savingstatus' => 1,
|
||||
'dsavingstatus' => 1,
|
||||
'cappingstatus' => 1,
|
||||
'cappingwatt' => 1,
|
||||
'cappingperc' => 1,
|
||||
# for FFO
|
||||
'fsavingstatus' => 1,
|
||||
'ffovalue' => 1,
|
||||
);
|
||||
|
||||
=head3 parse_args
|
||||
|
||||
DESCRIPTION:
|
||||
Parse the arguments from the command line of renergy command
|
||||
ARGUMENTS:
|
||||
The request hash from preprocess_request or process_request
|
||||
RETURN
|
||||
First element: rc: 0 -success; 1 - fail
|
||||
Second element:
|
||||
1. a string: a message for display;
|
||||
2. a reference to a hash: {verbose}, {query_list} and {set_pair}.
|
||||
|
||||
=cut
|
||||
sub parse_args {
|
||||
my $request = shift;
|
||||
|
||||
my $opt = ();
|
||||
my $cmd = $request->{command}->[0];
|
||||
my $args = $request->{arg};
|
||||
my $nodes = $request->{node};
|
||||
|
||||
my @query_list = (); # The attributes list for query operation
|
||||
my @set_pair = (); # The attribute need to be set. e.g. savingstatus=on
|
||||
|
||||
my $set_flag = (); # Indicate there's setting param in the argv
|
||||
my $query_flag = (); # Indicate there's param in the argv
|
||||
|
||||
# set the usage subroutine
|
||||
local *usage = sub {
|
||||
my $add_msg = shift;
|
||||
my $usage_string = xCAT::Usage->getUsage($cmd);
|
||||
if ($add_msg) {
|
||||
return("$add_msg\n".$usage_string);
|
||||
} else {
|
||||
return($usage_string);
|
||||
}
|
||||
};
|
||||
|
||||
# handle the arguments
|
||||
if ($request->{arg}) {
|
||||
@ARGV = @{$request->{arg}};
|
||||
|
||||
$Getopt::Long::ignorecase = 0;
|
||||
Getopt::Long::Configure( "bundling" );
|
||||
|
||||
if (!GetOptions( 'V' => \$::VERBOSE,
|
||||
'h|help' => \$::HELP,
|
||||
'v|version' => \$::VERSION)) {
|
||||
return (1, &usage());
|
||||
}
|
||||
if ($::HELP && $::VERSION) {
|
||||
return (1, &usage());
|
||||
}
|
||||
if ($::HELP) {
|
||||
return (0, &usage());
|
||||
}
|
||||
|
||||
if ($::VERSION) {
|
||||
my $version_string = xCAT::Usage->getVersion('renergy');
|
||||
return(0, $version_string);
|
||||
}
|
||||
|
||||
if ($::VERBOSE) {
|
||||
$opt->{verbose} = 1;
|
||||
}
|
||||
}
|
||||
|
||||
# if the request has node range
|
||||
if ($nodes) {
|
||||
# the default option is query all attributes
|
||||
if ($#ARGV < 0) {
|
||||
$ARGV[0] = "all";
|
||||
}
|
||||
# Check the validity of the parameters of Query and Set
|
||||
# Forbid to perform both query and set
|
||||
foreach my $attr (@ARGV) {
|
||||
my ($set_attr, $set_value) = split (/=/, $attr);
|
||||
if (defined($set_value)) {
|
||||
if ($query_flag) {
|
||||
return (1, &usage("Cannot perform both Query and Set."));
|
||||
}
|
||||
|
||||
# make sure the attribute is valid
|
||||
if ($SET_ATTRS{$set_attr} != 1) {
|
||||
return (1, &usage());
|
||||
}
|
||||
|
||||
# make sure the value for attirbute is valid
|
||||
if (($set_attr eq "savingstatus" || $set_attr eq "fsavingstatus")
|
||||
&& ($set_value ne "on" && $set_value ne "off")) {
|
||||
return (1, &usage());
|
||||
} elsif ($set_attr eq "dsavingstatus"
|
||||
&& ($set_value ne "off"
|
||||
&& $set_value ne "on-norm" && $set_value ne "on-maxp")) {
|
||||
return (1, &usage());
|
||||
} elsif ($set_attr eq "cappingstatus"
|
||||
&& ($set_value ne "on" && $set_value ne "off")) {
|
||||
return (1, &usage());
|
||||
} elsif ( ($set_attr eq "cappingwatt"
|
||||
|| $set_attr eq "cappingperc" || $set_attr eq "ffovalue")
|
||||
&& $set_value =~ /\D/) {
|
||||
return (1, &usage());
|
||||
}
|
||||
|
||||
push @set_pair, $set_attr."=".$set_value;
|
||||
$set_flag = 1;
|
||||
} else {
|
||||
if ($set_flag) {
|
||||
return (1, &usage("Cannot perform both Query and Set."));
|
||||
}
|
||||
|
||||
# replace the 'all' with all valid attribute
|
||||
if ($attr eq "all") {
|
||||
foreach my $q_attr (keys %QUERY_ATTRS) {
|
||||
if (!grep (/^$q_attr$/, @query_list)) {
|
||||
push @query_list, $q_attr;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
# make sure the query attribute is valid
|
||||
if ($QUERY_ATTRS{$attr} != 1) {
|
||||
return (1, &usage("Invalid attribute."));
|
||||
}
|
||||
if (!grep (/^$attr$/, @query_list)) {
|
||||
push @query_list, $attr;
|
||||
}
|
||||
}
|
||||
$query_flag = 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
# no noderange, do nothing
|
||||
return (1, &usage());
|
||||
}
|
||||
|
||||
if (@query_list) {
|
||||
$opt->{'query_list'} = join(',', @query_list);
|
||||
} elsif (@set_pair) {
|
||||
$opt->{'set_pair'} = join(',',@set_pair);
|
||||
}
|
||||
|
||||
return (0, $opt);
|
||||
}
|
||||
|
||||
sub preprocess_request
|
||||
{
|
||||
my $req = shift;
|
||||
my $callback = shift;
|
||||
|
||||
# Exit if the packet has been preprocessed
|
||||
if (defined ($req->{_xcatpreprocessed}) && $req->{_xcatpreprocessed}->[0] == 1) { return [$req]; }
|
||||
|
||||
my ($rc, $args) = parse_args($req);
|
||||
if ($rc) {
|
||||
# error or message display happens
|
||||
xCAT::MsgUtils->message("E", {error => [$args], errorcode => [$rc]}, $callback);
|
||||
return;
|
||||
} else {
|
||||
unless (ref($args)) {
|
||||
xCAT::MsgUtils->message("I", {data => [$args]}, $callback);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# do nothing if no query or setting required.
|
||||
unless (defined ($args->{query_list}) || defined($args->{set_pair})) {
|
||||
return;
|
||||
}
|
||||
|
||||
# This plugin only handle the node which is 1. mgt=fsp, mtm=(p8); 2. mgt=ipmi, arch=ppc64le;
|
||||
# otherwise, make other plugin to handle it
|
||||
my (@mpnodes, @fspnodes, @bmcnodes, @nohandle);
|
||||
xCAT::Utils->filter_nodes($req, \@mpnodes, \@fspnodes, \@bmcnodes, \@nohandle);
|
||||
|
||||
# Find the nodes which are not handled by mp (@mpnodes), fsp (@fspnodes) and bmc (@bmcnods), and not in @nohandle.
|
||||
# They are the one of p8_fsp nodes which should be handled by this plugin
|
||||
my %tmphash = map {$_ => 1} (@mpnodes, @fspnodes, @bmcnodes, @nohandle);
|
||||
my @nodes = grep {not $tmphash{$_}} @{$req->{node}};
|
||||
|
||||
# build request array
|
||||
my @requests;
|
||||
if (@nodes) {
|
||||
my $sn = xCAT::ServiceNodeUtils->get_ServiceNode( \@nodes, 'xcat', 'MN' );
|
||||
|
||||
# Build each request for each service node
|
||||
foreach my $snkey ( keys %$sn ) {
|
||||
my $reqcopy = {%$req};
|
||||
$reqcopy->{node} = $sn->{$snkey};
|
||||
$reqcopy->{'_xcatdest'} = $snkey;
|
||||
$reqcopy->{_xcatpreprocessed}->[0] = 1;
|
||||
if (defined($args->{verbose})) {
|
||||
$reqcopy->{verbose} = $args->{verbose};
|
||||
}
|
||||
if (defined($args->{query_list})) {
|
||||
$reqcopy->{query_list} = $args->{query_list};
|
||||
}
|
||||
if (defined($args->{set_pair})) {
|
||||
$reqcopy->{set_pair} = $args->{set_pair};
|
||||
}
|
||||
push @requests, $reqcopy;
|
||||
}
|
||||
|
||||
return \@requests;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
sub process_request {
|
||||
my $request = shift;
|
||||
my $callback = shift;
|
||||
my $subreq = shift;
|
||||
|
||||
my $verbose;
|
||||
|
||||
my $nodes = $request->{node};
|
||||
my $args = $request->{arg};
|
||||
if (defined($request->{verbose})) {
|
||||
$verbose = $request->{verbose};
|
||||
}
|
||||
|
||||
# get the password for the nodes
|
||||
my $user_default = "admin";
|
||||
my $password_default = "admin";
|
||||
|
||||
my $ipmi_tab = xCAT::Table->new('ipmi', -create=>0);
|
||||
my $ipmi_hash;
|
||||
if ($ipmi_tab) {
|
||||
$ipmi_hash = $ipmi_tab->getNodesAttribs($request->{node}, ['bmc', 'username','password']);
|
||||
}
|
||||
|
||||
my $ppc_tab = xCAT::Table->new('ppc', -create=>0);
|
||||
my $ppc_hash;
|
||||
my @ppc_all_entry;
|
||||
my $cec2fsp;
|
||||
if ($ppc_tab) {
|
||||
$ppc_hash = $ppc_tab->getNodesAttribs($request->{node}, ['hcp', 'nodetype']);
|
||||
}
|
||||
|
||||
my $nodehm_tab = xCAT::Table->new('nodehm', -create => 0);
|
||||
my $nodehm_hash;
|
||||
if ($nodehm_tab) {
|
||||
$nodehm_hash = $nodehm_tab->getNodesAttribs($request->{node}, ['mgt']);
|
||||
}
|
||||
|
||||
my $ppcdirect_tab = xCAT::Table->new('ppcdirect', -create=>0);
|
||||
|
||||
foreach my $node (@{$request->{node}}) {
|
||||
my $user = $user_default;
|
||||
my $password = $password_default;
|
||||
my $hcp_ip;
|
||||
|
||||
if (defined ($nodehm_hash->{$node}->[0]->{mgt})) {
|
||||
my $mgt = $nodehm_hash->{$node}->[0]->{mgt};
|
||||
|
||||
if ($mgt eq 'fsp') {
|
||||
# This is Power node which is running in PowerVM mode
|
||||
unless (@ppc_all_entry) {
|
||||
@ppc_all_entry = $ppc_tab->getAllNodeAttribs(['node', 'parent', 'hcp', 'nodetype']);
|
||||
foreach my $ppcentry (@ppc_all_entry) {
|
||||
if (defined($ppcentry->{parent})) {
|
||||
$cec2fsp->{$ppcentry->{parent}} .= "$ppcentry->{node},";
|
||||
}
|
||||
}
|
||||
}
|
||||
$hcp_ip = $cec2fsp->{$node};
|
||||
|
||||
# Get the user/password for the node
|
||||
if ($ppcdirect_tab) {
|
||||
my $ppcdirect_hash = $ppcdirect_tab->getAttribs({hcp => $node, username => $user}, 'password');
|
||||
if ($ppcdirect_hash) {
|
||||
$password = $ppcdirect_hash->{'password'};
|
||||
}
|
||||
}
|
||||
} elsif ($mgt eq 'ipmi') {
|
||||
if (defined ($ipmi_hash->{$node}->[0]->{bmc})){
|
||||
# This is a ipmi managed node. (should be a ppcle)
|
||||
$hcp_ip = $ipmi_hash->{$node}->[0]->{bmc};
|
||||
if (defined ($ipmi_hash->{$node}->[0]->{username})){
|
||||
$user = $ipmi_hash->{$node}->[0]->{username};
|
||||
$password = $ipmi_hash->{$node}->[0]->{password};
|
||||
}
|
||||
} else {
|
||||
xCAT::MsgUtils->message("E", {data => ["$node: Missed attribute [bmc]."]}, $callback);
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
xCAT::MsgUtils->message("E", {data => ["$node: Support the valid mgt [fsp, ipmi]."]}, $callback);
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
xCAT::MsgUtils->message("E", {data => ["$node: Missed important attributes [mgt] to know how to handle this node."]}, $callback);
|
||||
return 1;
|
||||
}
|
||||
unless ($hcp_ip) {
|
||||
xCAT::MsgUtils->message("E", {data => ["$node: Cannot find HCP"]}, $callback);
|
||||
return 1;
|
||||
}
|
||||
foreach my $ip (split(',', $hcp_ip)) {
|
||||
unless ($ip) { next; }
|
||||
my %args = (
|
||||
node => $node,
|
||||
ip => $ip,
|
||||
port => '5989',
|
||||
method => 'POST',
|
||||
user => $user,
|
||||
password => $password);
|
||||
|
||||
if ($verbose) {
|
||||
xCAT::MsgUtils->message("I", {data => ["$node: Access hcp [$ip], user [$user], passowrd [$password]"]}, $callback);
|
||||
}
|
||||
# call the cim utils to connect to cim server
|
||||
my $ret = run_cim ($request, $callback, \%args);
|
||||
# 0 - success; 1 - cim error; 10 - ip is not pingable; 11 - this ip is a standby fsp
|
||||
unless ($ret == 10 || $ret == 11) {
|
||||
last;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
=head3 query_pum
|
||||
|
||||
DESCRIPTION:
|
||||
Query the attribute for instance of FipS_PUMService class
|
||||
|
||||
ARGUMENTS:
|
||||
$http_params - refer to the HTTP_PARAMS in xCAT::CIMUtils.pm
|
||||
|
||||
RETURN
|
||||
$ret - return code and messages
|
||||
$pum - a hash includes all the attributes
|
||||
|
||||
=cut
|
||||
|
||||
sub query_pum
|
||||
{
|
||||
my $http_params = shift;
|
||||
|
||||
my %cimargs = ( classname => 'FipS_PUMService' );
|
||||
my ($ret, $value) = xCAT::CIMUtils->enum_instance($http_params, \%cimargs);
|
||||
if ($ret->{rc}) {
|
||||
return ($ret);
|
||||
}
|
||||
|
||||
my $pum;
|
||||
foreach my $instance (@$value) {
|
||||
foreach my $pname (keys %{$instance->{property}}) {
|
||||
$pum->{$pname} = $instance->{property}->{$pname}->{value};
|
||||
}
|
||||
}
|
||||
|
||||
return ($ret, $pum);
|
||||
}
|
||||
|
||||
=head3 run_cim
|
||||
|
||||
DESCRIPTION:
|
||||
Handle the Query and Setting of Energy via CIM
|
||||
|
||||
ARGUMENTS:
|
||||
$request
|
||||
$callback
|
||||
$http_params - refer to the HTTP_PARAMS in xCAT::CIMUtils.pm
|
||||
|
||||
RETURN
|
||||
First element: rc: 0 -success; 1 - cim error; 10 - ip is not pingable; 11 - this ip is a standby fsp
|
||||
|
||||
=cut
|
||||
sub run_cim
|
||||
{
|
||||
my $request = shift;
|
||||
my $callback = shift;
|
||||
|
||||
my $http_params = shift;
|
||||
my $node = $http_params->{node};
|
||||
|
||||
my @output;
|
||||
my $verbose;
|
||||
my $query_list;
|
||||
my $set_pair;
|
||||
|
||||
if (defined($request->{verbose})) {
|
||||
$verbose = $request->{verbose};
|
||||
}
|
||||
if (defined($request->{query_list})) {
|
||||
$query_list = $request->{query_list};
|
||||
}
|
||||
if (defined($request->{set_pair})) {
|
||||
$set_pair = $request->{set_pair};
|
||||
}
|
||||
|
||||
# Try to connect CIM Server to Enumerate CEC object;
|
||||
# If cannot access this ip, return 10 for caller to connect to the next ip
|
||||
my %cimargs = (
|
||||
classname => 'fips_cec',
|
||||
);
|
||||
$http_params->{timeout} = 5;
|
||||
my ($ret, $value) = xCAT::CIMUtils->enum_instance($http_params, \%cimargs);
|
||||
if ($ret->{rc}) {
|
||||
if ($ret->{msg} =~ /Couldn't connect to server/) {
|
||||
xCAT::MsgUtils->message("E", data => ["$node: Couldn not connect to server [$http_params->{ip}]."], $callback);
|
||||
return 10;
|
||||
} else {
|
||||
xCAT::MsgUtils->message("E", {data => ["$node: $ret->{msg}"]}, $callback);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
# start to handle the query and setting
|
||||
my $query_pum_value;
|
||||
# Pre-query some specific objects
|
||||
my $query_pum_capabilities_flag; # set to query the instance for [FipS_PUMServiceCapabilities]
|
||||
my $query_pum_flag; # set to query the instance for [FipS_PUMService]
|
||||
foreach my $attr (split(',', $query_list)) {
|
||||
if ($attr =~ /^(savingstatus|dsavingstatus|fsavingstatus)$/) {
|
||||
$query_pum_flag = 1;
|
||||
}
|
||||
if ($attr =~ /^(ffoMin|ffoVmin|ffoTurbo|ffoNorm|ffovalue)$/) {
|
||||
$query_pum_flag = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ($query_pum_flag) {
|
||||
($ret, $query_pum_value) = query_pum($http_params);
|
||||
if ($ret->{rc}) {
|
||||
xCAT::MsgUtils->message("E", {data => ["$node: $ret->{msg}"]}, $callback);
|
||||
return ($ret->{rc});
|
||||
}
|
||||
}
|
||||
|
||||
foreach my $attr (split(',', $query_list)) {
|
||||
if ($attr =~ /^(savingstatus|dsavingstatus|fsavingstatus)$/) {
|
||||
if ($query_pum_flag) {
|
||||
if (defined ($query_pum_value->{PowerUtilizationMode})) {
|
||||
# 2 = None; 3 = Dynamic; 4 = Static; 32768 = Dynamic Favor Performance; 32769 = FFO
|
||||
if ($query_pum_value->{PowerUtilizationMode} eq "2") {
|
||||
push @output, "$node: $attr: off";
|
||||
} elsif ($query_pum_value->{PowerUtilizationMode} eq "3") {
|
||||
if ($attr eq "dsavingstatus") {
|
||||
push @output, "$node: $attr: on-norm";
|
||||
} else {
|
||||
push @output, "$node: $attr: off";
|
||||
}
|
||||
} elsif ($query_pum_value->{PowerUtilizationMode} eq "4") {
|
||||
if ($attr eq "savingstatus") {
|
||||
push @output, "$node: $attr: on";
|
||||
} else {
|
||||
push @output, "$node: $attr: off";
|
||||
}
|
||||
} elsif ($query_pum_value->{PowerUtilizationMode} eq "32768") {
|
||||
if ($attr eq "dsavingstatus") {
|
||||
push @output, "$node: $attr: on-maxp";
|
||||
} else {
|
||||
push @output, "$node: $attr: off";
|
||||
}
|
||||
} elsif ($query_pum_value->{PowerUtilizationMode} eq "32769") {
|
||||
if ($attr eq "fsavingstatus") {
|
||||
push @output, "$node: $attr: on";
|
||||
} else {
|
||||
push @output, "$node: $attr: off";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
push @output, "$node: $attr: na";
|
||||
}
|
||||
} else {
|
||||
push @output, "$node: $attr: na";
|
||||
}
|
||||
}
|
||||
|
||||
if ($attr =~ /^(ffoMin|ffoVmin|ffoTurbo|ffoNorm|ffovalue)$/) {
|
||||
if ($query_pum_flag) {
|
||||
if (defined ($query_pum_value->{FixedFrequencyPoints}) && defined ($query_pum_value->{FixedFrequencyPointValues})) {
|
||||
my @ffo_point = split (',', $query_pum_value->{FixedFrequencyPoints});
|
||||
my @ffo_point_value = split (',', $query_pum_value->{FixedFrequencyPointValues});
|
||||
foreach my $index (0..$#ffo_point) {
|
||||
if ($ffo_point[$index] eq '2' && $attr eq 'ffoNorm') { # Norminal
|
||||
push @output, "$node: $attr: $ffo_point_value[$index]";
|
||||
} elsif ($ffo_point[$index] eq '3' && $attr eq 'ffoTurbo') { # Turbo
|
||||
push @output, "$node: $attr: $ffo_point_value[$index]";
|
||||
} elsif ($ffo_point[$index] eq '4' && $attr eq 'ffoVmin') { # Vmin
|
||||
push @output, "$node: $attr: $ffo_point_value[$index]";
|
||||
} elsif ($ffo_point[$index] eq '5' && $attr eq 'ffoMin') { # Min
|
||||
push @output, "$node: $attr: $ffo_point_value[$index]";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
push @output, "$node: $attr: na";
|
||||
}
|
||||
} else {
|
||||
push @output, "$node: $attr: na";
|
||||
}
|
||||
}
|
||||
|
||||
if ($attr eq 'ffovalue') {
|
||||
if ($query_pum_flag) {
|
||||
if (defined ($query_pum_value->{FixedFrequencyOverrideFreq})) {
|
||||
if ($query_pum_value->{FixedFrequencyOverrideFreq} eq '4294967295') {
|
||||
push @output, "$node: $attr: 0";
|
||||
} else {
|
||||
push @output, "$node: $attr: $query_pum_value->{FixedFrequencyOverrideFreq}";
|
||||
}
|
||||
} else {
|
||||
push @output, "$node: $attr: na";
|
||||
}
|
||||
} else {
|
||||
push @output, "$node: $attr: na";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
# Display the output
|
||||
my $rsp;
|
||||
push @{$rsp->{data}}, @output;
|
||||
xCAT::MsgUtils->message("I", $rsp, $callback);
|
||||
return;
|
||||
|
||||
|
||||
|
||||
|
||||
%cimargs = (
|
||||
classname => 'CIM_PowerUtilizationManagementService',
|
||||
#classname => 'FipS_PowerMetricValue',
|
||||
);
|
||||
|
||||
($ret, $value) = xCAT::CIMUtils->enum_instance($http_params, \%cimargs);
|
||||
if ($ret->{rc}) {
|
||||
xCAT::MsgUtils->message("E", {data => "$node: $ret->{msg}"}, $callback);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($cimargs{classname} eq 'FipS_PowerMetricValue') {
|
||||
my %instance_id;
|
||||
foreach my $instance (@$value) {
|
||||
if (defined ($instance->{property}->{InstanceID})) {
|
||||
my $i_id = $instance->{property}->{InstanceID}->{value};
|
||||
$i_id =~ s/ .*$//;
|
||||
$instance_id{$i_id} = 1;
|
||||
}
|
||||
foreach my $pname (keys %{$instance->{property}}) {
|
||||
xCAT::MsgUtils->message("I", "$pname: $instance->{property}->{$pname}->{value} ($instance->{property}->{$pname}->{type})\n", $callback);
|
||||
}
|
||||
}
|
||||
#foreach (keys %instance_id) {
|
||||
# print "Instance ID for FipS_PowerMetricValue: $_\n";
|
||||
#}
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
@ -81,7 +81,7 @@ sub preprocess_request {
|
||||
my (@fspnodes, @nohandle);
|
||||
xCAT::Utils->filter_nodes($arg1, undef, \@fspnodes, undef, \@nohandle);
|
||||
if (@fspnodes) {
|
||||
$arg1->{noderange} = \@fspnodes;
|
||||
$arg1->{node} = \@fspnodes;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user