text
stringlengths
0
93.6k
node.name,
remote_host,
key="{}-{}".format(remote_port, port),
headport=remote_port,
tailport=port)
else:
G.add_edge(node.name, remote_host,
key="{}-{}".format(remote_port, port))
edge = G.get_edge(
node.name, remote_host, key="{}-{}".format(
remote_port, port))
if topology[remote_host]['node_type'] == 'hca':
edge.attr['color'] = HCA_Edge_Color
if useClusters:
if Subgraph_For_Current_Switch is None:
Subgraph_For_Current_Switch = G.subgraph(
remote_host, 'cluster{}'.format(
global_cluster_id))
Subgraph_For_Current_Switch.graph_attr[
'fillcolor'] = Cluster_Color
Subgraph_For_Current_Switch.graph_attr[
'style'] = 'filled'
global_cluster_id = global_cluster_id + 1
else:
Subgraph_For_Current_Switch.add_node(
remote_host)
else:
# Else the node connects two switches.
edge.attr['color'] = Switch_Edge_Color
if exportGexf:
gephi_edge_id += 1
edge_node = et.SubElement(
edges_node, 'edge',
attrib={'id': str(gephi_edge_id),
'source': node.name,
'target': remote_host,
'label': "{} -- {}".format(
node.name, remote_host)})
r, g, b = hex_to_rgb(edge.attr['color'])
et.SubElement(
edge_node, 'viz:color', attrib={
'r': str(r), 'g': str(g), 'b': str(b)})
node.attr['label'] = label
# print(G.string())
LOG.info(("Total number of nodes: %d\n"
"Total number of Switches: %d\n"
"Total number of HCAs: %d\n"
"Total number of Edges: %d"),
num_of_hcas + num_of_switches,
num_of_switches,
num_of_hcas,
len(G.edges()))
output_filename = os.path.basename(topology_file)
dot_filename = "{}.dot".format(output_filename)
G.write(dot_filename)
LOG.info(
"The dot file has been saved in the file '%s'.", dot_filename)
if options.render_file:
# twopi, gvcolor, wc, ccomps, tred, sccmap, fdp, circo, neato, acyclic,
# nop, gvpr, dot, sfdp
drawing_args = ''
G.layout(prog='neato', args=drawing_args)
# 'canon', 'cmap', 'cmapx', 'cmapx_np', 'dia', 'dot',
# 'fig', 'gd', 'gd2', 'gif', 'hpgl', 'imap', 'imap_np',
# 'ismap', 'jpe', 'jpeg', 'jpg', 'mif', 'mp', 'pcl', 'pdf',
# 'pic', 'plain', 'plain-ext', 'png', 'ps', 'ps2', 'svg',
# 'svgz', 'vml', 'vmlz', 'vrml', 'vtx', 'wbmp', 'xdot', 'xlib'
render_filename = "{}.pdf".format(output_filename)
G.draw(render_filename)
LOG.info("The rendered file has been saved in the file '%s'.",
render_filename)
# Use command line to debug long executing drawings:
# dot -Tpdf -Gnslimit=1000 k-18-n-3.topology.dot -v -O
if exportGexf:
gexf_filename = "{}.gexf".format(output_filename)
xml_ugly = et.tostring(root_node, encoding='UTF-8', method='xml')
xml = md.parseString(xml_ugly)
with open(gexf_filename, 'wb') as f:
f.write(xml.toprettyxml(indent=" ", newl="\n", encoding='UTF-8'))
LOG.info(
"The gexf file has been saved in the file '%s'.", gexf_filename)
LOG.info(("\nIf you want to generate a beautiful graph with Gephi,"
" follow the following steps:\n"
" 1. Load the file '%s' in Gephi.\n"
" 2. Go to the 'Overview' tab and choose a placement layout"
" (I like the results of 'ForceAtlas 2' algorithm).\n"
" 3. Tune as needed and run the layout until you are"
" satisfied with the placement and press stop.\n"
" 4. Go to the 'Preview' tab and press the 'Refresh'"