-
Notifications
You must be signed in to change notification settings - Fork 1
/
HTMLoutput.py
executable file
·74 lines (67 loc) · 3.17 KB
/
HTMLoutput.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
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
"""
Python Project (Cisco Incubator 2018)
Constributors:
- Boriychuk Dima
- Gain Gaulthier
Libs used:
- https://docs.python.org/2/library/webbrowser.html
- https://docs.python.org/2/library/os.html
"""
import webbrowser
import os
class HTML:
# Need list of devises ID and list with serial numbers-Eol
def __init__ (self, dev, EoL):
self.dev = dev
self.EoL = EoL
"""
Method allowing to create HTML file with router's data
"""
def createHTML(self):
web = open ('results.html','w')
text = ' <!DOCTYPE html><html><head>'
text +='<style>#customers { font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;'
text +=' border-collapse: collapse;'
text +=' width: 100%;}'
text +='#customers td, #customers th {'
text +=' border: 1px solid #ddd;'
text +=' padding: 8px;}'
text +='#customers tr:nth-child(even){background-color: #f2f2f2;}'
text +='#customers tr:hover {background-color: #ddd;}'
text +='#customers th {'
text +=' padding-top: 12px;'
text +=' padding-bottom: 12px;'
text +=' text-align: left;'
text +=' background-color: #4CAF50;'
text +=' color: white;}</style>'
text += '<meta charset="UTF-8"><title>Network details</title></head><body>'
web.write(text)
for device in self.dev:
text = '<h3> Router - host: ' + device['Host'] + '</h3> <table id="customers">'
text += '<tr><td> IP </td> <td>' + device['Host'] + '</td></tr>'
text += '<tr><td> Password </td> <td>' + device['Password'] + '</td></tr>'
text += '<tr><td> Hardware version </td> <td>' + device['Hardware version'] + '</td></tr>'
text += '<tr><td> OS version </td> <td>' + device['IOS version'] + '</td></tr>'
text += '<tr><td> Serial numbers </td> <td>' + device['SN'] + '</td></tr></tr>'
text += '</table></body></html>'
text += '<p> Modules </p><table id="customers">'
for slot, value in device['Modules'].items():
text += '<tr><td>' + slot + '</td><td>' + value + '</td></tr>'
text += '</table><br>'
text += '<p> Interfaces </p><table id="customers">'
for interface, info in device['Interfaces'].items():
text += '<tr><th>' + interface + '</th><th>Status</th><th>Protocol</th><th>Description</th>'
text += '<tr><td></td><td>'+ info['Status'] + '</td><td>' + info['Protocol'] + '</td><td>' + info['Description'] +'</td></tr>'
text += '</table><br>'
web.write(text)
text += '<h3> Last date of support for devises</h3>'
text += '<table id="customers"><tr><th>Serial number</th><th>End of life date</th><tr>'
for SN, date in self.EoL.items():
text += '<tr><td>'+SN+'</td><td>'+date+'</td><tr>'
text += '</table>'
web.write(text)
web.close()
# Write HTLM code in a local file
dir_path = os.path.dirname(os.path.realpath(__file__))
filename = 'file://' + dir_path + '/results.html'
webbrowser.open_new_tab(filename)