diff --git a/docs/source/advanced/pdu/irpdu.rst b/docs/source/advanced/pdu/irpdu.rst index c7a557ed7..dccaf049a 100644 --- a/docs/source/advanced/pdu/irpdu.rst +++ b/docs/source/advanced/pdu/irpdu.rst @@ -47,6 +47,14 @@ The following commands are supported against a compute node: The following commands are supported against a PDU: + * To change hostname of IR PDU: :: + + # rspconfig f5pdu3 hosname=f5pdu3 + + * To change ip address of IR PDU: :: + + # rsconfig f5pdu3 ip=x.x.x.x netmaks=255.x.x.x + * Check the status of the full PDU: :: # rpower f5pdu3 stat diff --git a/docs/source/advanced/pdu/pdu.rst b/docs/source/advanced/pdu/pdu.rst index 0157ee8da..6e0ca6862 100644 --- a/docs/source/advanced/pdu/pdu.rst +++ b/docs/source/advanced/pdu/pdu.rst @@ -20,7 +20,7 @@ xCAT uses snmp scan method to discover PDU. Make sure net-snmp-utils package is -x XML formatted output. -z Stanza formatted output. -w Writes output to xCAT database. - --setup Process switch-based pdu discovery and configure the PDUs(it included passwordless , change ip address from dhcp to static and snmp configuration). It required predefined PDU node definition with switch name and switch port attributes for mapping. (Notes: only support for crpdu for now for this options) + --setup Process switch-based pdu discovery and configure the PDUs. For crpdu, --setup options will configure passwordless , change ip address from dhcp to static, hostname changes and snmp v3 configuration. For irpdu, it will configure ip address and hostname. It required predefined PDU node definition with switch name and switch port attributes for mapping. Define PDU Objects diff --git a/xCAT-server/lib/xcat/plugins/pdu.pm b/xCAT-server/lib/xcat/plugins/pdu.pm index eca4553bf..f62121089 100644 --- a/xCAT-server/lib/xcat/plugins/pdu.pm +++ b/xCAT-server/lib/xcat/plugins/pdu.pm @@ -76,20 +76,21 @@ sub pdu_usage my ($callback, $command) = @_; my $usagemsg = "Usage: + The following commands support both type of PDUs : pdudiscover [|--range ipranges] [-r|-x|-z] [-w] [-V|--verbose] [--setup] rpower pdunodes [off|on|stat|reset] + rinv pdunodes + rvitals pdunodes - The following command supports IR PDU with pdutype=irpdu : - rpower CN [pduoff|pduon|pdustat|pdustatus|pdureset] + The following commands support IR PDU with pdutype=irpdu : + rpower computenodes [pduoff|pduon|pdustat|pdustatus|pdureset] + rspconfig irpdunode [hostname=|ip=|gateway=|mask=] The following commands support CR PDU with pdutype=crpdu : rpower pdunodes relay=[1|2|3] [on|off] - rinv pdunodes - rvitals pdunodes rspconfig pdunodes sshcfg rspconfig pdunodes snmpcfg rspconfig pdunode [hostname=|ip=|mask=] - \n"; if ($callback) @@ -214,7 +215,7 @@ sub process_request process_sshcfg($noderange, $subcmd, $callback); }elsif ($subcmd eq 'snmpcfg') { process_snmpcfg($noderange, $subcmd, $callback); - }elsif ($subcmd =~ /ip|netmask|hostname/) { + }elsif ($subcmd =~ /ip|gateway|netmask|hostname/) { process_netcfg($request, $subreq, $subcmd, $callback); } else { $callback->({ errorcode => [1],error => "The input $command $subcmd is not support for pdu"}); @@ -628,17 +629,19 @@ sub process_netcfg { my $pdutab = xCAT::Table->new('pdu'); my $pduhash = $pdutab->getNodesAttribs($nodes, ['pdutype']); - unless ($pduhash->{$pdu}->[0]->{pdutype} eq "crpdu") { - xCAT::SvrUtils::sendmsg("This command only supports CONSTELLATION PDU with pdutype=crpdu", $callback,$pdu); - return; - } my $nodetab = xCAT::Table->new('hosts'); my $nodehash = $nodetab->getNodesAttribs($nodes,['ip','otherinterfaces']); - - # connect to PDU my $static_ip = $nodehash->{$pdu}->[0]->{ip}; my $discover_ip = $nodehash->{$pdu}->[0]->{otherinterfaces}; + + unless ($pduhash->{$pdu}->[0]->{pdutype} eq "crpdu") { + netcfg_for_irpdu($pdu, $static_ip, $discover_ip, $request, $subreq, $callback); + return; + } + + + # connect to PDU ($exp, $errstr) = session_connect($static_ip, $discover_ip); if (defined $errstr) { xCAT::SvrUtils::sendmsg("Failed to connect", $callback,$pdu); @@ -1361,6 +1364,158 @@ sub process_snmpcfg { } } +#------------------------------------------------------- + +=head3 netcfg_for_irpdu + + change hostname and network setting for IR PDU. + +=cut +#------------------------------------------------------- +sub netcfg_for_irpdu { + my $pdu = shift; + my $static_ip = shift; + my $discover_ip = shift; + my $request = shift; + my $subreq = shift; + my $callback = shift; + my $hostname; + my $ip; + my $gateway; + my $netmask; + + my $extrargs = $request->{arg}; + my @exargs = ($request->{arg}); + if (ref($extrargs)) { + @exargs = @$extrargs; + } + + #default password for irpdu + my $passwd = "1001"; + my $username = "ADMIN"; + my $timeout = 20; + my $send_change = "N"; + + my $login_ip; + + # somehow, only system command works for checking if irpdu is pingable + # Net::Ping Module and xCAT::NetworkUtils::isPingable both are not working + if (system("ping -c 2 $static_ip") == 0 ) { + $login_ip = $static_ip; + } elsif (system("ping -c 2 $discover_ip") == 0) { + $login_ip = $discover_ip; + } else { + xCAT::SvrUtils::sendmsg(" is not reachable", $callback,$pdu); + } + + foreach my $cmd (@exargs) { + my ($key, $value) = split(/=/, $cmd); + if ($key =~ /hostname/) { + $hostname = $value; + xCAT::SvrUtils::sendmsg("change pdu hostname to $hostname", $callback); + } + if ($key =~ /ip/) { + $ip = $value; + $send_change = "Y"; + xCAT::SvrUtils::sendmsg("change ip address for $pdu to $ip", $callback); + } + if ($key =~ /gateway/) { + $gateway = $value; + $send_change = "Y"; + xCAT::SvrUtils::sendmsg("change gateway for $pdu to $gateway", $callback); + } + if ($key =~ /netmask/) { + $netmask = $value; + $send_change = "Y"; + xCAT::SvrUtils::sendmsg("change netmask for $pdu to $netmask", $callback); + } + + } + + my $login_cmd = "telnet $login_ip\r"; + my $user_prompt = " Login: "; + my $pwd_prompt = "Password: "; + my $pdu_prompt = "Please Enter Your Selection => "; + my $send_zero = 0; + my $send_one = 1; + my $send_two = 2; + + my $mypdu = new Expect; + + $mypdu->log_stdout(1); # suppress stdout output.. + $mypdu->slave->stty(qw(sane -echo)); + + unless ($mypdu->spawn($login_cmd)) + { + $mypdu->soft_close(); + xCAT::SvrUtils::sendmsg("Unable to run $login_cmd", $callback); + return; + } + my @result = $mypdu->expect( + $timeout, + [ + $user_prompt, + sub { + $mypdu->clear_accum(); + $mypdu->send("$username\r"); + $mypdu->clear_accum(); + $mypdu->exp_continue(); + } + ], + [ + $pwd_prompt, + sub { + $mypdu->clear_accum(); + $mypdu->send("$passwd\r"); + $mypdu->clear_accum(); + $mypdu->exp_continue(); + } + ], + [ + $pdu_prompt, + sub { + $mypdu->clear_accum(); + $mypdu->send("$send_one\r"); + $mypdu->send("$send_one\r"); + #change hostname + $mypdu->send("$send_one\r"); + $mypdu->send("$hostname\r"); + $mypdu->send("$send_zero\r"); + #change network setting + $mypdu->send("$send_two\r"); + $mypdu->send("$send_one\r"); + $mypdu->send("$ip\r"); + $mypdu->send("$gateway\r"); + $mypdu->send("$netmask\r"); + $mypdu->send("$send_change\r"); + # go back Previous Menu + $mypdu->send("$send_zero\r"); + $mypdu->send("$send_zero\r"); + } + ], + ); + + if (defined($result[1])) + { + my $errmsg = $result[1]; + $mypdu->soft_close(); + xCAT::SvrUtils::sendmsg("Failed expect command $errmsg", $callback); + return; + } + $mypdu->soft_close(); + + xCAT::SvrUtils::sendmsg("hostname or network setting changed, update node definition ", $callback); + xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$pdu,"otherinterfaces="] }, $subreq, 0, 1); + if ( (defined $ip) and ($static_ip ne $ip) ) { + xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$pdu,"ip=$ip",'status=configured'] }, $subreq, 0, 1); + xCAT::Utils->runxcmd({ command => ['makehosts'], node => [$pdu] }, $subreq, 0, 1); + } + + return; +} + + + 1; diff --git a/xCAT-server/lib/xcat/plugins/switchdiscover.pm b/xCAT-server/lib/xcat/plugins/switchdiscover.pm index 7c3277154..630727af7 100644 --- a/xCAT-server/lib/xcat/plugins/switchdiscover.pm +++ b/xCAT-server/lib/xcat/plugins/switchdiscover.pm @@ -1440,31 +1440,38 @@ sub switchsetup { @nets = $nettab->getAllAttribs('net','mask'); } foreach my $mytype (keys %$nodes_to_config) { - if ( $mytype eq "irpdu" ) { - send_msg($request, 0, "the setup options for irpdu is not support yet\n"); - } elsif ( $mytype eq "crpdu" ) { - my $nodetab = xCAT::Table->new('hosts'); - my $nodehash = $nodetab->getNodesAttribs(\@{${nodes_to_config}->{$mytype}},['ip','otherinterfaces']); - foreach my $pdu(@{${nodes_to_config}->{$mytype}}) { - my $cmd = "rspconfig $pdu sshcfg"; - xCAT::Utils->runcmd($cmd, 0); - my $ip = $nodehash->{$pdu}->[0]->{ip}; - 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=$ip 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"); + my $nodetab = xCAT::Table->new('hosts'); + my $nodehash = $nodetab->getNodesAttribs(\@{${nodes_to_config}->{$mytype}},['ip','otherinterfaces']); + foreach my $pdu(@{${nodes_to_config}->{$mytype}}) { + my $ip = $nodehash->{$pdu}->[0]->{ip}; + my $mask; + foreach my $net (@nets) { + if (xCAT::NetworkUtils::isInSameSubnet( $net->{'net'}, $ip, $net->{'mask'}, 0)) { + $mask=$net->{'mask'}; } } - } else { - send_msg($request, 0, "the pdu type $mytype is not support\n"); + my $cmd; + my $rc = 0; + if ( $mytype eq "crpdu" ) { + $cmd = "rspconfig $pdu sshcfg"; + send_msg($request, 0, "process command: $cmd\n"); + $rc = xCAT::Utils->runcmd($cmd, 0); + $cmd = "rspconfig $pdu hostname=$pdu ip=$ip netmask=$mask"; + send_msg($request, 0, "process command: $cmd\n"); + $rc = xCAT::Utils->runcmd($cmd, 0); + } elsif ( $mytype eq "irpdu" ) { + $cmd = "rspconfig $pdu hostname=$pdu ip=$ip netmask=$mask"; + send_msg($request, 0, "process command: $cmd\n"); + $rc = xCAT::Utils->runcmd($cmd, 0); + } else { + send_msg($request, 0, "the pdu type $mytype is not support\n"); + $rc = 1; + } + if ($rc == 0) { + xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$pdu,'status=configured',"ip=$ip","otherinterfaces="] }, $sub_req, 0, 1); + } else { + send_msg($request, 0, "Failed to run rspconfig command to set ip/netmask\n"); + } } } return;