mirror of
https://github.com/xcat2/xcat-core.git
synced 2025-05-29 17:23:08 +00:00
#2939: Add -d
option alias for makeknownhosts -r
This commit is contained in:
parent
5416a7546e
commit
b8fdb3c890
@ -4,7 +4,7 @@ B<makeknownhosts> - Make a known_hosts file under $ROOTHOME/.ssh for input noder
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
B<makeknownhosts> I<noderange> [B<-r>|B<--remove>] [B<-V>|B<--verbose>]
|
||||
B<makeknownhosts> I<noderange> [B<-r>|B<--remove>|B<-d>|B<--delete>] [B<-V>|B<--verbose>]
|
||||
|
||||
B<makeknownhosts> [B<-h>|B<--help>]
|
||||
|
||||
@ -29,10 +29,14 @@ The file should be distributed using B<xdcp> to all the nodes, if you want node
|
||||
A set of comma delimited node names and/or group names.
|
||||
See the I<noderange> man page for details on supported formats.
|
||||
|
||||
=item B<-r|--remove>
|
||||
=item B<-d|--delete>
|
||||
|
||||
Only removes the entries for the nodes from the known_hosts file.
|
||||
|
||||
=item B<-r|--remove>
|
||||
|
||||
Synonymous to B<-d|--delete>.
|
||||
|
||||
=item B<-V|--verbose>
|
||||
|
||||
Verbose mode.
|
||||
@ -56,7 +60,7 @@ To build the known_hosts entry for the nodes in the lpars and service groups
|
||||
=item 3.
|
||||
To remove the known_hosts entry for node02
|
||||
|
||||
makeknownhosts node02 -r
|
||||
makeknownhosts node02 -d
|
||||
|
||||
=back
|
||||
|
||||
|
@ -130,7 +130,7 @@ sub process_request {
|
||||
if ($runconservercmd) {
|
||||
push @commandslist, [ 'makeconservercf', '-d' ];
|
||||
}
|
||||
push @commandslist, [ 'makeknownhosts', '-r' ];
|
||||
push @commandslist, [ 'makeknownhosts', '-d' ];
|
||||
if ($macflag) {
|
||||
push @commandslist, [ 'makedhcp', '-d' ];
|
||||
}
|
||||
|
@ -65,13 +65,14 @@ sub process_request
|
||||
if ($request && $request->{arg}) { @ARGV = @{ $request->{arg} }; }
|
||||
else { @ARGV = (); }
|
||||
|
||||
my $usage = "Usage: makeknownhosts <noderange> [-r] [-V]\n makeknownhosts -h";
|
||||
my $usage = "Usage: makeknownhosts <noderange> [-r|-d] [-V]\n makeknownhosts -h";
|
||||
|
||||
# print "argv=@ARGV\n";
|
||||
if (!GetOptions(
|
||||
'h|help' => \$::opt_h,
|
||||
'V|verbose' => \$::opt_V,
|
||||
'r|remove' => \$::opt_r
|
||||
'd|delete' => \$::opt_d
|
||||
))
|
||||
{
|
||||
my $rsp = {};
|
||||
@ -81,23 +82,22 @@ sub process_request
|
||||
}
|
||||
|
||||
# display the usage if -h
|
||||
if ($::opt_h)
|
||||
{
|
||||
if ($::opt_h) {
|
||||
my $rsp = {};
|
||||
$rsp->{data}->[0] = $usage;
|
||||
xCAT::MsgUtils->message("I", $rsp, $callback, 1);
|
||||
return 0;
|
||||
}
|
||||
if ($nodes eq "")
|
||||
{ # no noderange
|
||||
if ($nodes eq "") {
|
||||
# no noderange
|
||||
my $rsp = {};
|
||||
$rsp->{data}->[0] = "The Noderange is missing.";
|
||||
xCAT::MsgUtils->message("E", $rsp, $callback, 1);
|
||||
return 1;
|
||||
}
|
||||
my $hostkey = "/etc/xcat/hostkeys/ssh_host_rsa_key.pub";
|
||||
if (!(-e $hostkey))
|
||||
{ # the key is missing, cannot create known_hosts
|
||||
if (!(-e $hostkey)) {
|
||||
# the key is missing, cannot create known_hosts
|
||||
my $rsp = {};
|
||||
$rsp->{data}->[0] =
|
||||
"The keyfile:$hostkey is missing. Cannot create the known_hosts file.";
|
||||
@ -107,35 +107,28 @@ sub process_request
|
||||
|
||||
# Backup the existing known_hosts file to known_hosts.backup
|
||||
$rc = backup_known_hosts_file($callback);
|
||||
if ($rc != 0)
|
||||
{
|
||||
if ($rc != 0) {
|
||||
my $rsp = {};
|
||||
$rsp->{data}->[0] = "Error backing up known_hosts file.";
|
||||
xCAT::MsgUtils->message("E", $rsp, $callback, 1);
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
# Remove the nodes from knownhosts file
|
||||
$rc = remove_nodes_from_knownhosts($callback, $nodes);
|
||||
if ($rc != 0)
|
||||
{
|
||||
if ($rc != 0) {
|
||||
my $rsp = {};
|
||||
$rsp->{data}->[0] = "Error backing up known_hosts file.";
|
||||
xCAT::MsgUtils->message("E", $rsp, $callback, 1);
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
# if -r flag is not specified, adding the nodes back to known_hosts file
|
||||
if (!$::opt_r)
|
||||
{
|
||||
if (!($::opt_r or $::opt_d)) {
|
||||
my @nodelist = @$nodes;
|
||||
foreach my $node (@nodelist)
|
||||
{
|
||||
foreach my $node (@nodelist) {
|
||||
$rc = add_known_host($node, $callback);
|
||||
if ($rc != 0)
|
||||
{
|
||||
if ($rc != 0) {
|
||||
my $rsp = {};
|
||||
$rsp->{data}->[0] = "Error building known_hosts file.";
|
||||
xCAT::MsgUtils->message("E", $rsp, $callback, 1);
|
||||
@ -153,8 +146,6 @@ sub process_request
|
||||
Backs up the old known_hosts file in roots .ssh directory,
|
||||
if it exists.
|
||||
|
||||
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------
|
||||
|
@ -28,6 +28,18 @@ check:rc!=0
|
||||
check:output!~$$CN
|
||||
end
|
||||
|
||||
start:makeknownhosts_node_d
|
||||
description:delete known node entry from $ROOTHOME/.ssh
|
||||
cmd:makeknownhosts $$CN
|
||||
cmd:cat ~/.ssh/known_hosts|grep $$CN
|
||||
check:output=~$$CN
|
||||
cmd:makeknownhosts $$CN -d
|
||||
check:rc==0
|
||||
cmd:cat ~/.ssh/known_hosts|grep $$CN
|
||||
check:rc!=0
|
||||
check:output!~$$CN
|
||||
end
|
||||
|
||||
start:makeknownhosts_node_v
|
||||
description:verbose
|
||||
cmd:makeknownhosts $$CN -V
|
||||
|
Loading…
x
Reference in New Issue
Block a user