Skip to content

Commit

Permalink
Merge pull request #24 from srl-labs/fix_node_order
Browse files Browse the repository at this point in the history
Fix node order
  • Loading branch information
FloSch62 authored Jan 8, 2025
2 parents dfd5272 + 8c33c66 commit 8cedbb2
Show file tree
Hide file tree
Showing 18 changed files with 658 additions and 364 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
venv/*
__pycache__
test/*
launch.json
launch.json
lab-examples/*
!lab-examples/*.yml
!lab-examples/*.yaml
lab-examples/*flow_panel.yaml
28 changes: 17 additions & 11 deletions clab2drawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@

logger = logging.getLogger(__name__)


def main(
input_file: str,
output_file: str,
grafana: bool,
theme: str,
include_unlinked_nodes: bool=False,
no_links: bool=False,
layout: str="vertical",
verbose: bool=False,
interactive: bool=False,
grafana_config_path: str=None,
include_unlinked_nodes: bool = False,
no_links: bool = False,
layout: str = "vertical",
verbose: bool = False,
interactive: bool = False,
grafana_config_path: str = None,
) -> None:
"""
Main function to generate a topology diagram from a containerlab YAML or draw.io XML file.
Expand All @@ -42,7 +43,7 @@ def main(
:param layout: Layout direction ("vertical" or "horizontal").
:param verbose: Enable verbose output.
:param interactive: Run in interactive mode to define graph-levels and icons.
"""
"""
logger.debug("Starting clab2drawio main function.")
loader = TopologyLoader()
try:
Expand Down Expand Up @@ -90,7 +91,7 @@ def main(
# Use NodeLinkBuilder to build nodes and links
logger.debug("Building nodes and links...")
builder = NodeLinkBuilder(containerlab_data, styles, prefix, lab_name)
nodes, links = builder.build_nodes_and_links()
nodes, links = builder.build_nodes_and_links()

diagram.nodes = nodes

Expand Down Expand Up @@ -175,11 +176,15 @@ def main(
output_folder = os.path.dirname(grafana_output_file) or "."
diagram.grafana_dashboard_file = grafana_output_file
os.makedirs(output_folder, exist_ok=True)

grafana_dashboard = GrafanaDashboard(diagram, grafana_config_path=grafana_config_path)

grafana_dashboard = GrafanaDashboard(
diagram, grafana_config_path=grafana_config_path
)
panel_config = grafana_dashboard.create_panel_yaml()

flow_panel_output_file = os.path.splitext(grafana_output_file)[0] + ".flow_panel.yaml"
flow_panel_output_file = (
os.path.splitext(grafana_output_file)[0] + ".flow_panel.yaml"
)
with open(flow_panel_output_file, "w") as f:
f.write(panel_config)
print("Saved flow panel YAML to:", flow_panel_output_file)
Expand All @@ -204,6 +209,7 @@ def main(

print("Saved file to:", output_file)


if __name__ == "__main__":
args = parse_arguments()

Expand Down
3 changes: 2 additions & 1 deletion cli/parser_clab2drawio.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import argparse


def parse_arguments():
"""
Parse command-line arguments for clab2drawio tool.
Expand Down Expand Up @@ -32,7 +33,7 @@ def parse_arguments():
"--grafana-config",
type=str,
default=None,
help="Path to a Grafana YAML config file. If omitted, defaults are used."
help="Path to a Grafana YAML config file. If omitted, defaults are used.",
)
parser.add_argument(
"--include-unlinked-nodes",
Expand Down
17 changes: 13 additions & 4 deletions cli/parser_drawio2clab.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import argparse


def parse_arguments():
"""
Parse command-line arguments for drawio2clab tool.
Expand All @@ -9,9 +10,17 @@ def parse_arguments():
parser = argparse.ArgumentParser(
description="Convert a .drawio file to a Containerlab YAML file."
)
parser.add_argument("-i", "--input", required=True, help="The input .drawio XML file.")
parser.add_argument(
"-i", "--input", required=True, help="The input .drawio XML file."
)
parser.add_argument("-o", "--output", required=False, help="The output YAML file.")
parser.add_argument("--style", choices=["block", "flow"], default="flow", help="YAML style.")
parser.add_argument("--diagram-name", required=False, help="Name of the diagram to parse.")
parser.add_argument("--default-kind", default="nokia_srlinux", help="Default node kind.")
parser.add_argument(
"--style", choices=["block", "flow"], default="flow", help="YAML style."
)
parser.add_argument(
"--diagram-name", required=False, help="Name of the diagram to parse."
)
parser.add_argument(
"--default-kind", default="nokia_srlinux", help="Default node kind."
)
return parser.parse_args()
Loading

0 comments on commit 8cedbb2

Please sign in to comment.