added explicit tag in switches.sshusername to indicate that the username is for telnet. This will improve the performance for xdsh to switches

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@14563 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
linggao 2012-12-05 20:39:43 +00:00
parent db34a2548f
commit 933b5e0983
4 changed files with 46 additions and 28 deletions

View File

@ -603,8 +603,8 @@ noderes => {
privacy => 'The privacy protocol to use for v3. DES is assumed if v3 enabled, as it is the most readily available.',
auth => 'The authentication protocol to use for SNMPv3. SHA is assumed if v3 enabled and this is unspecified',
linkports => 'The ports that connect to other switches. Currently, this column is only used by vlan configuration. The format is: "port_number:switch,port_number:switch...". Please refer to the switch table for details on how to specify the port numbers.',
sshusername => 'The user name for ssh. For Ethernet switches, it can be user name for telnet if ssh is not set up.',
sshpassword => 'The password for ssh. For Ethernet switches, it can be password for telnet if ssh is not set up.',
sshusername => 'The user name for ssh. For Ethernet switches, it can be telnet username, use the format "tn:username" to indicate that it is for telnet.',
sshpassword => 'The password for ssh. For Ethernet switches, it can be password for telnet.',
switchtype => 'The type of switch. It is used to identify the file name that implements the functions for this swithc. The valid values are: MellanoxIB etc.',
},
},

View File

@ -209,14 +209,14 @@ of relevant device configuration file. The devicetype value must
correspond to a valid device configuration file.
xCAT ships some default configuration files
for Ethernet switches and and IB switches under
/opt/xcat/share/xcat/devicetype directory. If you want to overwrite
any of the configuration files, please copy it to /var/opt/xcat/
I</opt/xcat/share/xcat/devicetype> directory. If you want to overwrite
any of the configuration files, please copy it to I</var/opt/xcat/>
directory and cutomize it.
For example, <base>/IBSwitch/Qlogic/config is the configuration
For example, I<base/IBSwitch/Qlogic/config> is the configuration
file location if devicetype is specified as IBSwitch::Qlogic.
xCAT will first search config file using /var/opt/xcat/ as the base.
xCAT will first search config file using I</var/opt/xcat/> as the base.
If not found, it will search for it using
/opt/xcat/share/xcat/devicetype/ as the base.
I</opt/xcat/share/xcat/devicetype/> as the base.
=item B<-f>|B<--fanout> I<fanout_value>
@ -552,7 +552,7 @@ To define a BNT Ethernet switch as a node and run a command to create a new vlan
B<chdef> I<myswitch groups=all>
B<tabch> I<switch=myswitch switches.sshusername=admin switches.sshpassword=passw0rd>
where <admin> and <passw0rd> can be SSH or Telnet user name and password for the switch.
where I<admin> and I<passw0rd> are the SSH user name and password for the switch. If it is for Telnet, add I<tn:> in front of the user name: I<tn:admin>.
<xdsh> I<myswitch --devicetype EthSwitch::BNT 'enable;configure terminal;vlan 3;end;show vlan'>

View File

@ -27,6 +27,7 @@ use xCAT::MsgUtils;
#####################################################
sub remote_shell_command {
my ( $class, $config, $exec_path ) = @_;
#print Dumper($config);
my @command = ();
@ -42,8 +43,19 @@ sub remote_shell_command {
push @command, "-v";
}
if ($$config{'user'} && ($$config{'user'} !~ /^none$/i)) {
@tmp=split(' ', "-l $$config{'user'}");
push @command, @tmp;
my $username=$$config{'user'};
my $telnet=0;
if ($username =~ /^(tn:)(.*)$/) {
$telnet=1;
$username=$2;
}
if ($telnet) {
push @command, "-t";
}
if ($username) {
@tmp=split(' ', "-l $username");
push @command, @tmp;
}
}
if ($$config{'password'} && ($$config{'password'} !~ /^none$/i)) {
@tmp=split(' ', "-p $$config{'password'}");
@ -77,29 +89,33 @@ sub run_remote_shell_api {
my $node=shift;
my $user=shift;
my $passwd=shift;
my $telnet=shift;
my $verbose=shift;
my $args = join(" ", @_);
my $t;
my $prompt='.*[\>\#\$]\s*$';
my $more_prompt='(.*key to continue.*|.*--More--\s*|.*--\(more.*\)--.*$)';
my $output;
my $errmsg;
eval {
$output="start SSH session...\n";
$t = new xCAT::SSHInteract(
-username=>$user,
-password=>$passwd,
-host=>$node,
-nokeycheck=>1,
-output_record_separator=>"\r",
Timeout=>10,
Errmode=>'return',
Prompt=>"/$prompt/",
);
};
my $errmsg=$@;
$errmsg =~ s/ at (.*) line (\d)+//g;
$output.="$errmsg\n";
if (!$telnet) {
eval {
$output="start SSH session...\n";
$t = new xCAT::SSHInteract(
-username=>$user,
-password=>$passwd,
-host=>$node,
-nokeycheck=>1,
-output_record_separator=>"\r",
Timeout=>10,
Errmode=>'return',
Prompt=>"/$prompt/",
);
};
$errmsg=$@;
$errmsg =~ s/ at (.*) line (\d)+//g;
$output.="$errmsg\n";
}
my $rc=1;
if ($t) {

View File

@ -15,22 +15,24 @@ Getopt::Long::Configure("no_pass_through");
my $username;
my $passwd;
my $telnet;
my $help;
my $verbose;
if (!GetOptions(
'l|loginname=s' => \$username,
'p|password=s' => \$passwd,
't|telnet' => \$telnet, #use telnet, otherwise ssh
'h|help' => \$help,
'v|verbose'=> \$verbose,
) || $help || scalar(@ARGV)<2 ) {
print "Usage: rshell_api [-v] [-l <user>] [-p <passwrd>] <node> <command>\n";
print "Usage: rshell_api [-v] [-t] [-l <user>] [-p <passwrd>] <node> <command>\n";
exit;
}
my $node = $ARGV[0];
my $output =xCAT::RShellAPI::run_remote_shell_api($node, $username, $passwd, $verbose, @ARGV[1 .. $#ARGV]);
my $output =xCAT::RShellAPI::run_remote_shell_api($node, $username, $passwd, $telnet, $verbose, @ARGV[1 .. $#ARGV]);
my $rc=0;
my $data;
if ($output && (@$output > 1)) {