PATCH_STYLE = ''
NOT_CONNECTED_STYLE = ''
- DEFAULT_FORMAT = '[ %s ] %s -- { label: "%s %s"; } [ %s ] %s'
- OS_ROUTING_FORMAT = '[ %s ] %s -- { label: "%s %s"; } [ %s ] %s'
- NAMESPACE_FORMAT = '[ %s ] %s --> { label: %s %s; } [ %s ] %'
- PATCH_FORMAT = '[ %s ] %s <==> { label: %s : %s; } [ %s ] %s'
- VETH_FORMAT = '[ %s ] %s <--> { label: %s \| %s; } [ %s ] %s'
- VLAN_DIST_FORMAT = '[ %s ] %s <--> { label: %s\(%s\); } [ %s ] %s'
+ DEFAULT_FORMAT = 0
+ OS_ROUTING_FORMAT = 1
+ NAMESPACE_FORMAT = 2
+ PATCH_FORMAT = 3
+ VETH_FORMAT = 4
+ VLAN_DIST_FORMAT = 5
+
+ DEFAULT_FORMAT_DESC = '[ %s ] %s -- { label: "%s %s"; } [ %s ] %s'
+ OS_ROUTING_FORMAT_DESC = '[ %s ] %s -- { label: "%s %s"; } [ %s ] %s'
+ NAMESPACE_FORMAT_DESC = '[ %s ] %s --> { label: %s %s; } [ %s ] %'
+ PATCH_FORMAT_DESC = '[ %s ] %s <==> { label: %s : %s; } [ %s ] %s'
+ VETH_FORMAT_DESC = '[ %s ] %s <--> { label: %s \| %s; } [ %s ] %s'
+ VLAN_DIST_FORMAT_DESC = '[ %s ] %s <--> { label: %s\(%s\); } [ %s ] %s'
HEADER_FORMAT = ""
FOOTER_FORMAT = ""
port2_label = port2_label + " vnid=" + \
linkpair.port2.metadata["vxlan_vnid"]
- formatted_lp = linkpair.format % (
+ formatted_lp = cls.get_format_desc(linkpair.format) % (
device1_label,
cls.get_device_style(linkpair.device1.device_type),
port1_label,
return footer
@classmethod
- def get_device_style(cls, type=Device.DEFAULT_TYPE):
- if type == Device.DEFAULT_TYPE:
+ def get_device_style(cls, device_type=Device.DEFAULT_TYPE):
+ if device_type == Device.DEFAULT_TYPE:
return cls.DEFAULT_STYLE
- elif type == Device.VM_TYPE:
+ elif device_type == Device.VM_TYPE:
return cls.VM_STYLE
- elif type == Device.BR_TYPE:
+ elif device_type == Device.BR_TYPE:
return cls.BR_STYLE
- elif type == Device.OS_ROUTE_TYPE:
+ elif device_type == Device.OS_ROUTE_TYPE:
return cls.OS_ROUTE_STYLE
- elif type == Device.PHYNET_TYPE:
+ elif device_type == Device.PHYNET_TYPE:
return cls.PHYNET_STYLE
- elif type == Device.NAMESPACE_TYPE:
+ elif device_type == Device.NAMESPACE_TYPE:
return cls.NAMESPACE_STYLE
- elif type == Device.NOT_CONNECTED_TYPE:
+ elif device_type == Device.NOT_CONNECTED_TYPE:
return cls.NOT_CONNECTED_STYLE
else:
return cls.DEFAULT_STYLE
devices = sorted(set(devices), key=devices.index)
return devices
+ @classmethod
+ def get_format_desc(cls, format=Device.DEFAULT_TYPE):
+ if format == cls.DEFAULT_FORMAT:
+ return cls.DEFAULT_FORMAT_DESC
+ elif format == cls.OS_ROUTING_FORMAT:
+ return cls.OS_ROUTING_FORMAT_DESC
+ elif format == cls.NAMESPACE_FORMAT:
+ return cls.NAMESPACE_FORMAT_DESC
+ elif format == cls.PATCH_FORMAT:
+ return cls.PATCH_FORMAT_DESC
+ elif format == cls.VETH_FORMAT:
+ return cls.VETH_FORMAT_DESC
+ elif format == cls.VLAN_DIST_FORMAT:
+ return cls.VLAN_DIST_FORMAT_DESC
+ else:
+ return cls.DEFAULT_FORMAT_DESC
+
@apply
def linkpairs():
def get(self):
PATCH_STYLE = '{ fill: #ddddff; border: dotted; bordercolor: black; }'
NOT_CONNECTED_STYLE = '{ fill: #ffdddd; border: dotted; bordercolor: black; }'
- DEFAULT_FORMAT = '[ %s ] %s -- { label: "%s %s"; labelcolor: #663333; } [ %s ] %s'
- OS_ROUTING_FORMAT = '[ %s ] %s -- { label: "%s %s"; labelcolor: #663333; } [ %s ] %s'
- NAMESPACE_FORMAT = '[ %s ] %s --> { label: "%s %s"; labelcolor: #663333; } [ %s ] %s'
- PATCH_FORMAT = '[ %s ] %s <==> { label: "%s : %s"; labelcolor: #333366; } [ %s ] %s'
- VETH_FORMAT = '[ %s ] %s <--> { label: "%s \| %s"; labelcolor: #336633; } [ %s ] %s'
- VLAN_DIST_FORMAT = '[ %s ] %s --> { label: "%s\(%s\)"; labelcolor: #336633; } [ %s ] %s'
+ DEFAULT_FORMAT_DESC = '[ %s ] %s -- { label: "%s %s"; labelcolor: #663333; } [ %s ] %s'
+ OS_ROUTING_FORMAT_DESC = '[ %s ] %s -- { label: "%s %s"; labelcolor: #663333; } [ %s ] %s'
+ NAMESPACE_FORMAT_DESC = '[ %s ] %s --> { label: "%s %s"; labelcolor: #663333; } [ %s ] %s'
+ PATCH_FORMAT_DESC = '[ %s ] %s <==> { label: "%s : %s"; labelcolor: #333366; } [ %s ] %s'
+ VETH_FORMAT_DESC = '[ %s ] %s <--> { label: "%s \| %s"; labelcolor: #336633; } [ %s ] %s'
+ VLAN_DIST_FORMAT_DESC = '[ %s ] %s --> { label: "%s\(%s\)"; labelcolor: #336633; } [ %s ] %s'
HEADER = ""
FOOTER = ""
PATCH_STYLE = 'fillcolor="#ddddff", peripheries=2'
NOT_CONNECTED_STYLE = 'fillcolor="#ffdddd", style="filled,dotted"'
- DEFAULT_FORMAT = '"%s" -> "%s" [ color="#000000", fontcolor="#663333", label = "%s %s" ]'
- OS_ROUTING_FORMAT = '"%s" -> "%s" [ color="#000000", fontcolor="#663333", label = "%s %s", style="dotted" ]'
- NAMESPACE_FORMAT = '"%s" -> "%s" [ color="#000000", fontcolor="#663333", label = "%s %s" ]'
- PATCH_FORMAT = '"%s" -> "%s" [ dir=both, arrowhead=box, arrowtail=box, color="#000000:#000000", fontcolor="#333366", label = "%s : %s" ]'
- VETH_FORMAT = '"%s" -> "%s" [ dir=both, arrowhead=obox, arrowtail=obox, color="#000000", fontcolor="#336633", label="%s \| %s" ]'
- VLAN_DIST_FORMAT = '"%s" -> "%s" [ dir=forward, arrowhead=crow, arrowtail=none, color="#660000", fontcolor="#336633", label="%s\(%s\)", style="dotted" ]'
+ DEFAULT_FORMAT_DESC = '"%s" -> "%s" [ color="#000000", fontcolor="#663333", label = "%s %s" ]'
+ OS_ROUTING_FORMAT_DESC = '"%s" -> "%s" [ color="#000000", fontcolor="#663333", label = "%s %s", style="dotted" ]'
+ NAMESPACE_FORMAT_DESC = '"%s" -> "%s" [ color="#000000", fontcolor="#663333", label = "%s %s" ]'
+ PATCH_FORMAT_DESC = '"%s" -> "%s" [ dir=both, arrowhead=box, arrowtail=box, color="#000000:#000000", fontcolor="#333366", label = "%s : %s" ]'
+ VETH_FORMAT_DESC = '"%s" -> "%s" [ dir=both, arrowhead=obox, arrowtail=obox, color="#000000", fontcolor="#336633", label="%s \| %s" ]'
+ VLAN_DIST_FORMAT_DESC = '"%s" -> "%s" [ dir=forward, arrowhead=crow, arrowtail=none, color="#660000", fontcolor="#336633", label="%s\(%s\)", style="dotted" ]'
# ADDNODE_STYLE = '"%s" [ fillcolor="#ffffff", style="filled,dotted" ]'
ADDNODE_STYLE = '"%s" [ %s ]'
port2_label = port2_label + " vnid=" + \
linkpair.port2.metadata["vxlan_vnid"]
- formatted_lp = linkpair.format % (
+ formatted_lp = cls.get_format_desc(linkpair.format) % (
device1_label,
device2_label,
port1_label,
PATCH_STYLE = "color: '#DDDDFF', directional: true"
NOT_CONNECTED_STYLE = "color: '#FFDDDD', directional: true"
- DEFAULT_FORMAT = "['%s', '%s', {%s, label: '%s %s'}]"
- OS_ROUTING_FORMAT = "['%s', '%s', {%s, label: '%s %s'}]"
- NAMESPACE_FORMAT = "['%s', '%s', {%s, label: '%s %s'}]"
- PATCH_FORMAT = "['%s', '%s', {%s, label: '%s : %s'}]"
- VETH_FORMAT = "['%s', '%s', {%s, label: '%s \| %s'}]"
- VLAN_DIST_FORMAT = "['%s', '%s', {%s, label: '%s\(%s\)'}]"
+ DEFAULT_FORMAT_DESC = "['%s', '%s', {%s, label: '%s %s'}]"
+ OS_ROUTING_FORMAT_DESC = "['%s', '%s', {%s, label: '%s %s'}]"
+ NAMESPACE_FORMAT_DESC = "['%s', '%s', {%s, label: '%s %s'}]"
+ PATCH_FORMAT_DESC = "['%s', '%s', {%s, label: '%s : %s'}]"
+ VETH_FORMAT_DESC = "['%s', '%s', {%s, label: '%s \| %s'}]"
+ VLAN_DIST_FORMAT_DESC = "['%s', '%s', {%s, label: '%s\(%s\)'}]"
ADDNODE_STYLE = "graph.addNodes('%s');"
ADDEDGE_START = "graph.addEdges("
port2_label = port2_label + " vnid=" + \
linkpair.port2.metadata["vxlan_vnid"]
- formatted_lp = linkpair.format % (
+ formatted_lp = cls.get_format_desc(linkpair.format) % (
device1_label,
device2_label,
cls.get_device_style(linkpair.device1.device_type),
PATCH_STYLE = "color: '#DDDDFF', directional: true"
NOT_CONNECTED_STYLE = "color: '#FFDDDD', directional: true"
- DEFAULT_FORMAT = "graph.newEdge(%s, %s, {color: '#00A0B0'});"
- OS_ROUTING_FORMAT = "graph.newEdge(%s, %s, {color: '#00A0B0'});"
- NAMESPACE_FORMAT = "graph.newEdge(%s, %s, {color: '#00A0B0'});"
- PATCH_FORMAT = "graph.newEdge(%s, %s, {color: '#00A0B0'});"
- VETH_FORMAT = "graph.newEdge(%s, %s, {color: '#00A0B0'});"
- VLAN_DIST_FORMAT = "graph.newEdge(%s, %s, {color: '#00A0B0'});"
+ DEFAULT_FORMAT_DESC = "graph.newEdge(%s, %s, {color: '#00A0B0'});"
+ OS_ROUTING_FORMAT_DESC = "graph.newEdge(%s, %s, {color: '#00A0B0'});"
+ NAMESPACE_FORMAT_DESC = "graph.newEdge(%s, %s, {color: '#00A0B0'});"
+ PATCH_FORMAT_DESC = "graph.newEdge(%s, %s, {color: '#00A0B0'});"
+ VETH_FORMAT_DESC = "graph.newEdge(%s, %s, {color: '#00A0B0'});"
+ VLAN_DIST_FORMAT_DESC = "graph.newEdge(%s, %s, {color: '#00A0B0'});"
ADDNODE_STYLE = "var %s = graph.newNode({label: '%s'});"
ADDEDGE_START = "graph.addEdges("
@classmethod
def format_linkpair(cls, linkpair):
formatted_lp = ""
- formatted_lp = linkpair.format % (
+ formatted_lp = cls.get_format_desc(linkpair.format) % (
str(linkpair.device1).replace(" ", "_").replace("-", "_"),
str(linkpair.device2).replace(" ", "_").replace("-", "_"))
return formatted_lp
return "[" + str(self.device1) + "]:" + str(self.port1) + \
" -- " + str(self.port2) + ":[" + str(self.device2) + "]"
- def _blank_format(self, format_name):
- if len(format_name) > 0:
- repr(format_name)
- else:
- return "\"\""
+ def _get_format_as_string(self, format):
+ return "\"" + str(self.format) + "\""
def get_linkpair_linkid(self):
return str(self.device1).replace(" ", "_") + "__" + \
"\"device2\":" + repr(self.device2) + "," + \
"\"port1\":" + repr(self.port1) + "," + \
"\"port2\":" + repr(self.port2) + "," + \
- "\"format\":" + self._blank_format(self.format_name) + "}"
+ "\"format\":" + self._get_format_as_string(self.format) + "}"
self.label = label
self.port_type = port_type
self.metadata = metadata
-
def __repr__(self):
return "{\"label\":\"" + self.label + \