-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathplaying.py
78 lines (66 loc) · 1.93 KB
/
playing.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
75
76
77
78
""" Playing to build topo from Arista eAPI"""
from graphviz import Digraph
import json
# add code to pull dynamically from live box
topo = '''{
"jsonrpc": "2.0",
"result": [
{},
{
"tablesLastChangeTime": 1483721367.4560423,
"tablesAgeOuts": 0,
"tablesInserts": 3,
"lldpNeighbors": [
{
"ttl": 120,
"neighborDevice": "HP830_LSW",
"neighborPort": "GigabitEthernet1/0/12",
"port": "Ethernet47"
},
{
"ttl": 120,
"neighborDevice": "HP_5500EI",
"neighborPort": "GigabitEthernet2/0/22",
"port": "Ethernet48"
},
{
"ttl": 120,
"neighborDevice": "HP_5500EI",
"neighborPort": "GigabitEthernet1/0/24",
"port": "Management1"
}
],
"tablesDeletes": 0,
"tablesDrops": 0
}
],
"id": "EapiExplorer-1"
}'''
topo = json.loads(topo)
neighbors = topo['result'][1]['lldpNeighbors']
def create_topo(root, neigh_list):
nodes = [root]
edges = []
for neighbor in neigh_list:
nodes.append(neighbor['neighborDevice'])
edges.append([root, neighbor['neighborDevice'], neighbor['neighborPort'] + "-" + neighbor['port'] ])
return [nodes, edges]
my_topo = create_topo('Arista249', neighbors)
#Creating the Topo graphic
dot = Digraph(comment='My Network')
def make_topology(network_name, mytopo):
dot = Digraph(comment=network_name, format='png')
dot.graph_attr['splines']='ortho'
dot.attr('node', shape='box')
dot.attr('node',style='filled' )
dot.attr('edge', dir='both')
dot.attr('edge', arrowsize='2')
dot.body.append(r'label = "\n\nMy Prettier Network Diagram"')
dot.body.append('fontsize=20')
for i in mytopo[0]:
dot.node(i)
for i in mytopo[1]:
dot.edge(i[0], i[1], i[2])
return dot
dot = make_topology("My New Network", my_topo)
dot.render(filename='SimplePrettierTopo')