-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkintest.py
29 lines (27 loc) · 947 Bytes
/
checkintest.py
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
import Exscript.util.file as euf
import Exscript.util.start as eus
import Exscript.util.match as eum
import pysvn
import os
import time
import datetime
hosts = euf.get_hosts_from_file('c:\\network_configs\\hosts.txt')
accounts = euf.get_accounts_from_file('c:\\network_configs\\accounts.cfg')
def dump_config(job, host, conn):
"""Connect to device, trim config file a bit, write to file"""
conn.execute('term len 0')
conn.execute('show run')
#get the actual hostname of the device
hostname = eum.first_match(conn, r'^hostname\s(.+)$')
cfg_file = 'c:\\network_configs\\' + hostname.strip() + '.cfg'
config = conn.response.splitlines()
# a little cleanup
for i in range(3):
config.pop(i)
config.pop(-0)
config.pop(-1)
# write config to file
with open(cfg_file, 'w') as f:
for line in config:
f.write(line +'\n')
eus.start(accounts, hosts, dump_config, max_threads=2)