r3806 reviewed with the author of the script to make it working again
[racktables] / gateways / deviceconfig / nxos4.connector
CommitLineData
48400875
DO
1#!/usr/bin/perl
2
3# a working NX-OS connector for RackTables by Dmitry Tejblum
4
5use strict;
6use File::FnMatch qw(:fnmatch);
7use Net::Telnet::Cisco;
8$#ARGV == 2 or die "usage";
9my $endpoint = shift @ARGV;
10my $command = shift @ARGV;
11my $workfile = shift @ARGV;
12
13$0 =~ m,^(.*)/[^/]+$,;
14my $mydir = $1;
15open(SECRETS, "<$mydir/switch.secrets.php") || die "switch.secrets.php: $!";
16my $skip = 1;
17my ($username, $password, $enable_password);
18while (<SECRETS>) {
19 chomp;
20 if ($skip && ($_ eq "# S-T-A-R-T")) {
21 $skip = 0;
22 next;
23 }
24 if (!$skip && ($_ eq "# S-T-O-P")) {
25 $skip = 1;
26 next;
27 }
28 next if ($skip);
29 next if m,^\s*(#.*)?$,;
30 my @f = split;
31 if (fnmatch($f[0], $endpoint)) {
32 $username = $f[4];
33 $password = $f[5];
34 $enable_password = $f[6];
35 last;
36 }
37}
38
39if (!defined($username)) {
40 exit(3);
41}
42
43my $session = Net::Telnet::Cisco->new('Host' => $endpoint,
44 Prompt => ' /(?m:^\015?\000?[\w.-]+(?:\(config[^\)]*\))?\s?[\$#>]\s?)/'
45);
46$session->login($username, $password);
47if ($enable_password ne "-") {
48 $session->enable($enable_password);
49}
db64180c 50if ($command eq "get8021q") {
48400875 51 open(WORKFILE, ">$workfile") || die "$workfile: $!";
07199a49
DO
52 $session->put ('terminal length 0');
53 $session->put ('terminal no monitor');
48400875
DO
54 my @r = $session->cmd ('show running-config vlan 1-4094');
55 print WORKFILE @r;
56 @r = $session->cmd('show running-config interface');
57 print WORKFILE @r;
58 exit(0);
59}
60if ($command eq "deploy") {
61 open(WORKFILE, "<$workfile") || die "$workfile: $!";
62 while (<WORKFILE>) {
63 $session->put($_);
64 }
65 exit(0);
66}