2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-05-30 17:46:38 +00:00

Merge pull request #4796 from chenglch/makegocons

List console status with makegocons -q|--query
This commit is contained in:
zet809 2018-02-08 12:48:32 +08:00 committed by GitHub
commit 0e9442d177
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 62 additions and 6 deletions

View File

@ -10,6 +10,7 @@ BEGIN
use lib "$::XCATROOT/lib/perl";
use strict;
use warnings "all";
use File::Copy qw(move);
use HTTP::Request;
use HTTP::Headers;
@ -22,6 +23,7 @@ my $go_api_port = 12429;
my $go_cons_port = 12430;
use constant CONSOLE_LOG_DIR => "/var/log/consoles";
use constant PRINT_FORMAT => "%-32s %-32s %-64s";
unless (-d CONSOLE_LOG_DIR) {
mkpath(CONSOLE_LOG_DIR, 0, 0755);
}
@ -115,6 +117,46 @@ sub create_nodes {
return $ret;
}
sub list_nodes {
my ($api_url, $node_map, $callback) = @_;
my $url = "$api_url/nodes";
my $rsp;
my $response = http_request("GET", $url);
if (!defined($response)) {
$rsp->{data}->[0] = "Failed to send list request.";
xCAT::MsgUtils->message("E", $rsp, $callback);
return 1;
}
if (!$response->{nodes}) {
$rsp->{data}->[0] = "Could not find any node.";
xCAT::MsgUtils->message("I", $rsp, $callback);
return 0;
}
$rsp->{data}->[0] = sprintf("\n".PRINT_FORMAT, "NODE", "SERVER", "STATE");
xCAT::MsgUtils->message("I", $rsp, $::callback);
foreach my $node (sort {$a->{name} cmp $b->{name}} @{$response->{nodes}}) {
if (!$node_map->{$node->{name}}) {
next;
}
$node_map->{$node->{name}}->{vis} = 1;
if (!$node->{host} || !$node->{state}) {
$rsp->{data}->[0] = sprintf(PRINT_FORMAT, $node->{name}, "", "Unable to parse the response message");
xCAT::MsgUtils->message("E", $rsp, $callback);
next;
}
$rsp->{data}->[0] = sprintf(PRINT_FORMAT, $node->{name}, $node->{host}, $node->{state});
xCAT::MsgUtils->message("I", $rsp, $::callback);
}
my %node_hash = %{$node_map};
for my $node (sort keys %node_hash) {
if(!$node_hash{$node}->{vis}) {
$rsp->{data}->[0] = sprintf(PRINT_FORMAT, $node, "", "unregistered");
xCAT::MsgUtils->message("I", $rsp, $callback);
}
}
return 0;
}
#-------------------------------------------------------------------------------
=head3 is_xcat_conf_ready
@ -218,6 +260,8 @@ sub is_conserver_running {
#-------------------------------------------------------------------------------
sub build_conf {
# try to backup the original configuration file, no matter sunccess or not
move('/etc/goconserver/server.conf', '/etc/goconserver/server.conf.bak');
my $config = "#generated by xcat ".xCAT::Utils->Version()."\n".
"global:\n".
" host: 0.0.0.0\n".
@ -231,6 +275,8 @@ sub build_conf {
" datadir: /var/lib/goconserver/ # the data file to save the hosts\n".
" port: $go_cons_port # the port for console\n".
" log_timestamp: true # log the timestamp at the beginning of line\n".
" # time precison for tcp or udp logger, precison for file logger is always second\n".
" time_precision: microsecond # Valid options: second, millisecond, microsecond, nanosecond\n".
" reconnect_interval: 10 # retry interval in second if console could not be connected\n".
" logger: # multiple logger targets could be specified\n".
" file: # file logger, valid fields: name,logdir. Accept array in yaml format\n".

View File

@ -19,8 +19,9 @@ my $isSN;
my $host;
my $bmc_cons_port = "2200";
my $usage_string =" makegocons [-V|--verbose] [-d|--delete] noderange
-h|--help Display this usage statement.
-v|--version Display the version number.";
-h|--help Display this usage statement.
-v|--version Display the version number.
-q|--query [noderange] Display the console connection status.";
my $version_string = xCAT::Utils->Version();
@ -86,13 +87,17 @@ sub preprocess_request {
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;
if ($ent) {
push (@items, $ent);
} else {
my $rsp->{data}->[0] = $node .": ignore, cons attribute or serialport attribute is not specified.";
xCAT::MsgUtils->message("I", $rsp, $::callback);
}
}
} else {
$allnodes = 1;
@items = $hmtab->getAllNodeAttribs([ 'node', 'serialport', 'cons', 'conserver' ]);
}
my @nodes = ();
foreach (@items) {
if (((!defined($_->{cons})) || ($_->{cons} eq "")) and !defined($_->{serialport})) {
@ -314,8 +319,9 @@ sub makegocons {
}
@ARGV = @exargs;
$Getopt::Long::ignorecase = 0;
my $delmode;
my ($delmode, $querymode);
GetOptions('d|delete' => \$delmode,
'q|query' => \$querymode,
);
my $svboot = 0;
@ -329,6 +335,11 @@ sub makegocons {
xCAT::SvrUtils::sendmsg([ 1, "Could not get any console request entry" ], $::callback);
return 1;
}
my $api_url = "https://$host:". xCAT::Goconserver::get_api_port();
if ($querymode) {
return xCAT::Goconserver::list_nodes($api_url, \%cons_map, $::callback)
}
my $ret = start_goconserver();
if ($ret != 0) {
return 1;
@ -351,7 +362,6 @@ sub makegocons {
xCAT::SvrUtils::sendmsg([ 1, "Could not generate the request data" ], $::callback);
return 1;
}
my $api_url = "https://$host:". xCAT::Goconserver::get_api_port();
$ret = xCAT::Goconserver::delete_nodes($api_url, $data, $delmode, $::callback);
if ($delmode) {
return $ret;