filmov
tv
Network Automation with Python - Automate IP Address configuration on switch/router interfaces

Показать описание
Network Automation with Python!
What problem is solved by this script?
Often, for troubleshooting or study reasons, I have to build large topologies. Usually, there is no need to use specific IP addresses, so for assigning the IP I use a simple convention: the IP address of an interface can be simply determined looking at the hostnames of the local and remote switches (read below for further details).
Still, even removing the problem of what IP scheme to use, a lot of time is required to configure the IP address of each interface and the process is error prone...to complicate also the situation, error at this stage are usually discovered later, when the protocols that require L3 communication on the link are not working properly
What does the script?
The python script automatically configures the IP addresses of the switches.
The script is made for configuring networks with point-to-point links, each interface receives a /30 address
The IP addresses are chosen using a convention. The four octets that made the IP address are selected in the following way:
-The first two octets are assigned per Group. Groups info are read from file group_addresses. Example: device R6 is in group R, group R has first two octets 172.16
-The third octet is chosen comparing the devices' ID. For each connection, the two devices IDs are concatenated, with the smaller one in the first position. Example: for the link between R2 and R5, the third octet is 25
-The fourth octet is chosen comparing the devices' ID as well. The device with smaller device ID has fourth octet equal to 1, the other device has the fourth octet equals to 2. Example: R2 interface Fa0/0 is connected to R3 interface Fa1/1. Group R has assigned address group "172.16". R2 Fa0/0 gets IP 172.16.23.1, R3 Fa1/1 gets IP 172.16.23.2
What are the requirements?
Each switch has to have at least one interface with a reachable address configured (usually, a management interface, in this example interface fastEthernet 0/0). Telnet connections have to be allowed and configured. CDP has to be enabled
NB: cdp has to be disabled on the interface used for the management of the switch (no cdp enable)
This version of the script supports only one group with maximum 10 switches (switch ID has to be between 0 and 9)
The script assumes between two switches there in only one link.
The script is developed for Cisco 2961. FastEth 0/0 and 0/1 are in L3 mode and shut down by default. FastEth 1/X are L2 mode and no shut by default. Could be easily changed for other switches/routers
What are the next steps?
-Validation of the configuration: the script will ping the IP address on the other side of the link to check the configuration was applied properly
-Multigroup support: this will allow having topologies with more than 10 switches
-OSPF automatic configuration
Where can the script be downloaded?
What problem is solved by this script?
Often, for troubleshooting or study reasons, I have to build large topologies. Usually, there is no need to use specific IP addresses, so for assigning the IP I use a simple convention: the IP address of an interface can be simply determined looking at the hostnames of the local and remote switches (read below for further details).
Still, even removing the problem of what IP scheme to use, a lot of time is required to configure the IP address of each interface and the process is error prone...to complicate also the situation, error at this stage are usually discovered later, when the protocols that require L3 communication on the link are not working properly
What does the script?
The python script automatically configures the IP addresses of the switches.
The script is made for configuring networks with point-to-point links, each interface receives a /30 address
The IP addresses are chosen using a convention. The four octets that made the IP address are selected in the following way:
-The first two octets are assigned per Group. Groups info are read from file group_addresses. Example: device R6 is in group R, group R has first two octets 172.16
-The third octet is chosen comparing the devices' ID. For each connection, the two devices IDs are concatenated, with the smaller one in the first position. Example: for the link between R2 and R5, the third octet is 25
-The fourth octet is chosen comparing the devices' ID as well. The device with smaller device ID has fourth octet equal to 1, the other device has the fourth octet equals to 2. Example: R2 interface Fa0/0 is connected to R3 interface Fa1/1. Group R has assigned address group "172.16". R2 Fa0/0 gets IP 172.16.23.1, R3 Fa1/1 gets IP 172.16.23.2
What are the requirements?
Each switch has to have at least one interface with a reachable address configured (usually, a management interface, in this example interface fastEthernet 0/0). Telnet connections have to be allowed and configured. CDP has to be enabled
NB: cdp has to be disabled on the interface used for the management of the switch (no cdp enable)
This version of the script supports only one group with maximum 10 switches (switch ID has to be between 0 and 9)
The script assumes between two switches there in only one link.
The script is developed for Cisco 2961. FastEth 0/0 and 0/1 are in L3 mode and shut down by default. FastEth 1/X are L2 mode and no shut by default. Could be easily changed for other switches/routers
What are the next steps?
-Validation of the configuration: the script will ping the IP address on the other side of the link to check the configuration was applied properly
-Multigroup support: this will allow having topologies with more than 10 switches
-OSPF automatic configuration
Where can the script be downloaded?