mirror of
https://github.com/xcat2/xcat-core.git
synced 2025-06-12 17:30:19 +00:00
Control openbmc Perl/Python commands with site attribute (#4879)
* Control openbmc Perl/Python commands with site attribute * update PR: control openbmc perl/python commands, using site attribute, env variable as well
This commit is contained in:
@ -4968,5 +4968,4 @@ sub console_sleep {
|
||||
sleep($time);
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
@ -22,6 +22,7 @@ use File::Path;
|
||||
use Fcntl ":flock";
|
||||
use IO::Socket::UNIX qw( SOCK_STREAM );
|
||||
use xCAT_monitoring::monitorctrl;
|
||||
use xCAT::TableUtils;
|
||||
|
||||
my $LOCK_DIR = "/var/lock/xcat/";
|
||||
my $LOCK_PATH = "/var/lock/xcat/agent.lock";
|
||||
@ -201,8 +202,8 @@ sub wait_agent {
|
||||
sub is_openbmc_python {
|
||||
my $environment = shift;
|
||||
$environment = shift if (($environment) && ($environment =~ /OPENBMC/));
|
||||
# If XCAT_OPENBMC_PYTHON is YES,
|
||||
# will return "ALL" and caller will run openbmc2.pm.
|
||||
# If XCAT_OPENBMC_PYTHON is YES,
|
||||
# will return "ALL" and caller will run openbmc2.pm.
|
||||
# If XCAT_OPENBMC_PYTHON is not set or is set to NO, return "NO" and caller
|
||||
# will run openbmc.pm
|
||||
# If XCAT_OPENBMC_PYTHON is a list of commands, return that list and caller
|
||||
@ -215,7 +216,7 @@ sub is_openbmc_python {
|
||||
} else {
|
||||
$::OPENBMC_PYTHON = $environment->{XCAT_OPENBMC_PYTHON};
|
||||
}
|
||||
if (defined($::OPENBMC_PYTHON)) {
|
||||
if (defined($::OPENBMC_PYTHON)) {
|
||||
if ($::OPENBMC_PYTHON eq "YES") {
|
||||
return "ALL";
|
||||
}
|
||||
@ -230,4 +231,53 @@ sub is_openbmc_python {
|
||||
return "NO";
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------------------------
|
||||
|
||||
=head3 is_support_in_perl
|
||||
check if specified command is included in site attribute openbmcperl
|
||||
The policy is:
|
||||
Get value from `openbmcperl`, `XCAT_OPENBMC_DEVEL`, agent.py:
|
||||
1. If agent.py not exist: ==>Go Perl
|
||||
2. If `openbmcperl` not set or not include a command:
|
||||
if `XCAT_OPENBMC_DEVEL` set to `NO`: ==> Go Perl
|
||||
else if set to `YES` or not set: ==> Go Python
|
||||
3. If `openbmcperl` set and include a command
|
||||
if `XCAT_OPENBMC_DEVEL` set to `YES`: == >Go Python
|
||||
else ==> Go Perl
|
||||
=cut
|
||||
|
||||
#--------------------------------------------------------------------------------
|
||||
sub is_support_in_perl {
|
||||
my ($class, $command, $env) = @_;
|
||||
if (! -e $PYTHON_AGENT_FILE) {
|
||||
return (1, '');
|
||||
}
|
||||
my @entries = xCAT::TableUtils->get_site_attribute("openbmcperl");
|
||||
my $site_entry = $entries[0];
|
||||
my $support_obmc = undef;
|
||||
if (ref($env) eq 'ARRAY' and ref($env->[0]->{XCAT_OPENBMC_DEVEL}) eq 'ARRAY') {
|
||||
$support_obmc = $env->[0]->{XCAT_OPENBMC_DEVEL}->[0];
|
||||
} elsif (ref($env) eq 'ARRAY') {
|
||||
$support_obmc = $env->[0]->{XCAT_OPENBMC_DEVEL};
|
||||
} else {
|
||||
$support_obmc = $env->{XCAT_OPENBMC_DEVEL};
|
||||
}
|
||||
if ($support_obmc and $support_obmc ne 'YES' and $support_obmc ne 'NO') {
|
||||
return (-1, "Value $support_obmc is invalid for XCAT_OPENBMC_DEVEL, only support 'YES' and 'NO'");
|
||||
}
|
||||
if ($site_entry and $site_entry =~ $command) {
|
||||
if ($support_obmc and $support_obmc eq 'YES') {
|
||||
return (0, '');
|
||||
} else {
|
||||
return (1, '');
|
||||
}
|
||||
} else {
|
||||
if ($support_obmc and $support_obmc eq 'NO') {
|
||||
return (1, '');
|
||||
} else {
|
||||
return (0, '');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -758,21 +758,12 @@ sub preprocess_request {
|
||||
|
||||
$callback = shift;
|
||||
my $command = $request->{command}->[0];
|
||||
my $python_env = xCAT::OPENBMC->is_openbmc_python($request->{environment});
|
||||
# Process command in this module only if PYTHON env is not ALL or command is
|
||||
# listed in the PYTHON env list (without EXCEPT: prefix.
|
||||
# All other cases => return
|
||||
SWITCH: {
|
||||
if ($python_env eq "ALL") {$request = {}; return;}
|
||||
if ($python_env eq "NO") {last SWITCH;}
|
||||
if ($python_env !~ $command) {
|
||||
if ($python_env =~ /^EXCEPT:/) {$request = {}; return;}
|
||||
else {last SWITCH;}
|
||||
}
|
||||
if ($python_env =~ $command) {
|
||||
if ($python_env =~ /^EXCEPT:/) {last SWITCH;}
|
||||
else {$request = {}; return;}
|
||||
}
|
||||
my ($rc, $msg) = xCAT::OPENBMC->is_support_in_perl($command, $request->{environment});
|
||||
if ($rc == 0) { $request = {}; return;}
|
||||
if ($rc < 0) {
|
||||
$request = {};
|
||||
$callback->({ errorcode => [1], data => [$msg] });
|
||||
return;
|
||||
}
|
||||
|
||||
if ($::XCATSITEVALS{xcatdebugmode}) { $xcatdebugmode = $::XCATSITEVALS{xcatdebugmode} }
|
||||
|
@ -13,7 +13,6 @@ use warnings "all";
|
||||
|
||||
use JSON;
|
||||
use Getopt::Long;
|
||||
use xCAT::Utils;
|
||||
use xCAT::Usage;
|
||||
use xCAT::SvrUtils;
|
||||
use xCAT::OPENBMC;
|
||||
@ -63,23 +62,8 @@ sub preprocess_request {
|
||||
$callback = shift;
|
||||
|
||||
my $command = $request->{command}->[0];
|
||||
my $python_env = xCAT::OPENBMC->is_openbmc_python($request->{environment});
|
||||
# Process command in this module only if PYTHON env is not NO or
|
||||
# command is listed in the PYTHON env list (without EXCEPT: prefix).
|
||||
# All other cases => return
|
||||
|
||||
SWITCH: {
|
||||
if ($python_env eq "NO") {$request = {}; return;}
|
||||
if ($python_env eq "ALL") {last SWITCH;}
|
||||
if ($python_env !~ $command) {
|
||||
if ($python_env =~ /^EXCEPT:/) {last SWITCH}
|
||||
else {$request = {}; return;}
|
||||
}
|
||||
if ($python_env =~ $command) {
|
||||
if ($python_env =~ /^EXCEPT:/) {$request = {}; return;}
|
||||
else {last SWITCH;}
|
||||
}
|
||||
}
|
||||
my ($rc, $msg) = xCAT::OPENBMC->is_support_in_perl($command, $request->{environment});
|
||||
if ($rc != 0) { $request = {}; return;}
|
||||
|
||||
my $noderange = $request->{node};
|
||||
my $extrargs = $request->{arg};
|
||||
|
Reference in New Issue
Block a user