Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions .devcontainer/Dockerfile

This file was deleted.

43 changes: 0 additions & 43 deletions .devcontainer/devcontainer.json

This file was deleted.

10 changes: 0 additions & 10 deletions .github/workflows/build-switchgentool.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,8 @@ jobs:
run: |
pyinstaller --onefile --clean --noconfirm --noupx `
--name network_config_generator `
--additional-hooks-dir=. `
--add-data "input;input" `
--collect-all jinja2 `
--hidden-import=convertors `
--hidden-import=convertors.convertors_lab_switch_json `
--hidden-import=convertors.convertors_bmc_switch_json `
--collect-submodules=convertors `
--exclude-module tkinter `
--exclude-module matplotlib `
--exclude-module PIL `
Expand All @@ -97,13 +92,8 @@ jobs:
run: |
pyinstaller --onefile --clean --noconfirm \
--name network_config_generator \
--additional-hooks-dir=. \
--add-data "input:input" \
--collect-all jinja2 \
--hidden-import=convertors \
--hidden-import=convertors.convertors_lab_switch_json \
--hidden-import=convertors.convertors_bmc_switch_json \
--collect-submodules=convertors \
--exclude-module tkinter \
--exclude-module matplotlib \
--exclude-module PIL \
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v4
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# Test binary, built with `go test -c`
*.test
_*
!**/__init__.py

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
Expand Down
24 changes: 17 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,14 @@ root/
│ ├── cisco/
│ └── dellemc/
├── src/ # Source code
│ ├── __init__.py # Package initialization
│ ├── main.py # Entry point for the tool
│ ├── generator.py # Main generation logic
│ ├── loader.py # Input file loading and parsing
│ └── convertors/ # Input format converters
│ └── convertors_lab_switch_json.py # Lab format to standard JSON converter
│ ├── __init__.py # Convertor registry
│ ├── convertors_lab_switch_json.py # Lab format converter
│ └── convertors_bmc_switch_json.py # BMC switch converter
├── tests/ # Test files
│ ├── test_generator.py # Unit tests for generator logic
│ ├── test_convertors.py # Unit tests for input conversion
Expand Down Expand Up @@ -247,21 +250,28 @@ The tool accepts these parameters:

| Parameter | Required | Description |
|-------------------|----------|-------------|
| `--input_json` | ✅ Yes | Path to your input JSON file |
| `--output_folder` | ✅ Yes | Directory to save generated configs |
| `--convertor` | ❌ No | Custom converter for non-standard formats |
| `--input_json` | ✅ Yes | Path to your input JSON file (lab or standard format) |
| `--output_folder` | ❌ No | Directory to save generated configs (default: current directory) |
| `--template_folder` | ❌ No | Folder containing Jinja2 templates (default: input/jinja2_templates) |
| `--convertor` | ❌ No | Convertor to use for non-standard formats (default: convertors.convertors_lab_switch_json) |

### Quick Examples

```bash
# Basic usage - auto-detects input format
python src/main.py --input_json your_input.json --output_folder outputs/
python src/main.py --input_json input/standard_input.json --output_folder output/

# With custom output directory
python src/main.py --input_json my_input.json --output_folder configs/

# Using short convertor alias
python src/main.py --input_json lab_input.json --output_folder output/ --convertor lab

# Using the standalone executable (Windows)
.\network_config_generator.exe --input_json your_input.json --output_folder outputs\
network_config_generator.exe --input_json input/standard_input.json --output_folder output/

# Using the standalone executable (Linux)
./network_config_generator --input_json your_input.json --output_folder outputs/
./network_config_generator --input_json input/standard_input.json --output_folder output/
```

> [!IMPORTANT]
Expand Down
13 changes: 0 additions & 13 deletions hook-convertors.py

This file was deleted.

6 changes: 6 additions & 0 deletions input/jinja2_templates/cisco/nxos/system.j2
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,9 @@ ip load-sharing address source-destination port source-destination
ip icmp-errors source-interface [MGMT_VLAN]

cli alias name wr copy running-config startup-config

{# -------- SNMP Settings -------- #}
snmp-server community [PLACEHOLDER] ro
snmp-server community [PLACEHOLDER] rW
snmp-server contact "Contact Support"
snmp-server location {{ switch.site }}
4 changes: 2 additions & 2 deletions input/jinja2_templates/dellemc/os10/bgp.j2
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ router bgp {{ bgp.asn }}
router-id {{ bgp.router_id }}
bestpath as-path multipath-relax
log-neighbor-changes
maximum-paths 8
maximum-paths ibgp 8
maximum-paths ebgp 8
address-family ipv4 unicast
{%- for network in bgp.networks %}
network {{ network }}
Expand Down Expand Up @@ -37,7 +37,6 @@ router bgp {{ bgp.asn }}
{%- endif %}
address-family ipv4 unicast
activate
sender-side-loop-detection
{%- if neighbor.af_ipv4_unicast is defined %}
{%- if neighbor.af_ipv4_unicast.prefix_list_in is defined %}
prefix-list {{ neighbor.af_ipv4_unicast.prefix_list_in }} in
Expand All @@ -46,6 +45,7 @@ router bgp {{ bgp.asn }}
prefix-list {{ neighbor.af_ipv4_unicast.prefix_list_out }} out
{%- endif %}
{%- endif %}
next-hop-self
{%- endif %}

{%- endfor %}
Expand Down
2 changes: 2 additions & 0 deletions input/jinja2_templates/dellemc/os10/full_config.j2
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

{% include "port_channel.j2" %}

{% include "vlt.j2" %}

{% include "prefix_list.j2" %}

{% include "bgp.j2" %}
Expand Down
23 changes: 23 additions & 0 deletions input/jinja2_templates/dellemc/os10/interface.j2
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
{%- set intf_range = iface.intf if iface.intf is defined else iface.start_intf ~ (('-' ~ iface.end_intf) if iface.end_intf is defined and iface.end_intf != iface.start_intf else '') %}
{%- set intf_name = iface.intf_type ~ ' ' ~ intf_range %}
{%- set is_range = '-' in intf_range | string %}
{%- if iface.shutdown is defined and iface.shutdown %}
! NOTE: This interface configuration initializes ports in shutdown state for security.
! This is a recommended best practice to prevent unauthorized access on unused ports.
! User may choose to apply this initial configuration or customize based on deployment requirements.
{%- endif %}
interface {% if is_range %}range {% endif %}{{ intf_name }}
description {{ iface.name }}
switchport mode access
Expand Down Expand Up @@ -56,6 +61,24 @@ interface {% if is_range %}range {% endif %}{{ intf_name }}
{%- endif %}
{% endfor %}

{#- -------- MLAG Peer Link Interfaces -------- #}
{% for iface in interfaces if iface.type == "MLAG" %}
{%- set intf_range = iface.intf if iface.intf is defined else iface.start_intf ~ (('-' ~ iface.end_intf) if iface.end_intf is defined and iface.end_intf != iface.start_intf else '') %}
{%- set intf_name = iface.intf_type ~ ' ' ~ intf_range %}
{%- set is_range = '-' in intf_range | string %}
interface {% if is_range %}range {% endif %}{{ intf_name }}
description {{ iface.name }}
no switchport
mtu 9216
flowcontrol receive off
priority-flow-control mode on
{%- if iface.shutdown is defined and iface.shutdown %}
shutdown
{%- else %}
no shutdown
{%- endif %}
{% endfor %}

{#- -------- L3 Interfaces (Ethernet only) -------- #}
{% for iface in interfaces if iface.type == "L3" and iface.intf_type | lower == "ethernet" %}
{%- set intf_range = iface.intf if iface.intf is defined else iface.start_intf ~ (('-' ~ iface.end_intf) if iface.end_intf is defined and iface.end_intf != iface.start_intf else '') %}
Expand Down
54 changes: 34 additions & 20 deletions input/jinja2_templates/dellemc/os10/port_channel.j2
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ interface port-channel{{ pc.id }}
description {{ pc.description }}

{%- if pc.type | lower == 'trunk' %}
switchport
no shutdown
switchport mode trunk
switchport trunk native vlan {{ pc.native_vlan }}
switchport access vlan {{ pc.native_vlan }}
{%- if pc.tagged_vlans is defined %}
switchport trunk allowed vlan {{ pc.tagged_vlans }}
{%- endif %}
{%- if pc.vlt_port is defined and pc.vlt_port %}
vlt-port-channel {{ pc.id }}
{%- elif 'peer' in (pc.description | lower) %}
vlt-port-channel {{ pc.id }}
{%- endif %}
priority-flow-control mode on
spanning-tree port type network
logging event port link-status

{%- if pc.vpc_peer_link is defined and pc.vpc_peer_link %}
vpc peer-link
Expand All @@ -25,29 +28,43 @@ interface port-channel{{ pc.id }}
{%- endif %}

{%- elif pc.type | lower == 'l3' %}
no shutdown
no switchport
priority-flow-control mode on
ip address {{ pc.ipv4 }}
mtu 9216
ip address {{ pc.ipv4 }}/30
{%- endif %}
{%- if pc.type | lower == 'trunk' %}
mtu 9216
no shutdown
{%- endif %}

{# -------- Member Interfaces -------- #}
{%- for member in pc.members %}
interface Ethernet {{ member }}
description {{ pc.description }}
no shutdown
channel-group {{ pc.id }} mode active

{%- if pc.type | lower == 'l3' %}
no switchport
mtu 9216
flowcontrol receive off
priority-flow-control mode on

{%- if pc.type | lower == 'trunk' %}
switchport
switchport mode trunk
switchport trunk native vlan {{ pc.native_vlan }}
{%- if pc.tagged_vlans is defined %}
switchport trunk allowed vlan {{ pc.tagged_vlans }}
{%- endif %}
spanning-tree port type network
{%- elif pc.type | lower == 'trunk' %}
{# For VLT/BMC peer-link members (po102), render as no switchport per reference #}
{%- if pc.id == 102 or ('tor_bmc' in (pc.description | lower)) %}
no switchport
mtu 9216
flowcontrol receive off
{%- else %}
switchport
switchport mode trunk
switchport trunk native vlan {{ pc.native_vlan }}
{%- if pc.tagged_vlans is defined %}
switchport trunk allowed vlan {{ pc.tagged_vlans }}
{%- endif %}
spanning-tree port type network
mtu 9216
flowcontrol receive off
{%- endif %}
{%- endif %}

{#- -------- QoS Policy -------- #}
Expand All @@ -57,9 +74,6 @@ interface Ethernet {{ member }}
qos-map traffic-class AZS_SERVICES_TrafficClass
ets mode on
{%- endif %}

channel-group {{ pc.id }} mode active
no shutdown
{% endfor %}

{%- endfor %}
Expand Down
17 changes: 17 additions & 0 deletions input/jinja2_templates/dellemc/os10/system.j2
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,22 @@ mac address-table aging-time 1000000
no ip dhcp-relay information-option
no ip dhcp snooping

{# -------- VRRP Settings (skip for BMC) -------- #}
{%- if switch.type | upper != 'BMC' %}
vrrp version 3
vrrp delay reload 180
{%- endif %}

{# -------- SNMP Settings -------- #}
! system.j2 - snmp_settings
snmp-server community [SNMP_COMMUNITY_RO] ro
snmp-server community [SNMP_COMMUNITY_RW] rw
snmp-server contact "Contact Support"
snmp-server location {{ switch.site }}

{# -------- Management VRF Configuration -------- #}
! system.j2 - management_vrf
ip vrf management
interface management

management route 0.0.0.0/0 [MGMT_GATEWAY_IP]
Loading
Loading