perl brocade switch问题使用Net :: OpenSSH

时间:2015-07-29 13:16:37

标签: perl

我需要有关从远程系统配置brocade switch的帮助。我有使用Net::OpenSSH

的示例代码

代码如下

#!/usr/bin/perl

use strict;
use warnings;

use List::Util qw( first );
use Net::OpenSSH;

use Log::Log4perl qw( :easy );
Log::Log4perl->easy_init( $INFO );

use Expect;
use 5.010;

my $logger = get_logger();

my $username = 'admin';
my $password = 'password';
my $ip       = '10.227.0.216';

$logger->info( "performing ssh to the swicth" );
my $ssh = Net::OpenSSH->new(
    $ip,
    user        => "$username",
    password    => "$password",
    master_opts => [-o => "StrictHostKeyChecking=no"] );

$logger->info( "listing zone on the switch $ip using zoneshow" );
my ( $out, $err ) = $ssh->capture2( "zoneshow" );
print "$out\n";
$logger->info( "zoneshow successful" );

$logger->info( "listing zone on the switch $ip using nsshow" );
( $out, $err ) = $ssh->capture2( "nsshow" );
print "$out\n";
$logger->info( "nsshow successful" );

sleep 3;

$logger->info( "create zone on the switch $ip using zonecreate" );
( $out, $err ) = $ssh->capture2( "zonecreate \"test5\", \" 20:01:00:11:0d:34:57:00\" " );
$ssh->error and die "remote find command failed: $!" . $ssh->error;
print "$out\n";
$logger->info( "zonecreate successful" );

##now add the zone to the config and save it
( $out, $err ) = $ssh->capture2( "cfgadd \"FC_DVT\", \"test5\"" );
$ssh->error and die "remote find command failed: $!" . $ssh->error;
print "$out\n";

( $out, $err ) = $ssh->capture2( { stdin_data => join( "yes", "cfgsave" ) } );
$ssh->error and die "remote find command failed: $!" . $ssh->error;
print "$out\n";

( $out, $err ) = $ssh->capture2( { stdin_data => join( "yes", "cfgenable \"FC_DVT\"" ) } );
$ssh->error and die "remote find command failed: $!" . $ssh->error;
print "$out\n";

错误见如下

[root@localhost jana]# ./switchconfig.pl
2015/07/29 23:59:57 performing ssh to the swicth
2015/07/29 23:59:58 listing zone on the switch 10.227.0.216 using zoneshow
Defined configuration:
cfg:   FC_DVT  MEZZI; MEZZI1; test1
zone:  MEZZI   mezzi1; mezzi2; sanblaze
zone:  MEZZI1  mezzi3; mezzi4; sanblaze
zone:  test1   20:00:00:11:0d:34:56:00
zone:  vikash_enfield
    10:00:00:00:c9:a1:95:aa; 10:00:00:00:c9:a1:95:ab;
    20:00:00:11:0d:34:56:00
alias: mezzi1  10:00:00:00:c9:cd:cc:6c
alias: mezzi2  10:00:00:00:c9:cd:cc:6d
alias: mezzi3  10:00:00:90:fa:2e:dd:9f
alias: mezzi4  10:00:00:90:fa:2e:dd:a0
alias: sanblaze
    20:01:00:11:0d:34:57:00

Effective configuration:
cfg:   FC_DVT
zone:  MEZZI   10:00:00:00:c9:cd:cc:6c
    10:00:00:00:c9:cd:cc:6d
    20:01:00:11:0d:34:57:00
zone:  MEZZI1  10:00:00:90:fa:2e:dd:9f
    10:00:00:90:fa:2e:dd:a0
    20:01:00:11:0d:34:57:00
zone:  test1   20:00:00:11:0d:34:56:00


2015/07/29 23:59:59 zoneshow successful
2015/07/29 23:59:59 listing zone on the switch 10.227.0.216 using nsshow
{
Type Pid    COS     PortName                NodeName                 TTL(sec)
N    010700;      3;50:0a:09:84:88:ed:66:d4;50:0a:09:80:88:ed:66:d4; na
FC4s: FCP [NETAPP  LUN             7360]
Fabric Port Name: 20:07:00:05:33:d4:06:4d
Permanent Port Name: 50:0a:09:84:88:ed:66:d4
Port Index: 7
Share Area: No
Device Shared in Other AD: No
Redirect: No
Partial: No
LSAN: No
N    010a00;      3;10:00:00:90:fa:2e:dd:9f;20:00:00:90:fa:2e:dd:9f; na
FC4s: IPFC FCP
PortSymb: [34] "Emulex PPN-10:00:00:90:fa:2e:dd:9f"
NodeSymb: [37] "Emulex 7101684 FV10.6.168.0 DV3.0.02 "
Fabric Port Name: 20:0a:00:05:33:d4:06:4d
Permanent Port Name: 10:00:00:90:fa:2e:dd:9f
Port Index: 10
Share Area: No
Device Shared in Other AD: No
Redirect: No
Partial: No
LSAN: No
N    010b00;    2,3;20:00:00:11:0d:34:56:00;20:00:00:11:0d:34:56:00; na
FC4s: FCP
PortSymb: [22] "SANBlaze FC Port Targ0"
Fabric Port Name: 20:0b:00:05:33:d4:06:4d
Permanent Port Name: 20:00:00:11:0d:34:56:00
Port Index: 11
Share Area: No
Device Shared in Other AD: No
Redirect: No
Partial: No
LSAN: No
N    010e00;    2,3;20:01:00:11:0d:34:57:00;20:01:00:11:0d:34:57:00; na
FC4s: FCP
PortSymb: [22] "SANBlaze FC Port Targ0"
Fabric Port Name: 20:0e:00:05:33:d4:06:4d
Permanent Port Name: 20:01:00:11:0d:34:57:00
Port Index: 14
Share Area: No
Device Shared in Other AD: No
Redirect: No
Partial: No
LSAN: No
The Local Name Server has 4 entries }

2015/07/30 00:00:00 nsshow successful
2015/07/30 00:00:03 create zone on the switch 10.227.0.216 using zonecreate

2015/07/30 00:00:04 zonecreate successful

remote find command failed: child exited with code 248 at ./switchconfig.pl line 45.

我需要发送 afer cfgsavecfgenable,因为交换机会使用{{1}提示saveenable配置}或yes选项 感谢

使用调试输出发布

no

1 个答案:

答案 0 :(得分:0)

问题得到了解决,不是我,而是来自perlmonks

发布答案

#!/usr/bin/perl
use strict;
use warnings;
use List::Util qw( first );
use Net::OpenSSH;
use Log::Log4perl qw(:easy);
Log::Log4perl->easy_init($INFO);
$Net::OpenSSH::debug = -1;


my $logger = get_logger();



my $username = 'admin';
my $password = 'password';
my $ip       = '10.227.0.216';


$logger->info( "performing ssh to the swicth" );
my $ssh = Net::OpenSSH->new(
    $ip,
    user        => "$username",
    password    => "$password",
    master_opts => [-o => "StrictHostKeyChecking=no"] );

$logger->info( "listing zone on the switch $ip using zoneshow" );
my ( $out, $err ) = $ssh->capture2( "zoneshow" );
print "$out\n";
$logger->info( "zoneshow successful" );

$logger->info( "listing zone on the switch $ip using nsshow" );
( $out, $err ) = $ssh->capture2( "nsshow" );
print "$out\n";
$logger->info( "nsshow successful" );

sleep 3;

$logger->info( "create zone on the switch $ip using zonecreate" );
( $out, $err ) = $ssh->capture2( "zonecreate \"test15\", \" 20:01:00:1
+1:0d:34:57:00\" " );
$ssh->error and die "remote find command failed: $!" . $ssh->error;
print "$out\n";
$logger->info( "zonecreate successful" );

##now add the zone to the config and save it
( $out, $err ) = $ssh->capture2( "cfgadd \"FC_DVT\", \"test15\"" );
$ssh->error and die "remote find command failed: $!" . $ssh->error;
print "$out\n";

( $out, $err ) = $ssh->capture2( { stdin_data =>"yes\n"}, "cfgsave"  )
+;
$ssh->error and die "remote find command failed: $!" . $ssh->error;
print "$out\n";

( $out, $err ) = $ssh->capture2( { stdin_data =>"yes\n"},"cfgenable \"
+FC_DVT\"");
$ssh->error and die "remote find command failed: $!" . $ssh->error;
print "$out\n";
[download]