FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
sysmap/python/sysmap/graph.py at master · blastmaster/sysmap · GitHub
blastmaster
/
sysmap
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
1
Code
Issues
9
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
sysmap
/
python
/
sysmap
/
graph.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
103 lines (81 loc) · 2.99 KB
Breadcrumbs
sysmap
/
python
/
sysmap
/
graph.py
Copy path
File metadata and controls
103 lines (81 loc) · 2.99 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
98
99
100
101
102
103
from
graphviz
import
Digraph
from
collections
import
namedtuple
class
NetworkGraph
:
''' Representation of the network connections.
This class contains the entities in the network e.g. hosts or switches.
And the connections between them.
'''
Vertex
=
namedtuple
(
'Vertexes'
, [
'hosts'
,
'switches'
])
_edges
=
[]
def
_sanitize_edge_connection
(
self
,
edge
):
''' Update '_to' and '_form' field of a edge.
:param edge: One edge connection.
:type edge: dict
:returns: Updated edge with _to and _from key.
:rtype: dict
'''
if
edge
[
'to_guid'
].
startswith
(
'S'
):
to_collection
=
'switches/'
elif
edge
[
'to_guid'
].
startswith
(
'H'
):
to_collection
=
'hosts/'
if
edge
[
'from_guid'
].
startswith
(
'S'
):
from_collection
=
'switches/'
elif
edge
[
'from_guid'
].
startswith
(
'H'
):
from_collection
=
'hosts/'
edge
.
update
({
'_to'
:
to_collection
+
edge
[
'to_guid'
],
'_from'
:
from_collection
+
edge
[
'from_guid'
]
})
return
edge
def
_sanitize_vertexes
(
self
,
vertex
):
''' Update '_key' field of vertex to appropriate guid.
:param vertex: Vertex
:type vertex: dict
:returns: An updated dict, '_key' field with 'guid' value.
:rtype: dict
'''
vertex
.
update
({
'_key'
:
vertex
[
'guid'
]})
return
vertex
def
__init__
(
self
,
hsts
=
None
,
switches
=
None
,
connections
=
None
):
self
.
_vertexes
=
self
.
Vertex
(
hosts
=
[
self
.
_sanitize_vertexes
(
h
)
for
h
in
hsts
],
switches
=
[
self
.
_sanitize_vertexes
(
s
)
for
s
in
switches
])
self
.
_edges
=
[
self
.
_sanitize_edge_connection
(
c
)
for
c
in
connections
]
@
property
def
vertexes
(
self
):
''' Returns a concatenated list of all vertexes.
:returns: List of vertexes, contains of hosts and switches.
:rtype: List[dict]
'''
return
self
.
_vertexes
.
hosts
+
self
.
_vertexes
.
switches
@
property
def
switches
(
self
):
''' Returns a list of all 'switch' vertexes.
:returns: List of all switches.
:rtype: List[dict]
'''
return
self
.
_vertexes
.
switches
@
property
def
hosts
(
self
):
''' Returns a list of all 'host' vertexes.
:returns: List of all hosts.
:rtype: List[dict]
'''
return
self
.
_vertexes
.
hosts
@
property
def
edges
(
self
):
''' Return a list of all 'connection' edges.
:returns: List of all connections.
:rtype: List[dict]
'''
return
self
.
_edges
def
to_graph
(
self
,
graphargs
):
''' Draw a dot graph of the network graph.
:params graphargs: Arguments to graphviz.Digraph.
:type graphargs: dict
'''
graph
=
Digraph
(
**
graphargs
)
for
v
in
self
.
_vertexes
:
graph
.
node
(
v
[
'guid'
],
v
[
'description'
])
for
c
in
self
.
_edges
:
graph
.
edge
(
c
[
'from_guid'
],
c
[
'to_guid'
])
graph
.
render
()
Back
|
FazBrowse Home
|
New Git URL