-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathport_info
59 lines (49 loc) · 1.73 KB
/
port_info
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import sys
import paramiko
import re
from getpass import getpass
#open csv and gather creds
csv = open('opengear.csv', 'w')
un = raw_input('>please type your username: ')
pw = getpass('>please type your password: ')
lh_un = raw_input('>please type the username for Lighthouse: ')
lh_pw = getpass('>please type the password for Lighthouse: ')
#collect OGs from Lighthouse
print "Attempting to gather OpenGear TS' via Lighthouse"
lighthouse_host = raw_input('>What would you like to use for lighthouse: ')
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.WarningPolicy())
ssh.connect(lighthouse_host, username=lh_un, password=lh_pw)
stdin, stdout, stderr = ssh.exec_command("node-info")
stdin.flush()
output = stdout.readlines()
ssh.close()
#create list of OGs
og_list = []
for item in output:
if len(re.findall('Name = (.*)', item)) != 0:
og_list.append(re.findall('Name = (.*)', item)[0] + '.net.tfayd.com')
#loop through opengears and connct
for og in og_list:
port_label = []
curr_og = og.split('.')[0]
try:
#prepare ssh sessions
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(og, username=un, password=pw)
stdin, stdout, stderr = ssh.exec_command('config -g config.ports | grep label')
#loop through config data and extract port/label
for line in stdout.readlines():
data = re.findall('config.ports.port([0-9]+).label\s+(\S+)', line.strip())
port_label.append(data.pop())
ssh.close()
#write data to file
for port,device in port_label:
csv.write(str(port) + ',')
csv.write(str(device + ','))
csv.write(curr_og + '\n')
except Exception:
print "Could not log into " + curr_og
csv.close()
print "script has completed"