Skip to content

Commit

Permalink
Merge pull request #12 from srl-labs/grafana_style
Browse files Browse the repository at this point in the history
Grafana style
  • Loading branch information
FloSch62 authored Apr 12, 2024
2 parents d346ecd + 12cd74f commit a194312
Show file tree
Hide file tree
Showing 48 changed files with 1,834 additions and 3,293 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
venv/*
__pycache__
grafana_test/
testlabsv2/
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ COPY clab2drawio.py /app/
COPY requirements.txt /app/
COPY entrypoint.sh /app/
COPY styles/ /app/styles/
COPY lib/ /app/lib/

# Install any needed packages specified in requirements.txt
RUN pip install --no-cache-dir -r /app/requirements.txt
Expand Down
25 changes: 7 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,19 @@ To simplify dependency management and execution, the tools can be run inside a D
#### Pulling from dockerhub

```bash
docker pull flosch62/clab-io-draw:latest
docker pull ghcr.io/srl-labs/clab-io-draw:latest
```

#### Building the Docker Image by yourself

Navigate to the project directory and run:

```bash
docker build -t clab-io-draw .
```

This command builds the Docker image of clab-io-draw with the tag clab-io-draw, using the Dockerfile located in the docker/ directory.

#### Running the Tools

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:

```bash
docker run -v "$(pwd)":/data flosch62/clab-io-draw -i lab-examples/clos03/cfg-clos.clab.yml
docker run -v "$(pwd)":/data ghcr.io/srl-labs/clab-io-draw -i lab-examples/clos03/cfg-clos.clab.yml
```

```bash
docker run -v "$(pwd)":/data flosch62/clab-io-draw -i output.drawio
docker run -v "$(pwd)":/data ghcr.io/srl-labs/clab-io-draw -i output.drawio
```

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.
Expand Down Expand Up @@ -86,23 +76,22 @@ Detailed Usages: [drawio2clab.md](docs/drawio2clab.md#usage) and [clab2drawio.md
## drawio2clab

```bash
python drawio2clab.py -i <input_file.drawio> -o <output_file.yaml>
python drawio2clab.py -i <input_file.drawio>
```

`-i, --input`: Specifies the path to your input .drawio file.
`-o, --output`: Specifies the path for the output YAML file.
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.
Make sure to replace `<input_file.drawio>` with the path to your .drawio file

For more comprehensive guidance, including additional command-line options, please see the Usage section in [drawio2clab.md](docs/drawio2clab.md#usage)

## clab2drawio

```bash
python clab2drawio.py -i <input_file.yaml> -o <output_file.drawio>
python clab2drawio.py -i <input_file.yaml>
```

`-i, --input`: Specifies the path to your input YAML file.
`-o, --output`: Specifies the path for the output drawio file.
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.
Make sure to replace `<input_file.yaml>` with the path to your .drawio file

For more comprehensive guidance, including additional command-line options, please see the Usage section in [clab2drawio.md](docs/clab2drawio.md#usage)
1,270 changes: 737 additions & 533 deletions clab2drawio.py

Large diffs are not rendered by default.

36 changes: 15 additions & 21 deletions docs/clab2drawio.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,13 @@
- **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.
- **Customizable Styles**: Supports customization of node and link styles within the diagrams.

## Installation

Clone the repository to your local machine:

```bash
git clone https://github.com/FloSch62/clab2drawio.git
cd clab2drawio
```

Ensure you have Python 3.x installed on your system. You can then install the required dependencies:
```bash
pip install -r requirements.txt
```

## Usage
To generate a network topology diagram from a containerlab YAML file, run the following command:

```bash
python clab2drawio.py -i <path_to_your_yaml_file> -o <path_to_output_file>
python clab2drawio.py -i <path_to_your_yaml_file>
```
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.
The output will be a Draw.io diagram file saved in the output path. In case without -o, the file will be saved in folder of the input file. You can open this file with Draw.io to view and further edit your network topology diagram.

## Advanced Usage

Expand Down Expand Up @@ -73,17 +59,21 @@ Using graph-level helps manage the vertical alignment of nodes in the generated
```bash
python clab2drawio.py -i <path_to_your_yaml_file> -o <path_to_output_file>
```
- `-g, --gf_dashboard`: Generates a grafana dashboard in grafana style. (WIP)

```bash
python clab2drawio.py -i <path_to_your_yaml_file> -g
```
- `--include-unlinked-nodes`: Include nodes without any links in the topology diagram. By default, only nodes with at least one connection are included.

- `--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.

- `--layout`: Specifies the layout of the topology diagram (either `vertical` or `horizontal`). The default layout is `vertical`.

- `--theme`: Specifies the theme for the diagram (`bright` or `dark`) or the path to a custom style config file. By default, the `bright` theme is used. Users can also create their own style file and place it in any directory, specifying its path with this option.
- `--theme`: Specifies the theme for the diagram (`nokia_bright` or `nokia_dark`) or the path to a custom style config file. By default, the `bright` theme is used. Users can also create their own style file and place it in any directory, specifying its path with this option. Feel free to contribute your own styles.

```bash
python clab2drawio.py --theme dark -i <path_to_your_yaml_file>
python clab2drawio.py --theme nokia_dark -i <path_to_your_yaml_file>
```

Or using a custom style file:
Expand All @@ -99,10 +89,14 @@ Using graph-level helps manage the vertical alignment of nodes in the generated
The tool allows for customization of node and link styles within the generated diagrams, making it possible to adjust the appearance to fit specific requirements or preferences.

### Custom Styles
To customize styles, you can edit the `clab2drawio_styles.yaml` configuration file. This file defines the base style, link style, source and target label styles, and custom styles for different types of nodes based on their roles (e.g., routers, switches, servers).
To customize styles, you can edit or copy the `nokia_bright.yaml` configuration file. This file defines the base style, link style, source and target label styles, and custom styles for different types of nodes based on their roles (e.g., routers, switches, servers).

An example snippet from `clab2drawio_styles.yaml`:
An example snippet from `nokia_bright.yaml`:
```yaml
#General Diagram settings:
pagew: "auto"
pageh: "auto"
base_style: "shape=image;imageAlign=center;imageVerticalAlign=middle;labelPosition=left;align=right;verticalLabelPosition=top;spacingLeft=0;verticalAlign=bottom;spacingTop=0;spacing=0;"
link_style: "endArrow=none;jumpStyle=gap;"
src_label_style: "verticalLabelPosition=bottom;verticalAlign=top;align=left;spacingLeft=1;spacingTop=1;spacingBottom=0;"
Expand All @@ -120,7 +114,7 @@ icon_to_group_mapping:
```

### Applying Styles
Custom styles are applied to nodes and links based on the configurations specified in the style configuration files (`bright.yaml` for the bright theme and `dark.yaml` for the dark theme), located in the `styles` directory by default. To apply a new style to a node type, update its corresponding style definition in the appropriate YAML file. These styles determine the appearance of nodes and links in the generated diagram, including shapes, colors, and icons.
Custom styles are applied to nodes and links based on the configurations specified in the style configuration files (`nokia_bright.yaml` for the bright theme and `nokia_dark.yaml` for the dark theme), located in the `styles` directory by default. To apply a new style to a node type, update its corresponding style definition in the appropriate YAML file. These styles determine the appearance of nodes and links in the generated diagram, including shapes, colors, and icons.

If you wish to create a completely new style, you can create a new YAML file with your custom configurations. This file can be placed in any directory, and you can specify its path when running the script using the `--theme` option.

Expand Down
9 changes: 5 additions & 4 deletions docs/drawio2clab.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ python drawio2clab.py -i input_file.xml -o output_file.yaml --diagram-name "Diag
```

### Arguments
- -i, --input: Input .drawio XML file.
- -o, --output: Output YAML file.
- --style: YAML style (block or flow). Default is block.
- --diagram-name: Name of the diagram to parse.

- `-i`, `--input`: Input `.drawio` XML file.
- `-o`, `--output`: Output YAML file.
- `--style`: YAML style (`block` or `flow`). Default is `block`.
- `--diagram-name`: Name of the diagram to parse.
Loading

0 comments on commit a194312

Please sign in to comment.