-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.py
More file actions
58 lines (39 loc) · 2.01 KB
/
script.py
File metadata and controls
58 lines (39 loc) · 2.01 KB
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
import argparse
from utils import validate_args, get_ip_address_list, make_connection, close_connection
from tasks import make_backup, config_timezone_ntp, make_report
from parsers import parse_show_version, parse_cdp_neighbor_detail, parse_ntp_status
def main():
parser = argparse.ArgumentParser(description='DevNet Tool')
parser.add_argument('--user', type=str, required=True, help='Username')
parser.add_argument('--password', type=str, required=True, help='Password')
parser.add_argument('--network', type=str, required=True, help='Management Network')
parser.add_argument('--ntp-server', type=str, required=True, help='NTP server')
args = parser.parse_args()
validate_args(args)
output_report = ''
for address in get_ip_address_list(args.network):
print(f'connection started to {address}')
connection = make_connection(address=address, user=args.user, password=args.password)
if not connection:
continue
print('connection success')
connection.enable()
device_info = parse_show_version(connection=connection)
if bool(device_info) is False:
print('show version parse failed, skip')
continue
config = make_backup(connection=connection, hostname=device_info['Hostname'])
if not config:
print('failed to get config, skip')
continue
device_cdp_info = parse_cdp_neighbor_detail(connection=connection, hostname=device_info['Hostname'])
config_timezone_ntp(
connection=connection, hostname=device_info['Hostname'], ntp_server=args.ntp_server, config=config)
ntp_service_info = parse_ntp_status(connection=connection, hostname=device_info['Hostname'])
close_connection(connection=connection)
output_report += make_report(device_info=device_info, cdp_info=device_cdp_info, ntp_info=ntp_service_info)
if output_report:
print('----SUMMARY----\n')
print(output_report)
if __name__ == "__main__":
main()