Skip to content

Commit 218330d

Browse files
committed
add readme, fix lint, update pkgs
1 parent d2a1f74 commit 218330d

File tree

6 files changed

+79
-37
lines changed

6 files changed

+79
-37
lines changed

docs/clab2drawio.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,22 @@ The easiest way to create perfect layouts is using the VS Code Containerlab exte
141141
clab2drawio -i <path_to_your_yaml_file> -g --theme grafana --grafana-config <path_to_your_cfg_file>
142142
```
143143

144+
- `--grafana-interface-format`: Maps interface names for Grafana export using regex patterns. This allows you to transform interface names to match your monitoring system's naming conventions.
145+
146+
```bash
147+
clab2drawio -i <path_to_your_yaml_file> -g --grafana-interface-format "e1-{x}:ethernet1/{x}"
148+
```
149+
150+
This would convert interface names like `e1-1` to `ethernet1/1` in the Grafana dashboard.
151+
152+
- `--grafana-interface-selector`: Selects which part of the interface name to display as the port label using regex patterns with capture groups.
153+
154+
```bash
155+
clab2drawio -i <path_to_your_yaml_file> -g --grafana-interface-selector "e1-1-c{x}-1"
156+
```
157+
158+
This would extract and display only the captured digit (e.g., from `e1-1-c3-1` it would display `3` as the port label).
159+
144160
For more detailed information about this feature, including compatibility, usage guidelines, and future enhancements, please see the [Grafana Dashboard Documentation](./grafana.md).
145161
146162
- `--include-unlinked-nodes`: Include nodes without any links in the topology diagram. By default, only nodes with at least one connection are included.

docs/grafana.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,32 @@ clab2drawio -i <path_to_yaml> -g --theme grafana --grafana-config <path_to_confi
5858
> [!TIP]
5959
> Customize targets, thresholds, or labels in your YAML to align with your network's metrics and visualization needs.
6060
61+
#### Interface Name Mapping
62+
63+
The `--grafana-interface-format` option allows you to transform interface names to match your monitoring system's naming conventions. This is useful when your containerlab topology uses different interface naming than your telemetry system.
64+
65+
Example:
66+
```bash
67+
clab2drawio -i topo.yml -g --grafana-interface-format "e1-{x}:ethernet1/{x}"
68+
```
69+
70+
This would map interface names like:
71+
- `e1-1``ethernet1/1`
72+
- `e1-48``ethernet1/48`
73+
74+
#### Interface Label Selection
75+
76+
The `--grafana-interface-selector` option lets you control which part of complex interface names appears as port labels in the diagram. This is useful for cleaner visualization when interface names contain multiple segments.
77+
78+
Example:
79+
```bash
80+
clab2drawio -i topo.yml -g --grafana-interface-selector "e1-1-c{x}-1"
81+
```
82+
83+
This would extract and display only the captured digit from interface names like:
84+
- `e1-1-c3-1` → displays `3` as the port label
85+
- `e1-1-c10-1` → displays `10` as the port label
86+
6187
#### To export the diagram as an SVG:
6288
To get a full guide: [https://github.com/andymchugh/andrewbmchugh-flow-panel/blob/main/src/README.md#using-drawio-to-create-your-svg](https://github.com/andymchugh/andrewbmchugh-flow-panel/blob/main/src/README.md#using-drawio-to-create-your-svg)
6389

pyproject.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "clab-io-draw"
3-
version = "0.6.2"
3+
version = "0.6.3"
44
description = "Convert between draw.io and containerlab topology files"
55
readme = "README.md"
66
requires-python = ">=3.11"
@@ -10,12 +10,12 @@ dependencies = [
1010
"PyYAML==6.0.2",
1111
"six==1.17.0",
1212
"wcwidth==0.2.13",
13-
"ruamel-yaml==0.18.14",
13+
"ruamel-yaml==0.18.15",
1414
"textual-dev==1.7.0",
1515
"textual==5.3.0",
1616
"networkx>=3.5.0",
1717
"defusedxml>=0.7.1",
18-
"typer>=0.16.0",
18+
"typer>=0.16.1",
1919
"pytest>=8.4.1",
2020
]
2121

@@ -75,5 +75,5 @@ docstring-code-line-length = "dynamic"
7575
[dependency-groups]
7676
dev = [
7777
"pre-commit>=4.2.0",
78-
"ruff>=0.11.13",
78+
"ruff>=0.12.10",
7979
]

src/clab_io_draw/clab2drawio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def main(
270270

271271
if grafana:
272272
styles["ports"] = True
273-
273+
274274
if grafana_interface_selector:
275275
styles["grafana_interface_selector"] = grafana_interface_selector
276276

src/clab_io_draw/core/diagram/diagram_builder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ def get_intf_digit(self, intf_name, styles):
1515
interface_selector = styles.get("grafana_interface_selector")
1616
if interface_selector:
1717
regex_pattern = interface_selector.replace("{x}", r"(\d+)")
18-
18+
1919
try:
2020
match = re.match(f"^{regex_pattern}$", intf_name)
2121
if match:
2222
return match.group(1)
2323
except re.error as e:
2424
logger.warning(f"Invalid pattern for grafana_interface_selector: {e}")
2525

26-
# fallback to default
26+
# fallback to default
2727
digits = re.findall(r"\d+", intf_name)
2828
return digits[-1] if digits else "0"
2929

0 commit comments

Comments
 (0)