Assumption: VLANs created 1024-2048
Python script to generate config script file (pass1vlanip.py)…
vl_fr = 1024
vl_to = 1278
pass1oct3 = 0
dhcpsrv = “10.10.10.10”
mask = “255.255.255.0”
for value in range (vl_fr,vl_to):
pass1oct3 = pass1oct3 + 1
ipadd = “1.1.” + str (pass1oct3) + “.1”
with open(‘pass1vlanip.cfg’, ‘a’) as outfile:
outfile.write(“\ninterface vlan ” + str (value))
outfile.write(“\nip address ” + str (ipadd) + ” ” + str (mask))
outfile.write(“\nip dhcp-relay”)
outfile.write(“\nexit”)
outfile.write(“\nip dhcp-relay fwd-path ” + str (ipadd) + ” ” + str (dhcpsrv))
outfile.write(“\nip dhcp-relay fwd-path ” + str (ipadd) + ” ” + str (dhcpsrv) + ” enable”)
outfile.write(“\nip dhcp-relay fwd-path ” + str (ipadd) + ” ” + str (dhcpsrv) + ” mode bootp_dhcp”)
Note: Create multiple files for each “pass” with different value in second octet to create batches of class C subnets 254 hosts (pass1vlanip.py, pass2vlanip.py, etc…).
Part of the output file (ie pass1vlanip.cfg):
interface vlan 1024
ip address 1.1.1.1 255.255.255.0
ip dhcp-relay
exit
ip dhcp-relay fwd-path 1.1.1.1 10.10.10.10
ip dhcp-relay fwd-path 1.1.1.1 10.10.10.10 enable
ip dhcp-relay fwd-path 1.1.1.1 10.10.10.10 mode bootp_dhcp
interface vlan 1025
ip address 1.1.2.1 255.255.255.0
ip dhcp-relay
exit
ip dhcp-relay fwd-path 1.1.2.1 10.10.10.10
ip dhcp-relay fwd-path 1.1.2.1 10.10.10.10 enable
ip dhcp-relay fwd-path 1.1.2.1 10.10.10.10 mode bootp_dhcp
interface vlan 1026
ip address 1.1.3.1 255.255.255.0
ip dhcp-relay
exit
ip dhcp-relay fwd-path 1.1.3.1 10.10.10.10
ip dhcp-relay fwd-path 1.1.3.1 10.10.10.10 enable
ip dhcp-relay fwd-path 1.1.3.1 10.10.10.10 mode bootp_dhcp
Rename .cfg file as .run file and move to .acli folder so that ACLI terminal can source the files.
From ACLI login to switch and type @run pass1ip.run which will run the commands created by the python script. This speeds up the process of creating multiple configuration entries such as VLANs, IP addresses, DHCP etc…
Another example script to delete a range of VLANs (delvlan.py):
vl_fr = 1024
vl_to = 2048
for value in range (vl_fr,vl_to):
with open(‘delvlan.cfg’, ‘a’) as outfile:
outfile.write(“\nvlan delete ” + str (value))
value = value + 1
with open(‘delvlan.cfg’, ‘a’) as outfile:
outfile.write(“\nvlan delete ” + str (value))
Output file (delvlan.cfg):
vlan delete 1024
vlan delete 1025
vlan delete 1026
vlan delete 1027
vlan delete 1028
etc…
Rename delvlan.run and type @run delvlan.run in ACLI terminal will remove long list of VLANs and all underlying VLAN configuration such as the IP address and VRRP. Otherwise have to delete each VLAN individually as there is no range parameter.