mirror of
https://github.com/xcat2/xcat-core.git
synced 2025-06-02 19:40:10 +00:00
Add makegocons -C|--cleanup to remove entries that do not exist
`rmdef` command do not help clean up the recousrces that related to the node when removing the node. this is a technical debt. This patch is only a work around to add -C|--cleanup option to help remove the entries in goconserver.
This commit is contained in:
parent
02200a8e68
commit
e86d544242
@ -90,7 +90,7 @@ OPTIONS
|
||||
|
||||
\ **-C|-**\ **-cleanup**\
|
||||
|
||||
Perform additional cleanup by running \ **nodeset offline**\ and \ **makeconservercf -d**\ on the objects specified in the \ *noderange*\ .
|
||||
Perform additional cleanup by running \ **nodeset offline**\, \ **makeconservercf -d**\ and \ **makegocons --cleanup**\ on the objects specified in the \ *noderange*\ .
|
||||
|
||||
|
||||
|
||||
|
@ -21,6 +21,8 @@ SYNOPSIS
|
||||
|
||||
\ **makegocons**\ [\ **-V|-**\ **-verbose**\ ] [\ **-d|-**\ **-delete**\ ] [\ **-q|-**\ **-query**\ ] [\ *noderange*\ ]
|
||||
|
||||
\ **makegocons**\ [\ **-V|-**\ **-verbose**\ ] [\ **-C|-**\ **-cleanup**\ ]
|
||||
|
||||
|
||||
***********
|
||||
DESCRIPTION
|
||||
@ -70,6 +72,12 @@ OPTIONS
|
||||
|
||||
|
||||
|
||||
\ **-C|-**\ **-cleanup**\
|
||||
|
||||
Remove the entries for the nodes whose definitions have been removed from xCAT db.
|
||||
|
||||
|
||||
|
||||
\ **-q|-**\ **-query**\
|
||||
|
||||
List the console connection of the nodes. If noderange is not specified, all of the console nodes will be displayed.
|
||||
|
@ -58,7 +58,7 @@ A set of comma delimited object types.
|
||||
|
||||
=item B<-C|--cleanup>
|
||||
|
||||
Perform additional cleanup by running B<nodeset offline> and B<makeconservercf -d> on the objects specified in the I<noderange>.
|
||||
Perform additional cleanup by running B<nodeset offline>, B<makeconservercf -d> and B<makegocons --cleanup> on the objects specified in the I<noderange>.
|
||||
|
||||
=item B<-V|--verbose>
|
||||
|
||||
|
@ -6,6 +6,7 @@ B<makegocons> - Register or unregister the node in the goconserver service
|
||||
|
||||
B<makegocons> [B<-V|--verbose>] [B<-d|--delete>] [B<-q|--query>] [I<noderange>]
|
||||
|
||||
B<makegocons> [B<-V|--verbose>] [B<-C|--cleanup>]
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
@ -48,6 +49,10 @@ B<Note:> goconserver only support the systemd based systems. It has been integra
|
||||
|
||||
Delete rather than add or refresh the nodes specified as a noderange.
|
||||
|
||||
=item B<-C|--cleanup>
|
||||
|
||||
Remove the entries for the nodes whose definitions have been removed from xCAT db.
|
||||
|
||||
=item B<-q|--query>
|
||||
|
||||
List the console connection of the nodes. If noderange is not specified, all of the console nodes will be displayed.
|
||||
|
@ -22,6 +22,7 @@ use IO::Socket::SSL qw( SSL_VERIFY_PEER );
|
||||
my $go_api_port = 12429;
|
||||
my $go_cons_port = 12430;
|
||||
my $bmc_cons_port = "2200";
|
||||
my $isSN = xCAT::Utils->isServiceNode();
|
||||
|
||||
use constant CONSOLE_LOG_DIR => "/var/log/consoles";
|
||||
use constant PRINT_FORMAT => "%-32s %-32s %-64s";
|
||||
@ -58,7 +59,7 @@ sub http_request {
|
||||
}
|
||||
|
||||
sub gen_request_data {
|
||||
my ($cons_map, $siteondemand, $isSN, $callback) = @_;
|
||||
my ($cons_map, $siteondemand, $callback) = @_;
|
||||
my (@openbmc_nodes, $data);
|
||||
while (my ($k, $v) = each %{$cons_map}) {
|
||||
my $ondemand;
|
||||
@ -397,6 +398,81 @@ sub list_nodes {
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub cleanup_nodes {
|
||||
my $callback = shift;
|
||||
my @hostinfo = xCAT::NetworkUtils->determinehostname();
|
||||
my $host = $hostinfo[-1];
|
||||
my $api_url = "https://$host:". get_api_port();
|
||||
my $rsp;
|
||||
my $response = http_request("GET", "$api_url/nodes");
|
||||
if (!defined($response)) {
|
||||
if ($callback) {
|
||||
$rsp->{data}->[0] = "Failed to send list request.";
|
||||
xCAT::MsgUtils->message("E", $rsp, $callback);
|
||||
} else {
|
||||
xCAT::MsgUtils->message("S", "Failed to send list request.");
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
if (!$response->{nodes}) {
|
||||
return 0;
|
||||
}
|
||||
my %delete_map;
|
||||
my %cons_map = get_cons_map(undef);
|
||||
foreach my $node (@{$response->{nodes}}) {
|
||||
# not in xcatdb but exist in goconserver
|
||||
$delete_map{$node->{name}} = 1 if !exists($cons_map{$node->{name}});
|
||||
}
|
||||
return delete_nodes($api_url, \%delete_map, 1, $callback);
|
||||
}
|
||||
|
||||
sub get_cons_map {
|
||||
my $req = shift;
|
||||
my %iphash = ();
|
||||
my %cons_map;
|
||||
my $hmtab = xCAT::Table->new('nodehm');
|
||||
my @cons_nodes;
|
||||
my @hostinfo = xCAT::NetworkUtils->determinehostname();
|
||||
foreach (@hostinfo) {
|
||||
$iphash{$_} = 1;
|
||||
}
|
||||
if (defined($req) && (($req->{node} and @{$req->{node}} > 0) or $req->{noderange}->[0])) {
|
||||
# Note: do not consider terminal server currently
|
||||
@cons_nodes = $hmtab->getNodesAttribs($req->{node}, [ 'node', 'cons', 'serialport', 'mgt', 'conserver', 'consoleondemand' ]);
|
||||
# Adjust the data structure to make the result consistent with the getAllNodeAttribs() call we make if a noderange was not specified
|
||||
my @tmpcons_nodes;
|
||||
foreach my $ent (@cons_nodes)
|
||||
{
|
||||
foreach my $nodeent (keys %$ent)
|
||||
{
|
||||
push @tmpcons_nodes, $ent->{$nodeent}->[0];
|
||||
}
|
||||
}
|
||||
@cons_nodes = @tmpcons_nodes
|
||||
} else {
|
||||
@cons_nodes = $hmtab->getAllNodeAttribs([ 'cons', 'serialport', 'mgt', 'conserver', 'consoleondemand' ]);
|
||||
}
|
||||
$hmtab->close();
|
||||
my $rsp;
|
||||
|
||||
foreach (@cons_nodes) {
|
||||
if ($_->{cons} or defined($_->{'serialport'})) {
|
||||
unless ($_->{cons}) { $_->{cons} = $_->{mgt}; } #populate with fallback
|
||||
if ($isSN && $_->{conserver} && exists($iphash{ $_->{conserver} }) || !$isSN) {
|
||||
$cons_map{ $_->{node} } = $_; # also put the ref to the entry in a hash for quick look up
|
||||
} else {
|
||||
$rsp->{data}->[0] = $_->{node} .": ignore, the host for conserver could not be determined.";
|
||||
xCAT::MsgUtils->message("I", $rsp, $::callback);
|
||||
}
|
||||
} else {
|
||||
$rsp->{data}->[0] = $_->{node} .": ignore, cons attribute or serialport attribute is not specified.";
|
||||
xCAT::MsgUtils->message("I", $rsp, $::callback);
|
||||
}
|
||||
}
|
||||
return %cons_map;
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
=head3 is_xcat_conf_ready
|
||||
|
@ -4423,6 +4423,12 @@ sub defrm
|
||||
command => ['makeconservercf'],
|
||||
node => [@allnodes],
|
||||
arg => ['-d'],}, $doreq, 0, 1);
|
||||
if (-x "/usr/bin/goconserver") {
|
||||
require xCAT::Goconserver;
|
||||
if (xCAT::Goconserver::is_goconserver_running()) {
|
||||
xCAT::Goconserver::cleanup_nodes(undef);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@ my $host;
|
||||
my $usage_string =" makegocons [-V|--verbose] [-d|--delete] noderange
|
||||
-h|--help Display this usage statement.
|
||||
-v|--version Display the version number.
|
||||
-C|--cleanup Remove the entries for the nodes whose definitions have been removed from xCAT db.
|
||||
-q|--query [noderange] Display the console connection status.";
|
||||
|
||||
my $version_string = xCAT::Utils->Version();
|
||||
@ -138,50 +139,6 @@ sub process_request {
|
||||
}
|
||||
}
|
||||
|
||||
sub get_cons_map {
|
||||
my ($req, $iphashref) = @_;
|
||||
my %cons_map;
|
||||
my %iphash = %{$iphashref};
|
||||
my $hmtab = xCAT::Table->new('nodehm');
|
||||
my @cons_nodes;
|
||||
|
||||
if (($req->{node} and @{$req->{node}} > 0) or $req->{noderange}->[0]) {
|
||||
# Note: do not consider terminal server currently
|
||||
@cons_nodes = $hmtab->getNodesAttribs($req->{node}, [ 'node', 'cons', 'serialport', 'mgt', 'conserver', 'consoleondemand' ]);
|
||||
# Adjust the data structure to make the result consistent with the getAllNodeAttribs() call we make if a noderange was not specified
|
||||
my @tmpcons_nodes;
|
||||
foreach my $ent (@cons_nodes)
|
||||
{
|
||||
foreach my $nodeent (keys %$ent)
|
||||
{
|
||||
push @tmpcons_nodes, $ent->{$nodeent}->[0];
|
||||
}
|
||||
}
|
||||
@cons_nodes = @tmpcons_nodes
|
||||
|
||||
} else {
|
||||
@cons_nodes = $hmtab->getAllNodeAttribs([ 'cons', 'serialport', 'mgt', 'conserver', 'consoleondemand' ]);
|
||||
}
|
||||
$hmtab->close();
|
||||
my $rsp;
|
||||
|
||||
foreach (@cons_nodes) {
|
||||
if ($_->{cons} or defined($_->{'serialport'})) {
|
||||
unless ($_->{cons}) { $_->{cons} = $_->{mgt}; } #populate with fallback
|
||||
if ($isSN && $_->{conserver} && exists($iphash{ $_->{conserver} }) || !$isSN) {
|
||||
$cons_map{ $_->{node} } = $_; # also put the ref to the entry in a hash for quick look up
|
||||
} else {
|
||||
$rsp->{data}->[0] = $_->{node} .": ignore, the host for conserver could not be determined.";
|
||||
xCAT::MsgUtils->message("I", $rsp, $::callback);
|
||||
}
|
||||
} else {
|
||||
$rsp->{data}->[0] = $_->{node} .": ignore, cons attribute or serialport attribute is not specified.";
|
||||
xCAT::MsgUtils->message("I", $rsp, $::callback);
|
||||
}
|
||||
}
|
||||
return %cons_map;
|
||||
}
|
||||
|
||||
sub start_goconserver {
|
||||
my ($rsp, $running, $ready, $ret);
|
||||
unless (-x "/usr/bin/goconserver") {
|
||||
@ -233,18 +190,24 @@ sub makegocons {
|
||||
}
|
||||
@ARGV = @exargs;
|
||||
$Getopt::Long::ignorecase = 0;
|
||||
my ($delmode, $querymode);
|
||||
my ($delmode, $querymode, $cleanupmode);
|
||||
GetOptions('d|delete' => \$delmode,
|
||||
'q|query' => \$querymode,
|
||||
'C|cleanup' => \$cleanupmode,
|
||||
);
|
||||
|
||||
my $svboot = 0;
|
||||
if (exists($req->{svboot})) {
|
||||
$svboot = 1;
|
||||
}
|
||||
my %iphash = ();
|
||||
foreach (@$hostinfo) { $iphash{$_} = 1; }
|
||||
my %cons_map = get_cons_map($req, \%iphash);
|
||||
if ($cleanupmode) {
|
||||
if (exists($req->{_allnodes}) && $req->{_allnodes}->[0] != 1) {
|
||||
xCAT::SvrUtils::sendmsg([ 1, "Can not specify noderange together with -C|--cleanup." ], $::callback);
|
||||
return 1;
|
||||
}
|
||||
return xCAT::Goconserver::cleanup_nodes($::callback);
|
||||
}
|
||||
my %cons_map = xCAT::Goconserver::get_cons_map($req);
|
||||
if (! %cons_map) {
|
||||
xCAT::SvrUtils::sendmsg([ 1, "Could not get any console request entry" ], $::callback);
|
||||
return 1;
|
||||
@ -271,7 +234,7 @@ sub makegocons {
|
||||
}
|
||||
}
|
||||
my (@nodes);
|
||||
my $data = xCAT::Goconserver::gen_request_data(\%cons_map, $siteondemand, $isSN, $::callback);
|
||||
my $data = xCAT::Goconserver::gen_request_data(\%cons_map, $siteondemand, $::callback);
|
||||
if (! $data) {
|
||||
xCAT::SvrUtils::sendmsg([ 1, "Could not generate the request data" ], $::callback);
|
||||
return 1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user