2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-05-29 09:13:08 +00:00

Add more print statement for config switches scripts (#4872)

* Add more print statement for config switches scripts

* modified from reviews

* more modify from review
This commit is contained in:
cxhong 2018-03-05 22:25:38 -05:00 committed by yangsong
parent c43d74f6a0
commit 4038056879
5 changed files with 64 additions and 37 deletions

View File

@ -105,7 +105,7 @@ if **--setup** flag is specified, the command will perform following steps:
snmppassword=xcatadminpassw0rd@snmp
snmpusername=xcatadmin
snmpversion=3
status=hostname_configed
status=hostname_configured
statustime=08-31-2016 15:35:49
supportedarchs=ppc64
switch=switch-10-5-23-1
@ -155,13 +155,13 @@ These two config files are located in the **/opt/xcat/share/xcat/scripts** direc
Switch Status
~~~~~~~~~~~~~
During the switch-based switch discovery process, there are four states displayed. User may only see **switch_configed** status on node definition if discovery process successfully finished.
During the switch-based switch discovery process, there are four states displayed. User may only see **switch_configured** status on node definition if discovery process successfully finished.
**Matched** --- Discovered switch is matched to predefine switch, **otherinterfaces** attribute is updated to dhcp IP address, and mac address, **switch type** and **usercomment** also updated with vendor information for the predefined switch.
**ip_configed** --- switch is set up to static IP address based on predefine switch IP address. If failure to set up IP address, the status will stay as **Matched**.
**ip_configured** --- switch is set up to static IP address based on predefine switch IP address. If failure to set up IP address, the status will stay as **Matched**.
**hostname_configed** -- switch host name is changed based on predefine switch hostname. If failure to change hostname on the switch, the status will stay as **ip_configed**.
**hostname_configured** -- switch host name is changed based on predefine switch hostname. If failure to change hostname on the switch, the status will stay as **ip_configured**.
**switch_configed** -- snmpv3 is setup for the switches. This should be finial status after running ``switchdiscover --setup`` command. If failure to setup snmpv3, the status will stay as **hostname_configed**.
**switch_configured** -- snmpv3 is setup for the switches. This should be finial status after running ``switchdiscover --setup`` command. If failure to setup snmpv3, the status will stay as **hostname_configured**.

View File

@ -1491,20 +1491,20 @@ sub switchsetup {
if (-r -x $config_script) {
my $switches = join(",",@{${nodes_to_config}->{$mytype}});
if ($mytype eq "onie") {
send_msg($request, 0, "Call to config $switches\n");
send_msg($request, 0, "Calling $config_script to configure $mytype switches $switches...");
my $out = `$config_script --switches $switches --all`;
send_msg($request, 0, "output = $out\n");
send_msg($request, 0, "$out");
} else {
send_msg($request, 0, "call to config $mytype switches $switches\n");
send_msg($request, 0, "Calling $config_script to configure $mytype switches $switches...");
if ($mytype =~ /Mellanox/) {
send_msg($request, 0, "NOTE: If command takes too long for Mellanox IB switch, please CTRL C out of the command\n");
send_msg($request, 0, "then run $config_script --switches $switches --all\n");
send_msg($request, 0, "NOTE: If command takes too long for Mellanox IB switch, open another window and ping the switches being configured, once they are complete, ctrl-c out of this command");
send_msg($request, 0, "then run $config_script --switches $switches --all again");
}
my $out = `$config_script --switches $switches --all`;
send_msg($request, 0, "output = $out\n");
send_msg($request, 0, "$out");
}
} else {
send_msg($request, 0, "the switch type $mytype is not support yet\n");
send_msg($request, 0, "the switch type $mytype is not support yet");
}
}

View File

@ -162,7 +162,7 @@ sub config_ip {
}
foreach my $switch (@nodes) {
print "change $switch to static ip address\n";
print "change $switch to static IP address\n";
#makesure host is in the /etc/hosts
$cmd = "makehosts $switch";
@ -171,7 +171,7 @@ sub config_ip {
my $dip= $nodehash->{$switch}->[0]->{otherinterfaces};
my $mac= $machash->{$switch}->[0]->{mac};
if (!$dip) {
print "ERROR: Add otherinterfaces attribute for discover ip: chdef $switch otherinterfaces=x.x.x.x\n";
print "ERROR: Add otherinterfaces attribute for discover IP: chdef $switch otherinterfaces=x.x.x.x\n";
next;
}
@ -186,7 +186,7 @@ sub config_ip {
# don't need to set if ip addresses are same
if ($dip eq $static_ip) {
print "static ip $static_ip and discovery ip $dip is same, will not process command for $switch\n";
print "static IP $static_ip and discovery IP $dip is same, will not process command for $switch\n";
$cmd = "chdef $switch otherinterfaces=";
$rc= xCAT::Utils->runcmd($cmd, 0);
next;
@ -220,6 +220,7 @@ sub config_ip {
}
}
print "Changing IP address of $dswitch to $static_ip...\n";
# For RackSwitch G8124
if ($mac =~ /fc\:cf\:62/i) {
$cmd="xdsh $dswitch -t 10 --devicetype EthSwitch::BNT 'enable;configure terminal;show interface ip;interface ip-mgmt enable;interface ip-mgmt address $static_ip $mask;exit' ";
@ -246,7 +247,7 @@ sub config_ip {
}
print "retry $retry_failed\n";
if ($retry_failed) {
print "Failed to set up static ip address: $static_ip for $switch\n";
print "Failed to set up static IP address: $static_ip for $switch\n";
push (@discover_switches, $dswitch);
next;
}
@ -257,8 +258,9 @@ sub config_ip {
if (@config_switches) {
#update switch status
my $csw = join(",",@config_switches);
$cmd = "chdef $csw status=ip_configed otherinterfaces=";
$cmd = "chdef $csw status=ip_configured otherinterfaces=";
$rc= xCAT::Utils->runcmd($cmd, 0);
print "$csw: IP address configured\n";
}
if (@discover_switches) {
my $dsw = join(",",@discover_switches);
@ -292,14 +294,16 @@ sub config_hostname {
$rc= xCAT::Utils->runcmd($cmd, 0);
if ($::RUNCMD_RC != 0) {
xCAT::MsgUtils->message("E","Failed to setup hostname for $switch");
print "$switch: Failed to setup hostname\n";
next;
}
print "$switch: Hostname changed to $switch\n";
push (@config_switches, $switch);
}
if (@config_switches) {
#update switch status
my $csw = join(",",@config_switches);
$cmd = "chdef $csw status=hostname_configed" ;
$cmd = "chdef $csw status=hostname_configured" ;
$rc= xCAT::Utils->runcmd($cmd, 0);
}
}
@ -485,8 +489,9 @@ sub config_snmp {
if (@config_switches) {
#update switch status
my $csw = join(",",@config_switches);
$cmd = "chdef $csw status=switch_configed snmpversion=3 snmpauth=sha snmpprivacy=authNoPriv snmpusername=$snmp_user snmppassword=$snmp_passwd";
$cmd = "chdef $csw status=switch_configured snmpversion=3 snmpauth=sha snmpprivacy=authNoPriv snmpusername=$snmp_user snmppassword=$snmp_passwd";
$rc= xCAT::Utils->runcmd($cmd, 0);
print "$csw: SNMP configured\n";
}
}
@ -567,7 +572,12 @@ sub config_vlan {
$vlan = $::VLAN;
print "Tagging VLAN=$vlan for $switches port $port\n";
#create vlan, tagged vlan
$cmd = `xdsh $switches --devicetype EthSwitch::BNT "enable;configure terminal;vlan $vlan;exit;interface port $port;switchport mode trunk;switchport trunk allowed vlan $vlan;write memory;exit;exit"`;
$cmd = "xdsh $switches --devicetype EthSwitch::BNT 'enable;configure terminal;vlan $vlan;exit;interface port $port;switchport mode trunk;switchport trunk allowed vlan $vlan;write memory;exit;exit' ";
$rc= xCAT::Utils->runcmd($cmd, 0);
if ($::RUNCMD_RC != 0) {
xCAT::MsgUtils->message("E","Failed to setup VLAN number");
print "$switches: Failed to setup VLAN\n";
}
}
@ -597,7 +607,10 @@ sub config_desc {
if ($::VERBOSE) {
print "Executing cmd: \n==> $final_cmd\n";
}
`$final_cmd`
$rc= xCAT::Utils->runcmd($final_cmd, 0);
if ($::RUNCMD_RC != 0) {
xCAT::MsgUtils->message("E","Failed to set a description on the port: $port");
}
}
#---------------------------------------------------------
@ -618,7 +631,7 @@ sub usage
configBNT --switches switchnames --snmp [--user snmp_user] [--password snmp_password] [--group snmp_group]
configBNT --switches switchnames --port port --vlan vlan
To set the ip address, hostname and config snmp:
To set the IP address, hostname and config snmp:
configBNT --switches switchnames --all
To set the description for a port on the switch:

View File

@ -150,7 +150,7 @@ sub config_ip {
# Validate if this IP is reachable
my $p = Net::Ping->new();
if (!$p->ping($dip)) {
print "$dip is not reachable, will not change ip address\n";
print "$dip is not reachable, will not change IP address\n";
#clean up discovery switch deifnition if any
my $ip_str = $dip;
$ip_str =~ s/\./\-/g;
@ -168,7 +168,7 @@ sub config_ip {
# don't need to set if ip addresses are same
if ($dip eq $static_ip) {
print "static ip $static_ip and discovery ip $dip is same, will not process command for $switch\n";
print "static IP $static_ip and discovery IP $dip is same, will not process command for $switch\n";
next;
}
@ -219,23 +219,24 @@ sub config_ip {
}
}
print "Sending xdsh command to change IP address...\n";
$cmd="xdsh $dswitch -t 10 -l admin --devicetype IBSwitch::Mellanox 'enable;configure terminal;no interface mgmt0 dhcp;interface mgmt0 ip address $static_ip $mask;configuration write;exit;exit' ";
$rc= xCAT::Utils->runcmd($cmd, 0);
if (!$p->ping($static_ip)) {
print "$switch: Failed to change ip address to $static_ip\n";
print "$switch: Failed to change IP address to $static_ip\n";
next;
}
push (@discover_switches, $dswitch);
push (@config_switches, $switch);
print "$switch: Changing IP address to static IP $static_ip\n";
print "$switch: IP address changed to $static_ip\n";
}
if (@config_switches) {
# update switch status
my $csw = join(",",@config_switches);
$cmd = "chdef $csw status=ip_configed otherinterfaces=";
$cmd = "chdef $csw status=ip_configured otherinterfaces=";
$rc= xCAT::Utils->runcmd($cmd, 0);
$cmd = "makehosts $csw";
$rc= xCAT::Utils->runcmd($cmd, 0);
@ -279,6 +280,7 @@ sub config_hostname {
$rc= xCAT::Utils->runcmd($cmd, 0);
if ($::RUNCMD_RC != 0) {
xCAT::MsgUtils->message("E","Failed to setup hostname for $switch");
print "$switch: Failed to setup hostname\n";
next;
}
push (@config_switches, $switch);
@ -287,7 +289,7 @@ sub config_hostname {
if (@config_switches) {
# update switch status
my $csw = join(",",@config_switches);
$cmd = "chdef $csw status=hostname_configed" ;
$cmd = "chdef $csw status=hostname_configured" ;
$rc= xCAT::Utils->runcmd($cmd, 0);
}
}
@ -349,8 +351,10 @@ sub config_snmp {
$cmd = $cmd . "configuration write\;exit\;";
my $final_cmd = $cmd_prefix . " \"" . $cmd . "\"";
`$final_cmd`
my $rc= xCAT::Utils->runcmd($final_cmd, 0);
if ($::RUNCMD_RC != 0) {
print "Failed to configure SNMP";
}
}
}
@ -382,7 +386,7 @@ sub run_rspconfig {
if (@config_switches) {
# update switch status
my $csw = join(",",@config_switches);
$cmd = "chdef $csw status=switch_configed" ;
$cmd = "chdef $csw status=switch_configured" ;
$rc= xCAT::Utils->runcmd($cmd, 0);
}
@ -482,7 +486,10 @@ sub config_vlan {
$cmd = $cmd . "exit\;exit\;exit\;";
my $final_cmd = $cmd_prefix . " \"" . $cmd . "\"";
`$final_cmd`
my $rc= xCAT::Utils->runcmd($final_cmd, 0);
if ($::RUNCMD_RC != 0) {
print "Failed to config VLAN";
}
}
}
}
@ -505,7 +512,7 @@ sub usage
configMellanox --switches switchnames --name
configMellanox --switches switchnames --snmp
To set the ip address, hostname, config snmp and run rspconfig command:
To set the IP address, hostname, config snmp and run rspconfig command:
configMellanox --switches switchnames --all
To run rspconfig command:

View File

@ -158,7 +158,7 @@ sub config_ssh {
my ($exp, $errstr) = cumulus_connect($ssh_ip, $userid, $password, $timeout);
if (!defined $exp) {
print ("connect failed $errstr\n");
print ("Failed to connect to $ssh_ip, $errstr\n");
next;
}
@ -198,6 +198,7 @@ sub config_ssh {
$rc= xCAT::Utils->runcmd($cmd, 0);
if ($::RUNCMD_RC != 0) {
xCAT::MsgUtils->message("E","Failed to run updatenode, please check the switch");
print "Failed to run $cmd\n";
}
$cmd = "chdef $csw status=configured";
$rc= xCAT::Utils->runcmd($cmd, 0);
@ -283,6 +284,7 @@ sub install_license {
$rc= xCAT::Utils->runcmd($cmd, 0);
if ($::RUNCMD_RC != 0) {
xCAT::MsgUtils->message("E","Failed to xscp $license_file to $switch");
print "$switch: Failed to run $cmd\n";
next;
}
@ -290,6 +292,7 @@ sub install_license {
$rc= xCAT::Utils->runcmd($cmd, 0);
if ($::RUNCMD_RC != 0) {
xCAT::MsgUtils->message("E","Failed to $cmd to $switch");
print "$switch: Failed to run $cmd\n";
next;
}
#restart switchd and reload interface
@ -317,6 +320,7 @@ sub config_snmp {
$rc= xCAT::Utils->runcmd($cmd, 0);
if ($::RUNCMD_RC != 0) {
xCAT::MsgUtils->message("E","xdsh command to $switch failed");
print "$switch: Failed to run $cmd\n";
next;
}
@ -346,9 +350,10 @@ sub config_snmp {
$rc= xCAT::Utils->runcmd($dshcmd, 0);
if ($::RUNCMD_RC != 0) {
xCAT::MsgUtils->message("E","Failed to update snmpd.conf for $switch");
print "$switch: Failed to update snmpd.conf\n";
next;
}
print "Add username=$username, password=$password, privacy=$privacy, auth=$auth to snmp service for $switch \n";
print "$switch: snmp service is configured\n";
}
}
@ -400,12 +405,13 @@ sub config_ntp {
$rc= xCAT::Utils->runcmd($cmd, 0);
if ($::RUNCMD_RC != 0) {
xCAT::MsgUtils->message("E","xdsh command to $switch failed");
print "$switch: Failed to run $cmd\n";
next;
}
$cmd = "xdsh $switch 'echo $timezone >/etc/timezone;dpkg-reconfigure --frontend noninteractive tzdata' ";
$rc= xCAT::Utils->runcmd($cmd, 0);
if ($::RUNCMD_RC != 0) {
print "Failed to update ntp timezone\n";
print "$switch: Failed to update ntp timezone\n";
xCAT::MsgUtils->message("E","Failed to update ntp timezone for $switch");
}
#use ntpserver from network table if available
@ -433,6 +439,7 @@ sub config_ntp {
$rc= xCAT::Utils->runcmd($cmd, 0);
if ($::RUNCMD_RC != 0) {
xCAT::MsgUtils->message("E","Failed to update ntp for $switch");
print "$switch: Failed to configure ntp service\n";
next;
}
push (@config_switches, $switch);
@ -445,7 +452,7 @@ sub config_ntp {
my $csw = join(",",@config_switches);
$cmd = "chdef $csw status=ntp_configured";
$rc= xCAT::Utils->runcmd($cmd, 0);
print "$csw: ntp configured\n";
print "$csw: NTP service is configured\n";
}