Skip to content

Commit 0969ff6

Browse files
committed
initial commit
0 parents  commit 0969ff6

File tree

141 files changed

+9459
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

141 files changed

+9459
-0
lines changed

Dockerfile

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Use an official Python runtime as a parent image
2+
FROM python:3.8-slim
3+
4+
# Set the working directory in the container
5+
WORKDIR /app
6+
7+
# Copy the Python scripts and the entrypoint script into the container
8+
COPY drawio2clab.py /app/
9+
COPY clab2drawio.py /app/
10+
COPY requirements.txt /app/
11+
COPY entrypoint.sh /app/
12+
13+
# Install any needed packages specified in requirements.txt
14+
RUN pip install --no-cache-dir -r requirements.txt
15+
16+
# Make the entrypoint script executable
17+
RUN chmod +x /app/entrypoint.sh
18+
19+
# Use the entrypoint script to handle script execution
20+
ENTRYPOINT ["/app/entrypoint.sh"]
21+
# CMD can be used to specify default arguments or left as it is to pass commands through the docker run command

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 FloSch62
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# clab-io-draw
2+
3+
The `clab-io-draw` project unifies two tools, `clab2drawio` and `drawio2clab`. These tools facilitate the conversion between [Containerlab](https://github.com/srl-labs/containerlab) YAML files and Draw.io diagrams, making it easier for network engineers and architects to visualize, document, and share their network topologies.
4+
5+
![Drawio Example](img/drawio1.png)
6+
7+
## clab2drawio
8+
9+
`clab2drawio` is a Python script that automatically generates Draw.io diagrams from Containerlab YAML configurations. It aims to simplify the visualization of network designs by providing a graphical representation of container-based network topologies.
10+
11+
For detailed information on `clab2drawio`, including features, options, and usage instructions, please refer to the [clab2drawio.md](clab2drawio.md) file located in the same directory as this README.
12+
13+
## drawio2clab
14+
15+
`drawio2clab` is a Python script that converts Draw.io diagrams into Containerlab-compatible YAML files. This tool is designed to assist in the setup of container-based networking labs by parsing .drawio XML files and generating structured YAML representations of the network.
16+
17+
For more details on `drawio2clab`, including features, constraints for drawing, and how to run the tool, please see the [drawio2clab.md](drawio2clab.md) file in this directory.
18+
19+
# Quick Usage
20+
21+
## Running with Docker
22+
To simplify dependency management and execution, the tools can be run inside a Docker container. Follow these instructions to build and run the tool using Docker.
23+
24+
### Pulling from dockerhub
25+
```bash
26+
docker pull flosch62/clab-io-draw:latest
27+
```
28+
29+
### Building the Docker Image by yourself
30+
31+
Navigate to the project directory and run:
32+
33+
```bash
34+
docker build -t clab-io-draw .
35+
```
36+
This command builds the Docker image of clab-io-draw with the tag clab-io-draw, using the Dockerfile located in the docker/ directory.
37+
38+
### Running the Tools
39+
Run drawio2clab or clab2drawio within a Docker container by mounting the directory containing your .drawio/.yaml files as a volume. Specify the input and output file paths relative to the mounted volume:
40+
```bash
41+
docker run -e SCRIPT_NAME=clab2drawio.py -v "$(pwd)":/data flosch62/clab-io-draw -i /data/lab-examples/clos03/cfg-clos.clab.yml -o /data/output.drawio
42+
```
43+
```bash
44+
docker run -e SCRIPT_NAME=drawio2clab.py -v "$(pwd)":/data flosch62/clab-io-draw -i /data/output.drawio -o /data/lab-examples/clos03/cfg-clos.clab.yml
45+
```
46+
47+
Replace your_input_file.drawio and your_output_file.yaml with the names of your actual files. This command mounts your current directory to /data inside the container.
48+
49+
## Running locally
50+
51+
### Requirements
52+
- Python 3.6+
53+
54+
### Installation
55+
56+
#### Virtual Environment Setup
57+
58+
It's recommended to use a virtual environment for Python projects. This isolates your project dependencies from the global Python environment. To set up and activate a virtual environment:
59+
60+
```bash
61+
python3 -m venv venv
62+
source venv/bin/activate
63+
```
64+
#### Installing Dependencies
65+
After activating the virtual environment, install the required packages from the requirements.txt file:
66+
```bash
67+
pip install -r requirements.txt
68+
```
69+
70+
# Usage
71+
72+
This section provides a brief overview on how to use the `drawio2clab` and `clab2drawio` tools. For detailed instructions, including command-line options and examples, please refer to the dedicated usage sections in their respective documentation files.
73+
74+
Detailed Usages: [drawio2clab.md](drawio2clab.md#usage) and [clab2drawio.md](drawio2clab.md#usage)
75+
76+
## drawio2clab
77+
78+
```bash
79+
python drawio2clab.py -i <input_file.drawio> -o <output_file.yaml>
80+
```
81+
`-i, --input`: Specifies the path to your input .drawio file.
82+
`-o, --output`: Specifies the path for the output YAML file.
83+
Make sure to replace `<input_file.drawio>` with the path to your .drawio file and `<output_file.yaml>` with the desired output YAML file path.
84+
85+
For more comprehensive guidance, including additional command-line options, please see the Usage section in [drawio2clab.md](drawio2clab.md#usage)
86+
87+
88+
## clab2drawio
89+
90+
```bash
91+
python clab2drawio.py -i <input_file.yaml> -o <output_file.drawio>
92+
```
93+
`-i, --input`: Specifies the path to your input YAML file.
94+
`-o, --output`: Specifies the path for the output drawio file.
95+
Make sure to replace `<input_file.yaml>` with the path to your .drawio file and `<output_file.drawio>` with the desired output YAML file path.
96+
97+
For more comprehensive guidance, including additional command-line options, please see the Usage section in [clab2drawio.md](clab2drawio.md#usage)

clab2drawio.md

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# clab2drawio
2+
3+
`clab2drawio` is a tool designed to automatically generate network topology diagrams from [Containerlab](https://github.com/srl-labs/containerlab) YAML files, rendering them into visually appealing diagrams using Draw.io. This tool simplifies the process of visualizing network designs and configurations, making it easier for network engineers and architects to document and share their containerlab environments.
4+
5+
![Drawio ](img/drawio1.png)
6+
7+
## Features
8+
9+
- **Automatic Diagram Generation**: Converts containerlab YAML configurations into detailed Draw.io diagrams in vertical and horizontal layouts.
10+
- **Intelligent Node Placement**: Attempts to determine the best placement for nodes automatically. However, for complex topologies, this can be challenging.
11+
- **Graph-level-Based Layout**: Organizes nodes into graph-level based on their connectivity for clearer topology visualization. Users can influence node placement by specifying graph-level directly in the containerlab configuration.
12+
- **Graph-icon Support**: Enhances node visualization by allowing users to specify graph-icon labels such as router, switch, or host to define custom icons for nodes in the generated diagrams.
13+
- **Customizable Styles**: Supports customization of node and link styles within the diagrams.
14+
15+
## Installation
16+
17+
Clone the repository to your local machine:
18+
19+
```bash
20+
git clone https://github.com/FloSch62/clab2drawio.git
21+
cd clab2drawio
22+
```
23+
24+
Ensure you have Python 3.x installed on your system. You can then install the required dependencies:
25+
```bash
26+
pip install -r requirements.txt
27+
```
28+
29+
## Usage
30+
To generate a network topology diagram from a containerlab YAML file, run the following command:
31+
32+
```bash
33+
python clab2drawio.py -i <path_to_your_yaml_file> -o <path_to_output_file>
34+
```
35+
The output will be a Draw.io diagram file saved in the output path. You can open this file with Draw.io to view and further edit your network topology diagram.
36+
37+
## Advanced Usage
38+
39+
### Influencing Node Placement
40+
41+
The tool attempts to automatically determine the best placement for nodes. However, achieving an optimal layout for complex topologies might be challenging. You can influence node placement behavior through the `graph-level` and `graph-icon` labels in the containerlab file, which supports both vertical and horizontal layouts. The `graph-level` label impacts the placement of nodes along the primary axis of the chosen layout A lower `graph-level` number (e.g., `graph-level: 1`) indicates a position towards the start of the canvas, while a higher number places the node further along the primary axis. This feature allows you to suggest a specific hierarchy for each node, aiding the tool in organizing the topology more effectively.
42+
43+
Example configuration to set node graph-level:
44+
45+
```bash
46+
client1:
47+
kind: "linux"
48+
labels:
49+
graph-level: 1 # This node will be placed towards the top of the canvas
50+
graph-icon: host # This node will use the client icon
51+
```
52+
```bash
53+
spine1:
54+
kind: "linux"
55+
labels:
56+
graph-level: 2 # This node will be placed below graph-level 1 nodes on the canvas
57+
graph-icon: switch # This node will use the switch icon
58+
```
59+
Using graph-level helps manage the vertical alignment of nodes in the generated diagram, making it easier to visualize the hierarchical structure of your network.
60+
61+
### Command-Line Arguments
62+
63+
`clab2drawio` supports several command-line arguments to customize the diagram generation process. Use these arguments to fine-tune the output according to your specific requirements:
64+
65+
- `-i, --input`: Specifies the filename of the input file. This file should be a containerlab YAML for diagram generation. This argument is required.
66+
67+
```bash
68+
python clab2drawio.py -i <path_to_your_yaml_file>
69+
```
70+
71+
- `-o, --output`: Specifies the output file path for the generated diagram in draw.io format. This argument is required.
72+
73+
```bash
74+
python clab2drawio.py -i <path_to_your_yaml_file> -o <path_to_output_file>
75+
```
76+
77+
- `--include-unlinked-nodes`: Include nodes without any links in the topology diagram. By default, only nodes with at least one connection are included.
78+
79+
- `--no-links`: Do not draw links between nodes in the topology diagram. This option can be useful for focusing on node placement or when the connectivity between nodes is not relevant.
80+
81+
- `--layout`: Specifies the layout of the topology diagram (either `vertical` or `horizontal`). The default layout is `vertical`.
82+
83+
- `--verbose`: Enable verbose output for debugging purposes.
84+
85+
86+
## Customization
87+
The tool allows for basic customization of node and link styles within the generated diagram. To customize, edit the custom_styles dictionary within the clab2drawio.py file according to your preferences.

0 commit comments

Comments
 (0)