From 42a74ca61ce9a2f9e023fbd88aaf59d254334a5a Mon Sep 17 00:00:00 2001 From: "D. Arnodo" <124083497+darnodo@users.noreply.github.com> Date: Sun, 30 Mar 2025 15:53:49 +0200 Subject: [PATCH] feat(access template) : Create the Access jinja template (#8) - Switch do dind - update host IPs configuration --- .devcontainer/devcontainer.json | 2 +- containerlab/hosts/h1_interfaces | 2 +- containerlab/hosts/h2_interfaces | 2 +- containerlab/hosts/h3_interfaces | 2 +- templates/access.j2 | 27 +++++++++++++++++++++++++++ 5 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 templates/access.j2 diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 206ebf3..f697bae 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,5 +1,5 @@ { - "image": "ghcr.io/srl-labs/containerlab/devcontainer-dood:latest", + "image": "ghcr.io/srl-labs/containerlab/devcontainer-dind:latest", "runArgs": [ "--network=host", "--pid=host", diff --git a/containerlab/hosts/h1_interfaces b/containerlab/hosts/h1_interfaces index 588f9a7..98ef770 100755 --- a/containerlab/hosts/h1_interfaces +++ b/containerlab/hosts/h1_interfaces @@ -3,5 +3,5 @@ iface lo inet loopback auto eth1 iface eth1 inet static - address 10.100.100.1 + address 10.0.0.10 netmask 255.255.255.0 \ No newline at end of file diff --git a/containerlab/hosts/h2_interfaces b/containerlab/hosts/h2_interfaces index 5883945..d8df4d5 100755 --- a/containerlab/hosts/h2_interfaces +++ b/containerlab/hosts/h2_interfaces @@ -3,5 +3,5 @@ iface lo inet loopback auto eth1 iface eth1 inet static - address 10.100.100.2 + address 100.0.0.2 netmask 255.255.255.0 \ No newline at end of file diff --git a/containerlab/hosts/h3_interfaces b/containerlab/hosts/h3_interfaces index 0c7cf0d..8186b29 100755 --- a/containerlab/hosts/h3_interfaces +++ b/containerlab/hosts/h3_interfaces @@ -3,5 +3,5 @@ iface lo inet loopback auto eth1 iface eth1 inet static - address 10.100.100.3 + address 100.0.0.20 netmask 255.255.255.0 \ No newline at end of file diff --git a/templates/access.j2 b/templates/access.j2 new file mode 100644 index 0000000..c3defdf --- /dev/null +++ b/templates/access.j2 @@ -0,0 +1,27 @@ +{# Check if device has location and tenant #} +{%- if device.location and device.location.tenant %} +{%- set tenant = device.location.tenant %} +{%- set tenant_vlans = tenant.vlans.all() %} + +{# Create VLANs only if tenant_vlans exists and is not empty #} +{%- if tenant_vlans and tenant_vlans|length > 0 %} +{# Create VLANs #} +{%- for vlan in tenant_vlans %} +vlan {{ vlan.vid }} + name IRB_{{ tenant.name|upper }}_SERVICE +! +{%- endfor %} + +{# Configure trunk port on Ethernet1 #} +interface Ethernet1 + switchport mode trunk + switchport trunk allowed vlan {{ tenant_vlans|map(attribute='vid')|join(',') }} +! + +{# Configure access port on Ethernet2 with first VLAN from tenant #} +interface Ethernet2 + switchport access vlan {{ tenant_vlans[0].vid }} + switchport mode access +! +{%- endif %} +{%- endif %} \ No newline at end of file