How to create network diagram using python list of dictionaries data

Question:

I have list of dictionaries of data, using this data i would need to create the network diagrams. Could any one suggest the best technique to do using python script (or any python libraries).

#!/usr/bin/env python

list_dict=[{'name': "dev", 'veth0': 'eth0' }, {'device': 'namespace',  "veth1":'eth1'}]

print list_dict

I would like to depict the data as per the below network diagram.

enter image description here

Asked By: john 517501

||

Answers:

You can use nwdiag library to create network diagrams. Please check the link for more info.
http://blockdiag.com/en/nwdiag/index.html

Check for examples:
http://blockdiag.com/en/nwdiag/nwdiag-examples.html#simple-diagram

But the list data has to be represented as below format .

sample example:

nwdiag {
  network dmz {
      address = "210.x.x.x/24"

      // set multiple addresses (using comma)
      web01 [address = "210.x.x.1, 210.x.x.20"];
      web02 [address = "210.x.x.2"];
  }
  network internal {
      address = "172.x.x.x/24";

      web01 [address = "172.x.x.1"];
      web02 [address = "172.x.x.2"];
      db01;
      db02;
  }
}
Answered By: user1720713

Released N2G recently, it can help to produce yEd diagrams from list of dictionaries, have a look at demo and docs.

Sample code to add elements to diagram:

from N2G import yed_diagram as create_yed_diagram

sample_list_graph = [
    {'source': 'dev', 'src_label': 'veth0:eth0', 'target': 'namespace', 'trgt_label': 'veth1:eth1'}
]

yed_diagram = create_yed_diagram()
yed_diagram.from_list(sample_list_graph)
yed_diagram.layout()
yed_diagram.dump_file()

After running above code, N2G will emit output in ./Output directory. Output file can be opened in yEd graph editor desktop app (app similar to Visio), use layout->label placement->ok to automatically place labels and after editing it might look like this:
enter image description here

Answered By: apraksim

You can use NetworkX & Plotly to generate the network diagram, see examples here.

Answered By: Summer
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.