This commit is contained in:
2026-02-21 22:54:19 +03:00
parent 76597cc7f1
commit de13989759
7 changed files with 66 additions and 9 deletions
View File
+30
View File
@@ -0,0 +1,30 @@
import yaml
from ..domain.models import Topology
"""
Example:
links:
networks:
- A: [PC1.eth0, PC2.eth0]
meta:
id: host-host.csv
name: host-host.csv
nodes:
- role: host
name: PC1
interfaces:
- eth0:
- ip: 10.0.12.1/24
network: A
- role: host
name: PC2
interfaces:
- eth0:
- ip: 10.0.12.2/24
network: A
"""
def make_yaml(topology: Topology, output_path: str) -> None:
pass
+26
View File
@@ -0,0 +1,26 @@
from ..domain.models import Topology
import graphviz
def generate_diagram(topology: Topology, output_path: str) -> None:
dot = graphviz.Graph(name="Network Topology", format="png", engine="neato")
dot.attr(overlap="false", splines="true")
for device in topology.devices.values():
shape = "box"
dot.node(device.name, label=device.name, shape=shape)
for network in topology.networks.values():
interfaces_with_device = [
iface for iface in network.interfaces if iface.device is not None
]
for i, iface_a in enumerate(interfaces_with_device):
for iface_b in interfaces_with_device[i + 1 :]:
label = network.name or ""
dot.edge(iface_a.device.name, iface_b.device.name, label=label)
output_path = output_path[:-4] if output_path.endswith(".png") else output_path
dot.render(output_path, cleanup=True)
return