if __name__ == "__main__": if not INTERFACE_NAME: print("The interface name is required") sys.exit(-1) # Instantiate an interface object INTERFACE = Interface(INTERFACE_NAME) print("Before changing the interface configuration") print(INTERFACE.config()) # Configure "switchport" so the interface is L2 INTERFACE.set_switchport() # Set the description on the interface INTERFACE.set_description(INTERFACE_DESCRIPTION) # Set the interface mode to be an access port INTERFACE.set_mode(INTERFACE_MODE) # Set the access vlan, there is no native setter method for this # so we have to do it manually INTERFACE._if_cfg('switchport access vlan {0}'.format(INTERFACE_ACCESS_VLAN)) INTERFACE.apply_config() # Set the interface state INTERFACE.set_state(INTERFACE_STATE) print("After changing the interface configuration") print(INTERFACE.config())
# Instantiate an interface object INTERFACE = Interface(INTERFACE_NAME) print("Before changing the interface configuration") print(INTERFACE.config()) # Configure "switchport" so the interface is L2 INTERFACE.set_switchport() # Set the description on the interface INTERFACE.set_description(INTERFACE_DESCRIPTION) # Set the interface mode to be an a trunk port INTERFACE.set_mode(INTERFACE_MODE) # Set the dot1q native vlan for the port, there is no native setter # method to do this so we have to do it manually INTERFACE._if_cfg("switchport trunk native vlan " + "{0}".format(TRUNK_NATIVE_VLAN)) INTERFACE.apply_config() # Set the vlans allowed on the trunk INTERFACE._if_cfg("switchport trunk allowed vlan " + "{0}".format(TRUNK_ALLOWED_VLANS)) INTERFACE.apply_config() # Set the interface state INTERFACE.set_state(INTERFACE_STATE) print("After changing the interface configuration") print(INTERFACE.config())