mirror of
https://github.com/xcat2/xcat-core.git
synced 2025-05-31 01:56:39 +00:00
* fix issueNode range not specified, see man page for syntax. return with no output when site.master is not set #4299 * Fix issue 4246, record rflash process in log file * dodiscovery: better disksize - ordered by major,minor and no `\n` (#4219) * better disksize: ordered by major,minor and no `\n` * nodediscover:`disksize` sent correctly: no need to `split`,`join` * general sort with explicit key columns, fix search pattern * dodiscovery: Fix bugs * dodiscovery: Fix ShellCheck SC2007,SC2004 * dodiscovery: simpler kcmdline parsing, disksize as IEC binary prefix * Add test case - switch_to_dns_forward_mode * Modify timeout of login by curl command for OpenBMC * Add makegocons command This patch enable goconserver service and manage the node sessions with a new `makegocons` command. Implement: #4215 * Refine the Cumulus Linux Section of the Doc (#4249) * No content in the switches subdirectory in docs, remove * Change the Network topic to Networking * Refine and reformat the Cumulus Linux documentation * Modify the script to build xCAT-genesis-base package (#4292) * Verify hash ID * change log messages * Timeout the ntpd process if ntpd service is not running on ntpserver (#4321) * enhance nodediscovery process: don't write "NOIP" if the node can not be resloved to an IP (#3995) * enhance nodediscovery process, if only 1 mac and have \*NOIP\* append, don't write mac table and don't generate dhcp lease entry * Enhance PR 3995: enhance nodediscovery process: don't write "NOIP" if the node can not be resloved to an IP * modified depending on comments * natural_sort_cmp: recursion to iterative implementation (#4314) * natural_sort_cmp: recursion to iterative implementation * natural_sort_cmp: correct prototype with parameters, as per `man perlfunc` * Task 3339, rspconfig ip/netmask/gateway/vlan support * * Minor enhance on xcatperftest to put all logs into one file * Fix a bug in simulatorctl.sh, and it cause the script cannot be found * modified depending on comments * QA list for makehosts (#4284) * QA list for makehosts * Fix some bus in makegocons * Revise test case - switch_to_dns_forward_mode * Enhancements after the review * Use IO::Socket to check BMC console port * Revise test case - switch_to_dns_forward_mode * modified depending on comments * Add messages to inform the user of the general action started via xCAT for flashing firmware * Fix bug, anything in the functional array is the one that's really active, priority will not be 0 if there is pending firmware * Fix 4338, remove all of in child process * fix issue #4354 :The XCATTEST_CN in xcattest can not detect HCP as config file (#4355) * Fix #4330, close the socket * Add image name to /opt/xcat/xcatinfo on compute node (#4359) * Integrate congo console from goconserver with rcons Enhance the original implement of rcons to support goconserver. `rcons` will help the user choose from one of the console backend service based on the console server status of management node. Implement #4216 * Fix 4363 - discovery broken (#4364) * do not set exit_code to 1 when the clock is not synced before the timeout (#4362) * Fix check for MTM values with spaces * modified depending on comments * rspconfig admin_password for OpenBMC * Fix merging in xdcpmerge.sh (#4328) * Fixes in xdcpmerge.sh Two fixes: 1. The grep pattern when finding duplicate usernames is missing ":" at the end. So, for example user "test" would also match "test2, etc.". Adding the ":" delimiter fixes the issue. 2. Another issue happens when the file to be merged is a superset of the files on the nodes. For example, if a new user is added and entire passwd file (that is otherwise identical) is sent to be merged. In this case, the $filebackup.nodups file, i.e. the original file with duplicates removed, becomes empty and the condition "if [ -s "$filebackup.nodups" ]" does not execute. Then the merged file ends up being original file with the merge file fully appended, clearly not what was intended. This is solved by changing the condition to check for file existence "-a" rather then for size. Additionally, I also turn the logic around so that the duplicates are removed from the merge file and then added to the original file. I think this makes logic a bit cleaner and also ensures that existing entries are not reordered or changed in any way. * Streamlining previous commit Adjustment to previous commit, streamlining and simplifying logic. Once $mergefile.nodups is created, just concatenate it the original file. * Update to xdcpmerge No need to copy $filebackup to $curfile, they are the same. * Modify for debug conveniently * add new cases and delete outdated test cases * Modify genesis build script for centos x86_64 * Add space between at and the time * Add a print out of the firmware levels for the various UT cases * Add unit test cases for rspconfig * rspconfig fix for set hostname * Enhance the testing case for rspconfig setting hostname * modified depending on comments * modified depending on comments * Add %pretrans script in <lua>. Handle directory to symlink change properly. See comment #3 of https://bugs.launchpad.net/rpm/+bug/633636 * Make xCAT-genesis-base confliects with early version of xCAT-genesis-scripts * rspconfig dump to allow admins capture logs * Adding comment * Improve the error message when BMC does not return a dump ID * Improve some messages and add timestamp for downloaded dump file * Improve the message to help Admin figure out where the file is missing * Leave a log file there when xCAT upgrade in case to debug issue while upgrading (#4389) * Listen on 0.0.0.0 instead of the hostname This patch modify the configuration of `makegocons` and `rcons` for goconserver. `cat /etc/goconserver/server.conf` ``` global: host: 0.0.0.0 ssl_key_file: /etc/xcat/cert/server-key.pem ssl_cert_file: /etc/xcat/cert/server-cert.pem ssl_ca_cert_file: /etc/xcat/cert/ca.pem logfile: /var/log/goconserver/server.log api: port: 12429 console: port: 12430 ``` * Support hostname=* for openbmc * Relay action and snmp configuration support for Coral PDU * ddns.pm: specify the "directory" option for DNS slaves too (cf. bug #4392) * Fix issue 4361, modify some sendmsg to message * 1. add "makeconserver -d" to "rmdef -C", 2. add "makeconserver -C|--cleanup" to remove entries for removed nodes * When there is a problem with the login, do not hide the message on debug mode. BMCReady does not make sense if the admin does not know how to find that state * Change function from login_logout_request to login_request, not doing any logout here * Check that RC is 200 to prevent unknown issues, handle the response generically * OpenBMC rspconfig dump timeout fixes * Fix issue 4408, modify error for rspconfig dump * Clear all BMC Dump logs when BMC firmware flash * modified depending on comments * More modifications for pr 4386, to deal with the conflicts * To handle one case which have 2 implementations, which one is for specific platform, on is for all platforms * return when current status is RSPCONFIG_DUMP_DOWNLOAD_REQUEST * fix issue 4417, delete 'clear next_status' * fix issue 4353: rspconfig needs to support multiple IPs on the BMC and ignore ZeroConfigIPs * Wait 15 seconds after OpenBMC interface with vlan tag to be activated * Fix issue #4397: rspconfig <> hostname=xxx show error message when there is multiple network in bmc * Some sentence modify for makeconservercf -C|--cleanup * OpenBMC rspconfig dump better dump file name formatting * Removed the --check and --ipsource option with PR 4258, update the man page * Improve the message on the HTTP response * modified depending on comments * Only handle 404 and 504 in the login request code, defer the rest to deal_with_response() * rflash stream support * 1. configure ip/netmask/gateway only on the NIC whose IP match node BMC attribute, 2. add some information for LinkLocal address * Fix confignetwork bond nic_type detection with multiple bonds * Modified configonie --ntp command (#4436) * Add man page for makegocons This is the guide about how to make goconserver as a replacement for conserver to help slove the issues reported for conserver, like: #4043, #3543. For openbmc, the solution of goconserver is much light-weighted than the conserver which could help save the system resource. In addition, sshpass is not needed for openbmc with goconserver. Implement: #4337 * Add another key for node_info in order not to after the content of $node_info{$node}{bmc} * enhance rflash stream * makedhcp does not work well when all service nodes not running dhcp but disjointdhcps=1 (#4426) (#4440) - if all service nodes not running dhcp, to treat it as disjointdhcps=0 - nodeset will send request to MN by default even if disjointdhcps=1 - Move out of the dhcp service checking from opts pre-check, and do it just before real makedhcp handling. * rspconfig configure bmc vlan will hung because of PR 4383 * OpenBMC rspconfig dump enhancements * Changes due to review comments * Print debug message before login attempt * Add warning when xCAT throttles SSL connections * Display first [openbmc_debug] when entering openbmc.pm * modified error msg * Make sure credential files have a trailing newline (#4442) * modified depending on comments * Fix the typo in the man page of makegocons * Update the print out based on the review comment, should not use since the regular expression is removed * Modify the nodeset disjoint test case accordingly for #4426 * Use short hostname in rcons for goconserver As the certificate of xcat is signed with short hostname, this commit force to use the short hostname in the environment variable for `congo console`. * Fix issue 3497, make sense for reventlog msg * Give summary after flash active when no debugmode * Fix the issue that the IP configuration will fail if bmc attribute is a hostname * enhance genimage for sles12sp2 (#4450) * Add dhcp-client-identifier to lease block (#4429) Machines that use Infiniband for PXE booting need to have the dhcp-client-identifier set in the lease block. Without it, they will not get the lease from the server. * Support multiple bonds on bring-up * modified depending on comments * fix the check for rc to 1 on error cases * modify response for bmcdiscover when error * Ignore syslog error in monitorctrl when setNodeStatusAttributes (#4459) * fix issue https://github.com/xcat2/xcat-core/issues/4411 (#4462) * fix issue Compute nodes fail to get provisioned #4411: covert imgsrv and xcatmaster to their ip addresses in case the hostname cannot be resolved inside initrd for diskless * More strict check to tell if it is a chroot env to avoid modify DB (#4463) when genimage for SN image (#4365) * issues for install license file on accton switches (#4460) * Add test cases for rflash regular usage against openbmc * modify depending on xuwei's comment * add 2 more cases for option d * enhance rflash upload message * Do not display message for clearing dumps when only PNOR * Display hostname even if multiple IP addresses * modified depending on comments * polished message * Modify the default consoleondemand based on the global setting This commit fix the bug that consoleondemand works incorrectly. * modify depending on comments * modified depending on comments * enhance rflash error messages * Modify documenation for servicenode attributes * build rst file from Schema.pm by db2man * change status back to starts * modified depending on comments * rm openbmcevents * Usage and man page update for rspconfig dump * let rflash error message flexible * Add support for the "file -> (noderange) file" syntax in synclist with ServiceNodes (#4445) * Add support for "file - (noderange) file" in synclist when using hierarchical mode. Fixes #4425 This patch ensures that: 1. the synclist is correctly parsed when running on a Service Node 2. all files are synchronized to SNs in hierarchical mode * Better test condition for #4425, addresses issue in https://github.com/xcat2/xcat-core/pull/4445#issuecomment-349472901 * Fix issue 4477, if has node-<mac> will not create node-<mtms> for the same node * fix issue updatenode -f loses directories when copying files to SN #4456 (#4494) * comment from ErTao * Crude attempt at including external configuration files in named.conf * Fixes after the review * Fix issue 4490, record any error when rflash active process * add -d usage and manpage * updatenode -F not work in hierachy env as the user name is FQDN of MN (#4484) * updatenode -F not work in hierachy env (#4455) - add trace when -V is enabled - get the DSH_FROM_USERID from updatenode client * - when 'updatenode -F' need to push SN first, using root as non-root does not have permission write to 'SNsyncfiledir' - move the set DSH_FROM_USERID code out of the loop, and also cover remote client case. * fix issue for command rspconfig hostname=* * enhance rflash * Adjust the server used for kernel/initrd and imgurl for petitboot (#4416) - URL for kernel/initrd, get the value from below value tftpserver -> xcatmaster -> myipfn - URL for image, get the value from below value nfsserver -> tftpserver -> xcatmaster -> myipfn * NODE attribute didn't populate in /opt/xcat/xcatinfo after reboot (#4428) * NODE attribute didn't populate in /opt/xcat/xcatinfo after reboot * Get NODE from mypostscripts * Improve the output message for reventlog, use a global variable to set PolicyFile Path * If debug_msg is not provided, use an empty string * Check for LinkLocal as well as 169.254 IP address * Fix issue 4507, add parameter check for rspconfig admin_passwd * record more information when rflash upload error * Fix the error when using array ref in updatenode with old version perl, it is introduced by PR#4484 (#4518) * Do not restart conserver if goconserver was started If goconserver was enabled, do not start conserver when restart xcatd on service node. * remove the /etc/localtime before copy timezone file * Use CONGO_CLIENT_TYPE to tell goconserver the source of client (#4501) goconserver could send back message based on the client type this commit set CONGO_CLIENT_TYPE to xcat to make the message from goconserver more friendly. * add rflash -d doc * only ignore 169.254.x.x for OpenBMC * Fix issue 4513, print out better error msg for reventlog -s * Modify or add openbmc test cases or bundle * add test cases for updatenode -f/F in hierarchy environment, covers issues #4456,#4455 and PR #4425 (#4500)
706 lines
25 KiB
Perl
706 lines
25 KiB
Perl
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
#TODO: delete entries not being refreshed if no noderange
|
|
package xCAT_plugin::conserver;
|
|
use strict;
|
|
use xCAT::Table;
|
|
use xCAT::Utils;
|
|
use xCAT::TableUtils;
|
|
use Getopt::Long;
|
|
use Sys::Hostname;
|
|
use xCAT::SvrUtils;
|
|
use xCAT::Scope;
|
|
|
|
use strict;
|
|
use Data::Dumper;
|
|
my @cservers = qw(mrv cyclades);
|
|
my %termservers; #list of noted termservers
|
|
my $siteondemand; # The site value for consoleondemand
|
|
|
|
my $usage_string =
|
|
" makeconservercf [-V|--verbose] [-d|--delete] noderange
|
|
makeconservercf [-V|--verbose] [-l|--local] [noderange]
|
|
makeconservercf [-V|--verbose] [-c|--conserver] [noderange]
|
|
makeconservercf [-V|--verbose] noderange [-t|--trust] hosts
|
|
makeconservercf [-h|--help|-v|--version]
|
|
-c|--conserver The conserver gets set up only on the conserver host.
|
|
The default goes down to all the conservers on
|
|
the server nodes and set them up
|
|
-l|--local The conserver gets set up only on the local host.
|
|
The default goes down to all the conservers on
|
|
the server nodes and set them up
|
|
-d|--delete Conserver has the relevant entries for the given noderange removed immediately from configuration
|
|
-C|--cleanup To remove the entries for the nodes that do not exist in xCAT db
|
|
-t|--trust Add additional trusted hosts.
|
|
-h|--help Display this usage statement.
|
|
-V|--verbose Verbose mode.
|
|
-v|--version Display the version number.";
|
|
|
|
my $version_string = xCAT::Utils->Version();
|
|
|
|
sub handled_commands {
|
|
return {
|
|
makeconservercf => "conserver"
|
|
}
|
|
}
|
|
|
|
sub preprocess_request {
|
|
my $request = shift;
|
|
|
|
#if ($request->{_xcatdest}) { return [$request]; } #exit if preprocessed
|
|
if ($request->{_xcatpreprocessed}->[0] == 1) { return [$request]; }
|
|
my $callback = shift;
|
|
my @requests;
|
|
my $noderange = $request->{node}; #Should be arrayref
|
|
|
|
#display usage statement if -h
|
|
my $extrargs = $request->{arg};
|
|
my @exargs = ($request->{arg});
|
|
if (ref($extrargs)) {
|
|
@exargs = @$extrargs;
|
|
}
|
|
@ARGV = @exargs;
|
|
|
|
my $isSN = xCAT::Utils->isServiceNode();
|
|
my @hostinfo = xCAT::NetworkUtils->determinehostname();
|
|
my %iphash = ();
|
|
foreach (@hostinfo) { $iphash{$_} = 1; }
|
|
|
|
$Getopt::Long::ignorecase = 0;
|
|
|
|
#$Getopt::Long::pass_through=1;
|
|
if (!GetOptions(
|
|
'c|conserver' => \$::CONSERVER,
|
|
'l|local' => \$::LOCAL,
|
|
'h|help' => \$::HELP,
|
|
'D|debug' => \$::DEBUG,
|
|
'C|cleanup' => \$::CLEANUP,
|
|
'v|version' => \$::VERSION,
|
|
'V|verbose' => \$::VERBOSE)) {
|
|
$request = {};
|
|
return;
|
|
}
|
|
if ($::HELP) {
|
|
$callback->({ data => $usage_string });
|
|
$request = {};
|
|
return;
|
|
}
|
|
if ($::VERSION) {
|
|
$callback->({ data => $version_string });
|
|
$request = {};
|
|
return;
|
|
}
|
|
if ($::LOCAL) {
|
|
if ($noderange && @$noderange > 0) {
|
|
$callback->({ data => "Invalid option -l or --local when there are nodes specified." });
|
|
$request = {};
|
|
return;
|
|
}
|
|
}
|
|
if ($::CONSERVER && $::LOCAL) {
|
|
$callback->({ data => "Can not specify -l or --local together with -c or --conserver." });
|
|
$request = {};
|
|
return;
|
|
}
|
|
if ($::CLEANUP && ($::CONSERVER or $::LOCAL)) {
|
|
$callback->({ data => "Can not specify -l|--local or -c|--conserver together with -C|--cleanup." });
|
|
$request = {};
|
|
return;
|
|
}
|
|
# The cleanup shall run on both MN and all SNs
|
|
if ($::CLEANUP) {
|
|
if ($noderange && @$noderange > 0) {
|
|
$callback->({ data => "Can not specify noderange together with -C|--cleanup." });
|
|
$request = {};
|
|
return;
|
|
}
|
|
my @sns = xCAT::ServiceNodeUtils->getSNList();
|
|
unless ( @sns > 0 ) {
|
|
return xCAT::Scope->get_parallel_scope($request);
|
|
}
|
|
return xCAT::Scope->get_broadcast_scope_with_parallel($request, \@sns);
|
|
}
|
|
|
|
# get site master
|
|
my $master = xCAT::TableUtils->get_site_Master();
|
|
if (!$master) { $master = hostname(); }
|
|
|
|
# get conserver for each node
|
|
my %cons_hash = ();
|
|
my $hmtab = xCAT::Table->new('nodehm');
|
|
my @items;
|
|
my $allnodes = 1;
|
|
if ($noderange && @$noderange > 0) {
|
|
$allnodes = 0;
|
|
my $hmcache = $hmtab->getNodesAttribs($noderange, [ 'node', 'serialport', 'cons', 'conserver' ]);
|
|
foreach my $node (@$noderange) {
|
|
my $ent = $hmcache->{$node}->[0]; #$hmtab->getNodeAttribs($node,['node', 'serialport','cons', 'conserver']);
|
|
push @items, $ent;
|
|
}
|
|
} else {
|
|
$allnodes = 1;
|
|
@items = $hmtab->getAllNodeAttribs([ 'node', 'serialport', 'cons', 'conserver' ]);
|
|
}
|
|
|
|
my @nodes = ();
|
|
foreach (@items) {
|
|
if (((!defined($_->{cons})) || ($_->{cons} eq "")) and !defined($_->{serialport})) { next; } #skip if 'cons' is not defined for this node, unless serialport suggests otherwise
|
|
if (defined($_->{conserver})) { push @{ $cons_hash{ $_->{conserver} }{nodes} }, $_->{node}; }
|
|
else { push @{ $cons_hash{$master}{nodes} }, $_->{node}; }
|
|
push @nodes, $_->{node};
|
|
}
|
|
|
|
#send all nodes to the MN
|
|
if (!$isSN && !$::CONSERVER) { #If -c flag is set, do not add the all nodes to the management node
|
|
if ($::VERBOSE) {
|
|
my $rsp;
|
|
$rsp->{data}->[0] = "Setting the nodes into /etc/conserver.cf on the management node";
|
|
xCAT::MsgUtils->message("I", $rsp, $callback);
|
|
}
|
|
my $reqcopy = {%$request};
|
|
$reqcopy->{'_xcatdest'} = $master;
|
|
$reqcopy->{_xcatpreprocessed}->[0] = 1;
|
|
$reqcopy->{'_allnodes'} = $allnodes; # the original command comes with nodes or not
|
|
if ($allnodes == 1) { @nodes = (); }
|
|
$reqcopy->{node} = \@nodes;
|
|
push @requests, $reqcopy;
|
|
if ($::LOCAL) { return \@requests; }
|
|
}
|
|
|
|
# send to conserver hosts
|
|
foreach my $cons (keys %cons_hash) {
|
|
|
|
#print "cons=$cons\n";
|
|
my $doit = 0;
|
|
if ($isSN) {
|
|
if (exists($iphash{$cons})) { $doit = 1; }
|
|
} else {
|
|
if (!exists($iphash{$cons}) || $::CONSERVER) { $doit = 1; }
|
|
}
|
|
|
|
if ($doit) {
|
|
my $reqcopy = {%$request};
|
|
$reqcopy->{'_xcatdest'} = $cons;
|
|
$reqcopy->{_xcatpreprocessed}->[0] = 1;
|
|
$reqcopy->{'_allnodes'} = [$allnodes]; # the original command comes with nodes or not
|
|
$reqcopy->{node} = $cons_hash{$cons}{nodes};
|
|
my $no = $reqcopy->{node};
|
|
|
|
#print "node=@$no\n";
|
|
push @requests, $reqcopy;
|
|
} #end if
|
|
} #end foreach
|
|
|
|
if ($::DEBUG) {
|
|
my $rsp;
|
|
$rsp->{data}->[0] = "In preprocess_request, request is " . Dumper(@requests);
|
|
xCAT::MsgUtils->message("I", $rsp, $callback);
|
|
}
|
|
return \@requests;
|
|
}
|
|
|
|
sub process_request {
|
|
my $req = shift;
|
|
my $cb = shift;
|
|
if ($req->{command}->[0] eq "makeconservercf") {
|
|
if (-x "/usr/bin/goconserver") {
|
|
my $cmd = "ps axf | grep -v grep | grep \/usr\/bin\/goconserver";
|
|
xCAT::Utils->runcmd($cmd, 0);
|
|
if ($::RUNCMD_RC == 0) {
|
|
my $rsp->{data}->[0] = "goconserver is started, please stop it at first.";
|
|
xCAT::MsgUtils->message("E", $rsp, $cb);
|
|
return;
|
|
}
|
|
}
|
|
makeconservercf($req, $cb);
|
|
}
|
|
}
|
|
|
|
# Add the initial/global entries to the beginning of the file
|
|
sub docfheaders {
|
|
|
|
# Put in standard headers common to all conserver.cf files
|
|
my $content = shift;
|
|
my $cb = shift;
|
|
my @newheaders = ();
|
|
my $numlines = @$content;
|
|
my $idx = 0;
|
|
my $skip = 0;
|
|
my @meat = grep(!/^#/, @$content);
|
|
unless (grep(/^config \* \{/, @meat)) {
|
|
|
|
# do not add the ssl configurations
|
|
# if conserver is not compiled with ssl support
|
|
my $cmd = "console -h 2>&1";
|
|
my $output = xCAT::Utils->runcmd($cmd, -1);
|
|
if ($output !~ "encryption not compiled")
|
|
{
|
|
push @newheaders, "config * {\n";
|
|
push @newheaders, " sslrequired yes;\n";
|
|
my $version = xCAT::Utils::get_conserver_version();
|
|
if (!$version) {
|
|
xCAT::SvrUtils::sendmsg([ 1, "Failed to get conserver version" ], $cb);
|
|
return;
|
|
}
|
|
if (xCAT::Utils::calc_conserver_version($version) < xCAT::Utils::calc_conserver_version("8.1.19")) {
|
|
push @newheaders, " sslauthority /etc/xcat/cert/ca.pem;\n";
|
|
} else {
|
|
push @newheaders, " sslcacertificatefile /etc/xcat/cert/ca.pem;\n";
|
|
}
|
|
push @newheaders, " sslcredentials /etc/xcat/cert/server-cred.pem;\n";
|
|
push @newheaders, "}\n";
|
|
}
|
|
}
|
|
unless (grep(/^default cyclades/, @meat)) {
|
|
push @newheaders, "default cyclades { type host; portbase 7000; portinc 1; }\n"
|
|
}
|
|
unless (grep(/^default mrv/, @meat)) {
|
|
push @newheaders, "default mrv { type host; portbase 2000; portinc 100; }\n"
|
|
}
|
|
|
|
#Go through and delete that which would match access and default
|
|
while ($idx < @$content) {
|
|
if (($content->[$idx] =~ /^access \*/)
|
|
|| ($content->[$idx] =~ /^default \*/)) {
|
|
$skip = 1;
|
|
}
|
|
if ($skip == 1) {
|
|
splice(@$content, $idx, 1);
|
|
} else {
|
|
$idx++;
|
|
}
|
|
if ($skip and $content->[$idx] =~ /\}/) {
|
|
splice(@$content, $idx, 1);
|
|
$skip = 0;
|
|
}
|
|
}
|
|
|
|
#push @$content,"#xCAT BEGIN ACCESS\n";
|
|
push @newheaders, "access * {\n";
|
|
push @newheaders, " trusted 127.0.0.1;\n";
|
|
my $master = xCAT::TableUtils->get_site_Master();
|
|
push @newheaders, " trusted $master;\n";
|
|
|
|
# trust all the ip addresses configured on this node
|
|
my @allips = xCAT::NetworkUtils->gethost_ips();
|
|
my @ips = ();
|
|
|
|
#remove $xcatmaster and duplicate entries
|
|
foreach my $ip (@allips) {
|
|
if (($ip eq "127.0.0.1") || ($ip eq $master)) {
|
|
next;
|
|
}
|
|
if (!grep(/^$ip$/, @ips)) {
|
|
push @ips, $ip;
|
|
}
|
|
}
|
|
if ($::TRUSTED_HOST)
|
|
{
|
|
my @trusted_host = (split /,/, $::TRUSTED_HOST);
|
|
foreach my $tip (@trusted_host)
|
|
{
|
|
if (!grep(/^$tip$/, @ips)) {
|
|
push @ips, $tip;
|
|
}
|
|
}
|
|
}
|
|
if (scalar(@ips) > 0) {
|
|
my $ipstr = join(',', @ips);
|
|
push @newheaders, " trusted $ipstr;\n";
|
|
}
|
|
|
|
push @newheaders, "}\n";
|
|
|
|
#push @$content,"#xCAT END ACCESS\n";
|
|
|
|
push @newheaders, "default * {\n";
|
|
push @newheaders, " logfile /var/log/consoles/&;\n";
|
|
push @newheaders, " timestamp 1lab;\n";
|
|
push @newheaders, " rw *;\n";
|
|
push @newheaders, " master localhost;\n";
|
|
|
|
#-- if option "conserverondemand" in site table is set to yes
|
|
#-- then start all consoles on demand
|
|
#-- this helps eliminate many ssh connections to blade AMM
|
|
#-- which seems to kill AMMs occasionally
|
|
my @entries = xCAT::TableUtils->get_site_attribute("consoleondemand");
|
|
my $site_entry = $entries[0];
|
|
$siteondemand = 0;
|
|
if (defined($site_entry)) {
|
|
if (lc($site_entry) eq "yes") {
|
|
push @newheaders, " options ondemand;\n";
|
|
$siteondemand = 1;
|
|
}
|
|
elsif (lc($site_entry) ne "no") {
|
|
# consoleondemand attribute is set, but it is not "yes" or "no"
|
|
xCAT::SvrUtils::sendmsg([ 1, "Unexpected value $site_entry for consoleondemand attribute in site table" ], $cb);
|
|
}
|
|
}
|
|
push @newheaders, "}\n";
|
|
unshift @$content, @newheaders;
|
|
}
|
|
|
|
# Read the file, get db info, update the file contents, and then write the file
|
|
sub makeconservercf {
|
|
my $req = shift;
|
|
%termservers = (); #clear hash of existing entries
|
|
my $cb = shift;
|
|
my $extrargs = $req->{arg};
|
|
my @exargs = ($req->{arg});
|
|
if (ref($extrargs)) {
|
|
@exargs = @$extrargs;
|
|
}
|
|
@ARGV = @exargs;
|
|
$Getopt::Long::ignorecase = 0;
|
|
|
|
#$Getopt::Long::pass_through=1;
|
|
my $delmode;
|
|
GetOptions('d|delete' => \$delmode,
|
|
't|trust=s' => \$::TRUSTED_HOST,
|
|
'C|cleanup' => \$::CLEANUP,
|
|
);
|
|
my $nodes = $req->{node};
|
|
my $svboot = 0;
|
|
if (exists($req->{svboot})) { $svboot = 1; }
|
|
my $cfile;
|
|
my @filecontent;
|
|
open $cfile, '/etc/conserver.cf';
|
|
while (<$cfile>) {
|
|
push @filecontent, $_;
|
|
}
|
|
close $cfile;
|
|
docfheaders(\@filecontent,$cb);
|
|
|
|
my $isSN = xCAT::Utils->isServiceNode();
|
|
my @hostinfo = xCAT::NetworkUtils->determinehostname();
|
|
my %iphash = ();
|
|
foreach (@hostinfo) { $iphash{$_} = 1; }
|
|
|
|
#print "process_request nodes=@$nodes\n";
|
|
|
|
# Get db info for the nodes related to console
|
|
my $hmtab = xCAT::Table->new('nodehm');
|
|
my @cfgents1; # = $hmtab->getAllNodeAttribs(['cons','serialport','mgt','conserver','termserver','termport']);
|
|
if (($nodes and @$nodes > 0) or $req->{noderange}->[0]) {
|
|
@cfgents1 = $hmtab->getNodesAttribs($nodes, [ 'node', 'cons', 'serialport', 'mgt', 'conserver', 'termserver', 'termport', 'consoleondemand' ]);
|
|
|
|
# Adjust the data structure to make the result consistent with the getAllNodeAttribs() call we make if a noderange was not specified
|
|
my @tmpcfgents1;
|
|
foreach my $ent (@cfgents1)
|
|
{
|
|
foreach my $nodeent (keys %$ent)
|
|
{
|
|
push @tmpcfgents1, $ent->{$nodeent}->[0];
|
|
}
|
|
}
|
|
@cfgents1 = @tmpcfgents1
|
|
|
|
} else {
|
|
@cfgents1 = $hmtab->getAllNodeAttribs([ 'cons', 'serialport', 'mgt', 'conserver', 'termserver', 'termport', 'consoleondemand' ]);
|
|
}
|
|
|
|
|
|
#cfgents1 should now have all the nodes, so we can fill in the cfgents array and cfgenthash one at a time.
|
|
# skip the nodes that do not have 'cons' defined, unless a serialport setting suggests otherwise
|
|
my @cfgents = ();
|
|
my %cfgenthash;
|
|
foreach (@cfgents1) {
|
|
if ($_->{cons} or defined($_->{'serialport'})) {
|
|
unless ($_->{cons}) { $_->{cons} = $_->{mgt}; } #populate with fallback
|
|
push @cfgents, $_;
|
|
$cfgenthash{ $_->{node} } = $_; # also put the ref to the entry in a hash for quick look up
|
|
}
|
|
}
|
|
|
|
if ($::DEBUG) {
|
|
my $rsp;
|
|
$rsp->{data}->[0] = "In makeconservercf, cfgents is " . Dumper(@cfgents);
|
|
xCAT::MsgUtils->message("I", $rsp, $cb);
|
|
}
|
|
|
|
# if nodes defined, it is either on the service node or makeconserver was called with noderange on mn
|
|
if (($nodes and @$nodes > 0) or $req->{noderange}->[0]) {
|
|
|
|
# strip all xCAT configured nodes from config if the original command was for all nodes
|
|
if (($req->{_allnodes}) && ($req->{_allnodes}->[0] == 1)) { zapcfg(\@filecontent); }
|
|
|
|
# call donodeent to add all node entries into the file. It will return the 1st node in error.
|
|
my $node;
|
|
if ($node = donodeent(\%cfgenthash, \@filecontent, $delmode)) {
|
|
|
|
#$cb->({node=>[{name=>$node,error=>"Bad configuration, check attributes under the nodehm category",errorcode=>1}]});
|
|
xCAT::SvrUtils::sendmsg([ 1, "Bad configuration, check attributes under the nodehm category" ], $cb, $node);
|
|
}
|
|
} elsif ($::CLEANUP) {
|
|
my $nodelstab = xCAT::Table->new('nodelist');
|
|
my @allnodeset = $nodelstab->getAllAttribs('node');
|
|
my %allnodehash = map { $_->{node} => 1 } @allnodeset;
|
|
my $rmnodes = delete_undefined_nodes_entry(\@filecontent, \%allnodehash);
|
|
my $rsp;
|
|
if (!defined($rmnodes)) {
|
|
$rsp->{data}->[0] = "Nothing removed";
|
|
} else{
|
|
$rsp->{data}->[0] = "Remove console entry for the nodes:".join(',', @$rmnodes);
|
|
}
|
|
xCAT::MsgUtils->message("I", $rsp, $cb);
|
|
} else { #no nodes specified, do em all up
|
|
zapcfg(\@filecontent); # strip all xCAT configured nodes from config
|
|
|
|
# get nodetype so we can filter out node types without console support
|
|
my $typetab = xCAT::Table->new('nodetype');
|
|
my %type;
|
|
|
|
if (defined($typetab)) {
|
|
my @ents = $typetab->getAllNodeAttribs([qw(node nodetype)]);
|
|
foreach (@ents) {
|
|
$type{ $_->{node} } = $_->{nodetype};
|
|
}
|
|
}
|
|
|
|
# remove nodes that arent for this SN or type of node doesnt have console
|
|
foreach (@cfgents) {
|
|
my $keepdoing = 0;
|
|
if ($isSN && $_->{conserver} && exists($iphash{ $_->{conserver} })) {
|
|
$keepdoing = 1; #only hanlde the nodes that use this SN as the conserver
|
|
}
|
|
if (!$isSN) { $keepdoing = 1; } #handle all for MN
|
|
if ($keepdoing) {
|
|
if ($_->{termserver} and not $termservers{ $_->{termserver} }) {
|
|
|
|
# add a terminal server entry to file
|
|
dotsent($_, \@filecontent);
|
|
$termservers{ $_->{termserver} } = 1; # dont add this one again
|
|
}
|
|
if ($type{ $_->{node} } =~ /fsp|bpa|hmc|ivm/) {
|
|
$keepdoing = 0; # these types dont have consoles
|
|
}
|
|
}
|
|
if (!$keepdoing) { delete $cfgenthash{ $_->{node} }; } # remove this node from the hash so we dont process it later
|
|
}
|
|
|
|
# Now add into the file all the node entries that we kept
|
|
my $node;
|
|
if ($node = donodeent(\%cfgenthash, \@filecontent, $delmode)) {
|
|
|
|
# donodeent will return the 1st node in error
|
|
#$cb->({node=>[{name=>$node,error=>"Bad configuration, check attributes under the nodehm category",errorcode=>1}]});
|
|
xCAT::SvrUtils::sendmsg([ 1, "Bad configuration, check attributes under the nodehm category" ], $cb, $node);
|
|
}
|
|
}
|
|
|
|
# Write out the file contents
|
|
open $cfile, '>', '/etc/conserver.cf';
|
|
if ($::VERBOSE) {
|
|
my $rsp;
|
|
$rsp->{data}->[0] = "Setting the following lines into /etc/conserver.cf:\n @filecontent";
|
|
xCAT::MsgUtils->message("I", $rsp, $cb);
|
|
}
|
|
foreach (@filecontent) {
|
|
print $cfile $_;
|
|
}
|
|
close $cfile;
|
|
|
|
# restart conserver
|
|
if (!$svboot) {
|
|
|
|
#restart conserver daemon
|
|
my $cmd;
|
|
if (xCAT::Utils->isAIX()) {
|
|
$cmd = "stopsrc -s conserver";
|
|
xCAT::Utils->runcmd($cmd, 0);
|
|
$cmd = "startsrc -s conserver";
|
|
xCAT::Utils->runcmd($cmd, 0);
|
|
} else {
|
|
$cmd = "/etc/init.d/conserver stop";
|
|
xCAT::Utils->runcmd($cmd, 0);
|
|
$cmd = "/etc/init.d/conserver start";
|
|
xCAT::Utils->runcmd($cmd, 0);
|
|
}
|
|
}
|
|
}
|
|
|
|
# Put a terminal server entry in the file - not used much any more
|
|
sub dotsent {
|
|
my $cfgent = shift;
|
|
my $tserv = $cfgent->{termserver};
|
|
my $content = shift;
|
|
my $idx = 0;
|
|
my $toidx = -1;
|
|
my $skip = 0;
|
|
my $skipnext = 0;
|
|
|
|
while ($idx < $#$content) { # Go through and delete that which would match my entry
|
|
if ($content->[$idx] =~ /^#xCAT BEGIN $tserv TS/) {
|
|
$toidx = $idx; #TODO put it back right where I found it
|
|
$skip = 1;
|
|
$skipnext = 1;
|
|
} elsif ($content->[$idx] =~ /^#xCAT END $tserv TS/) {
|
|
$skipnext = 0;
|
|
}
|
|
if ($skip) {
|
|
splice(@$content, $idx, 1);
|
|
} else {
|
|
$idx++;
|
|
}
|
|
$skip = $skipnext;
|
|
}
|
|
push @$content, "#xCAT BEGIN $tserv TS\n";
|
|
push @$content, "default $tserv {\n";
|
|
push @$content, " include " . $cfgent->{cons} . ";\n";
|
|
push @$content, " host $tserv;\n";
|
|
push @$content, "}\n";
|
|
push @$content, "#xCAT END $tserv TS\n";
|
|
|
|
}
|
|
|
|
# Add entries in the file for each node. This function used to do 1 node at a time, but was changed to do
|
|
# all nodes at once for performance reasons. If there is a problem with a nodes config, this
|
|
# function will return that node name as the one in error.
|
|
sub donodeent {
|
|
my $cfgenthash = shift;
|
|
my $content = shift;
|
|
my $delmode = shift;
|
|
my $idx = 0;
|
|
my $toidx = -1;
|
|
my $skip = 0;
|
|
my $skipnext = 0;
|
|
|
|
# Delete all the previous stanzas of the nodes specified
|
|
my $isSN = xCAT::Utils->isServiceNode();
|
|
my $curnode;
|
|
|
|
# Loop till find the start of a node stanza and remove lines till get to the end of the stanza
|
|
while ($idx <= $#$content) { # Go through and delete that which would match my entry
|
|
my ($begorend, $node) = $content->[$idx] =~ /^#xCAT (\S+) (\S+) CONS/;
|
|
if ($begorend eq 'BEGIN') {
|
|
if ($cfgenthash->{$node}) {
|
|
$toidx = $idx; #TODO put it back right where I found it
|
|
$skip = 1; # delete this line
|
|
$skipnext = 1; # put us in skip mode until we find the end of the stanza
|
|
$curnode = $node;
|
|
}
|
|
} elsif ($begorend eq 'END' && $node eq $curnode) {
|
|
$skipnext = 0;
|
|
}
|
|
if ($skip) {
|
|
splice(@$content, $idx, 1);
|
|
} else {
|
|
$idx++;
|
|
}
|
|
$skip = $skipnext;
|
|
}
|
|
if ($delmode) {
|
|
|
|
# dont need to add node entries, so we are done
|
|
return;
|
|
}
|
|
|
|
# Go thru all nodes specified to add them to the file
|
|
foreach my $node (sort keys %$cfgenthash) {
|
|
my $cfgent = $cfgenthash->{$node};
|
|
my $cmeth = $cfgent->{cons};
|
|
if (not $cmeth or (grep(/^$cmeth$/, @cservers) and (not $cfgent->{termserver} or not $cfgent->{termport}))) {
|
|
|
|
# either there is no console method (shouldnt happen) or not one of the supported terminal servers
|
|
return $node;
|
|
}
|
|
push @$content, "#xCAT BEGIN $node CONS\n";
|
|
push @$content, "console $node {\n";
|
|
if (grep(/^$cmeth$/, @cservers)) {
|
|
push @$content, " include " . $cfgent->{termserver} . ";\n";
|
|
push @$content, " port " . $cfgent->{termport} . ";\n";
|
|
if ((!$isSN) && ($cfgent->{conserver}) && xCAT::NetworkUtils->thishostisnot($cfgent->{conserver})) { # let the master handle it
|
|
push @$content, " master " . $cfgent->{conserver} . ";\n";
|
|
}
|
|
} else { #a script method...
|
|
push @$content, " type exec;\n";
|
|
if ((!$isSN) && ($cfgent->{conserver}) && xCAT::NetworkUtils->thishostisnot($cfgent->{conserver})) { # let the master handle it
|
|
push @$content, " master " . $cfgent->{conserver} . ";\n";
|
|
} else { # handle it here
|
|
my $locerror = $isSN ? "PERL_BADLANG=0 " : ''; # on service nodes, often LC_ALL is not set and perl complains
|
|
|
|
# add XCATSSLVER environment variable when it's set on sles11.x mn
|
|
# for cons script to communicate with xcatd through tls
|
|
my $env;
|
|
if (defined($ENV{'XCATSSLVER'})) {
|
|
$env = "XCATSSLVER=$ENV{'XCATSSLVER'} ";
|
|
}
|
|
push @$content, " exec $locerror$env" . $::XCATROOT . "/share/xcat/cons/" . $cmeth . " " . $node . ";\n"
|
|
}
|
|
}
|
|
if (defined($cfgent->{consoleondemand})) {
|
|
# consoleondemand attribute for node can be "1", "yes", "0" and "no"
|
|
if ((($cfgent->{consoleondemand} eq "1") || lc($cfgent->{consoleondemand}) eq "yes") && !$siteondemand) {
|
|
push @$content, " options ondemand;\n";
|
|
}
|
|
elsif ((($cfgent->{consoleondemand} eq "0") || lc($cfgent->{consoleondemand}) eq "no") && $siteondemand) {
|
|
push @$content, " options !ondemand;\n";
|
|
}
|
|
}
|
|
push @$content, "}\n";
|
|
push @$content, "#xCAT END $node CONS\n";
|
|
}
|
|
return 0;
|
|
}
|
|
# Remove cons entries for the undefined nodes
|
|
sub delete_undefined_nodes_entry {
|
|
my $content = shift;
|
|
my $allnodeshash = shift;
|
|
my $idx = 0;
|
|
my $toidx = -1;
|
|
my $skip = 0;
|
|
my $skipnext = 0;
|
|
my @rmnodes = ();
|
|
while ($idx <= $#$content) {
|
|
if ($content->[$idx] =~ /^#xCAT BEGIN (\S+) CONS/) {
|
|
$toidx = $idx;
|
|
my $node = $1;
|
|
unless (exists($allnodeshash->{$node})) {
|
|
$skip = 1;
|
|
$skipnext = 1;
|
|
push @rmnodes, $node;
|
|
print __LINE__."===== push node: $node==\n";
|
|
}
|
|
} elsif ($content->[$idx] =~ /^#xCAT END/) {
|
|
$skipnext = 0;
|
|
}
|
|
if ($skip) {
|
|
splice(@$content, $idx, 1);
|
|
} else {
|
|
$idx++;
|
|
}
|
|
$skip = $skipnext;
|
|
}
|
|
if (scalar(@rmnodes) > 0) {
|
|
return \@rmnodes;
|
|
} else {
|
|
return undef;
|
|
}
|
|
}
|
|
|
|
# Delete any xcat added node entries from the file
|
|
sub zapcfg {
|
|
my $content = shift;
|
|
my $idx = 0;
|
|
my $toidx = -1;
|
|
my $skip = 0;
|
|
my $skipnext = 0;
|
|
while ($idx <= $#$content) { # Go through and delete that which would match my entry
|
|
if ($content->[$idx] =~ /^#xCAT BEGIN/) {
|
|
$toidx = $idx; #TODO put it back right where I found it
|
|
$skip = 1;
|
|
$skipnext = 1;
|
|
} elsif ($content->[$idx] =~ /^#xCAT END/) {
|
|
$skipnext = 0;
|
|
}
|
|
if ($skip) {
|
|
splice(@$content, $idx, 1);
|
|
} else {
|
|
$idx++;
|
|
}
|
|
$skip = $skipnext;
|
|
}
|
|
}
|
|
|
|
|
|
1;
|