-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPython1_Ex3_ans_key.txt
executable file
·97 lines (78 loc) · 2.56 KB
/
Python1_Ex3_ans_key.txt
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
Skills: Using prettytable function - printing lists and Dictionary items
Write a python script to print output as below using loops:
*** MY REPORT: Catalyst Center managed devices ***
+------+--------------+---------------+----------------------+
| Name | Platform | Management IP | SW/FW version |
+------+--------------+---------------+----------------------+
| rtr1 | C8200L-1N-4T | 10.10.20.174 | 17.9.20220318:182713 |
| sw1 | C9KV-UADP-8P | 10.10.20.175 | 17.9.20220318:182713 |
| sw2 | C9KV-UADP-8P | 10.10.20.176 | 17.9.20220318:182713 |
+------+--------------+---------------+----------------------+
Given:
report_name = "Catalyst Center managed devices"
column_titles = ["Name", "Platform", "Management IP", "SW/FW version"]
network_devices = [
{
"hostname": "rtr1", "family":"Routers",
"platform": "C8200L-1N-4T",
"mgmt_ip": "10.10.20.174",
"version": "17.9.20220318:182713"
},
{
"hostname": "sw1",
"family":"Switches and Hubs",
"platform": "C9KV-UADP-8P",
"mgmt_ip": "10.10.20.175",
"version": "17.9.20220318:182713"
},
{
"hostname": "sw2",
"family":"Switches and Hubs",
"platform": "C9KV-UADP-8P",
"mgmt_ip": "10.10.20.176",
"version": "17.9.20220318:182713"
}
]
python -m venv report_venv
source report_venv/bin/activate
pip install prettytable
############################
from prettytable import prettytable
def print_report(report_name, devices):
table = PrettyTable()
table.field_names = ["Name", "Platform", "Management IP", "SW/FW version"]
for device in devices:
table.add_row(
[device["hostname"],
device["platform"],
device["mgmt_ip"],
device["version"]]
)
print(f"\n*** MY REPORT: {report_name} ***\n")
print(table)
if __name__ == "__main__":
report_name = "Catalyst Center managed devices"
network_devices = [
{
"hostname": "rtr1",
"family":"Routers",
"platform": "C8200L-1N-4T",
"mgmt_ip": "10.10.20.174",
"version": "17.9.20220318:182713"
},
{
"hostname": "sw1",
"family":"Switches and Hubs",
"platform": "C9KV-UADP-8P",
"mgmt_ip": "10.10.20.175",
"version": "17.9.20220318:182713"
},
{
"hostname": "sw2",
"family":"Switches and Hubs",
"platform": "C9KV-UADP-8P",
"mgmt_ip": "10.10.20.176",
"version": "17.9.20220318:182713"
}
]
print_report(report_name, network_devices)