Drawio2Clab is a tool that converts .drawio diagrams to YAML format, specifically designed for network topologies. It parses XML files exported from draw.io (or diagrams.net), extracts information about nodes and links, and generates a structured YAML representation of the network. This process streamlines the setup of complex network topologies within Containerlab environments, facilitating an easy and efficient way to manage container-based networking labs.
- Converts .drawio diagrams to Containerlab-compatible YAML.
- Allows selection of specific diagrams within a .drawio file.
- Supports block and flow styles for YAML endpoints.
- Extracts detailed node and link information for precise topology representation.
When creating your .drawio diagrams, please adhere to the following constraints to ensure successful conversion:
-
Node Labeling: All nodes must be labeled. To label a node, click on the node and start typing.
-
Link Labeling: All links need to be labeled. To label a link, double-click on the link and type your label. Only the labels closest to the source and destination will be considered.
In addition to labeling, nodes can contain additional data to further define the network configuration. The following attributes can be added to a node:
type
: Specify the type of the node. E.g., "ixrd2", "ixrd3".kind
: Specify the kind of the node, by default nokia_srlinuxmgmt-ipv4
: Assign a management IPv4 address to the node.group
: Define a group to which the node belongs.labels
: Add custom labels for additional metadata or categorization.
To add these attributes to a node, select the node and add custom properties in the format <property_name>=<value>
. Ensure each attribute is properly formatted according to the capabilities of draw.io for defining custom properties.
Those attributes will be added to the clab nodes.
The above image demonstrates how to correctly label nodes and links and add additional data to nodes for conversion.
Convert a .drawio file to YAML:
python drawio2clab.py -i input_file.xml -o output_file.yaml
Specify a diagram name and output style:
python drawio2clab.py -i input_file.xml -o output_file.yaml --diagram-name "Diagram 1" --style flow
-i
,--input
: Input.drawio
XML file.-o
,--output
: Output YAML file.--style
: YAML style (block
orflow
). Default isblock
.--diagram-name
: Name of the diagram to parse.--default-kind
: The default kind for nodes. Default is 'nokia_srlinux'