r4324 added RHEL6
[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,
89bf5458 44 Prompt => ' /(?:^|[\x0a\x0d0\0]+)[\w.-]+\s?(?:\(config[^\)]*\))?\s?[\$#>]\s?(?:\(enable\))?\s*$/',
48400875 45);
89bf5458 46$session->more_prompt('/(?:^|[\x0a\x0d\0]+)\s*(?:\x1b\S{1,3})?\s*--More--/');
48400875
DO
47$session->login($username, $password);
48if ($enable_password ne "-") {
49 $session->enable($enable_password);
50}
db64180c 51if ($command eq "get8021q") {
48400875 52 open(WORKFILE, ">$workfile") || die "$workfile: $!";
842c2004
DO
53 $session->cmd ('terminal length 0');
54 $session->cmd ('terminal no monitor');
48400875 55 my @r = $session->cmd ('show running-config vlan 1-4094');
00c51e16 56 print WORKFILE @r, "\n\n";
48400875 57 @r = $session->cmd('show running-config interface');
00c51e16 58 print WORKFILE @r, "\n\n";;
48400875
DO
59 exit(0);
60}
ffd829af
DO
61if ($command eq "getcdpstatus") {
62 open(WORKFILE, ">$workfile") || die "$workfile: $!";
63 $session->cmd ('terminal length 0');
64 $session->cmd ('terminal no monitor');
65 my @r = $session->cmd ('show cdp neighbors detail');
00c51e16 66 print WORKFILE @r, "\n\n";;
ffd829af
DO
67 exit(0);
68}
65e557dd
AA
69if ($command eq "getportstatus") {
70 open(WORKFILE, ">$workfile") || die "$workfile: $!";
71 $session->cmd ('terminal length 0');
72 $session->cmd ('terminal no monitor');
73 my @r = $session->cmd ('show int status');
74 print WORKFILE @r, "\n\n";;
75 exit(0);
76}
77if ($command eq "getmaclist") {
78 open(WORKFILE, ">$workfile") || die "$workfile: $!";
79 $session->cmd ('terminal length 0');
80 $session->cmd ('terminal no monitor');
81 my @r = $session->cmd ('show mac address-table dynamic');
82 print WORKFILE @r, "\n\n";;
83 exit(0);
84}
48400875
DO
85if ($command eq "deploy") {
86 open(WORKFILE, "<$workfile") || die "$workfile: $!";
87 while (<WORKFILE>) {
842c2004 88 $session->cmd($_);
48400875
DO
89 }
90 exit(0);
91}