mirror of
https://github.com/xcat2/xcat-core.git
synced 2025-06-14 18:30:23 +00:00
Support rspconfig command to change PDU's ip address, netmask and
hostname
This commit is contained in:
@ -177,6 +177,8 @@ sub process_request
|
||||
my $subcmd = $exargs[0];
|
||||
if ($subcmd eq 'sshcfg') {
|
||||
process_sshcfg($noderange, $subcmd, $callback);
|
||||
}elsif ($subcmd =~ /=/) {
|
||||
process_netcfg($request, $subreq, $subcmd, $callback);
|
||||
} else {
|
||||
$callback->({ errorcode => [1],error => "The input $command $subcmd is not support for pdu"});
|
||||
}
|
||||
@ -467,6 +469,87 @@ sub connectTopdu {
|
||||
|
||||
}
|
||||
|
||||
#-------------------------------------------------------
|
||||
|
||||
=head3 process_netcfg
|
||||
|
||||
Config hostname of PDU
|
||||
Config ip/netmask of PDU via PduManager command
|
||||
PduManager is a tool for CoralPdu to manager the PDU.
|
||||
* /dev/shm/bin/PduManager -h
|
||||
'-i' set PDU system IP
|
||||
'-n' set system ip netmask. e.g.:PduManager -i xxx.xxx.xxx.xxx -n xxx.xxx.xxx.xxx
|
||||
|
||||
example: rspconfig coralpdu hostname=coralpdu
|
||||
rspconfig coralpdu ip=1.1.1.1,netmask=255.0.0.0
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------
|
||||
sub process_netcfg {
|
||||
my $request = shift;
|
||||
my $subreq = shift;
|
||||
my $subcmd = shift;
|
||||
my $callback = shift;
|
||||
my $hostname;
|
||||
my $ip;
|
||||
my $netmask;
|
||||
my $args;
|
||||
|
||||
my $nodes = $request->{node};
|
||||
my $rsp = {};
|
||||
|
||||
xCAT::MsgUtils->message("I", "set hostname ");
|
||||
my @cmds = split(/,/,$subcmd);
|
||||
foreach my $cmd (@cmds) {
|
||||
my ($key, $value) = split(/=/, $cmd);
|
||||
if ($key =~ /hostname/) {
|
||||
$hostname = $value;
|
||||
$args = "echo $hostname > /etc/hostname;/etc/init.d/hostname.sh";
|
||||
xCAT::Utils->runxcmd({ command => ['xdsh'],
|
||||
node => $nodes,
|
||||
arg => [ $args ] }, $subreq, 0, 1);
|
||||
if ($::RUNCMD_RC != 0) {
|
||||
xCAT::MsgUtils->message("I", "xdsh command to set hostname failed");
|
||||
}
|
||||
}elsif ($key =~ /ip/) {
|
||||
$ip = $value;
|
||||
} elsif ($key =~ /netmask/) {
|
||||
$netmask = $value;
|
||||
} else {
|
||||
xCAT::MsgUtils->message("I", "rspconfig $cmd is not support yet");
|
||||
}
|
||||
}
|
||||
|
||||
$args = "/dev/shm/bin/PduManager ";
|
||||
my $opt;
|
||||
if ($ip) {
|
||||
$opt = "-i $ip ";
|
||||
}
|
||||
if ($netmask) {
|
||||
$opt = $opt . "-n $netmask";
|
||||
}
|
||||
if ($opt) {
|
||||
my $dshcmd = $args . $opt ;
|
||||
#comment this for now, coralPDU on the lab is not support PduManager yet
|
||||
my $output = xCAT::Utils->runxcmd({ command => ['xdsh'], node => $nodes, arg => [ $dshcmd ] }, $subreq, 0, 1);
|
||||
if ($::RUNCMD_RC != 0) {
|
||||
xCAT::SvrUtils::sendmsg("@$output", $callback);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------
|
||||
|
||||
=head3 process_sshcfg
|
||||
|
||||
Config passwordless for coralpdu
|
||||
|
||||
example: rspconfig coralpdu sshcfg
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------
|
||||
sub process_sshcfg {
|
||||
my $noderange = shift;
|
||||
my $subcmd = shift;
|
||||
@ -585,6 +668,18 @@ sub session_exec {
|
||||
return($mbmatch);
|
||||
}
|
||||
|
||||
#-----------------------------------------------------------------
|
||||
|
||||
=head3 process_pdudiscover
|
||||
|
||||
Discover the pdu for a given range of DHCP ip address
|
||||
it will call switchdiscover command with -s snmp --pdu options
|
||||
|
||||
example: pdudiscover --range iprange -w
|
||||
|
||||
=cut
|
||||
|
||||
#------------------------------------------------------------------
|
||||
sub process_pdudiscover {
|
||||
my $request = shift;
|
||||
my $sub_req = shift;
|
||||
@ -615,8 +710,6 @@ sub process_pdudiscover {
|
||||
my $rsp = {};
|
||||
push @{ $rsp->{data} }, "$result";
|
||||
xCAT::MsgUtils->message("I", $rsp, $callback);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -1404,15 +1404,18 @@ sub matchPredefineSwitch {
|
||||
}
|
||||
|
||||
my $stype = get_switchtype($vendor);
|
||||
if (exists($globalopt{pdu})) {
|
||||
$stype="pdu";
|
||||
}
|
||||
|
||||
send_msg($request, 0, "$device discovered and matched: $dswitch to $node" );
|
||||
|
||||
# only write to xcatdb if -w or --setup option specified
|
||||
if ( (exists($globalopt{w})) || (exists($globalopt{setup})) ) {
|
||||
if (exists($globalopt{pdu})) {
|
||||
xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"otherinterfaces=$ip",'status=Matched',"mac=$mac","switchtype=$stype","usercomment=$vendor"] }, $sub_req, 0, 1);
|
||||
xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"otherinterfaces=$ip",'status=Matched',"mac=$mac","usercomment=$vendor"] }, $sub_req, 0, 1);
|
||||
} else {
|
||||
xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"otherinterfaces=$ip",'status=Matched',"mac=$mac","switchtype=$stype","usercomment=$vendor","switchtype=$stype"] }, $sub_req, 0, 1);
|
||||
xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"otherinterfaces=$ip",'status=Matched',"mac=$mac","switchtype=$stype","usercomment=$vendor"] }, $sub_req, 0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1436,6 +1439,35 @@ sub switchsetup {
|
||||
my $request = shift;
|
||||
my $sub_req = shift;
|
||||
if (exists($globalopt{pdu})) {
|
||||
my $mytype = "pdu";
|
||||
my $nodetab = xCAT::Table->new('hosts');
|
||||
my $nodehash = $nodetab->getNodesAttribs(\@{${nodes_to_config}->{$mytype}},['ip','otherinterfaces']);
|
||||
# get netmask from network table
|
||||
my $nettab = xCAT::Table->new("networks");
|
||||
my @nets;
|
||||
if ($nettab) {
|
||||
@nets = $nettab->getAllAttribs('net','mask');
|
||||
}
|
||||
|
||||
foreach my $pdu(@{${nodes_to_config}->{$mytype}}) {
|
||||
my $cmd = "rspconfig $pdu sshcfg";
|
||||
xCAT::Utils->runcmd($cmd, 0);
|
||||
my $ip = $nodehash->{$pdu}->[0]->{otherinterfaces};
|
||||
my $mask;
|
||||
foreach my $net (@nets) {
|
||||
if (xCAT::NetworkUtils::isInSameSubnet( $net->{'net'}, $ip, $net->{'mask'}, 0)) {
|
||||
$mask=$net->{'mask'};
|
||||
}
|
||||
}
|
||||
$cmd = "rspconfig $pdu hostname=$pdu,ip=$otherinterfaces,netmask=$mask";
|
||||
xCAT::Utils->runcmd($cmd, 0);
|
||||
if ($::RUNCMD_RC == 0) {
|
||||
xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$pdu,"ip=$ip","otherinterfaces="] }, $sub_req, 0, 1);
|
||||
} else {
|
||||
send_msg($request, 0, "Failed to run rspconfig command to set ip/netmask\n");
|
||||
}
|
||||
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user