# A description to configure on the interface, setting this to a NoneType # object or an empty string will result in the description being unset on the # interface. INTERFACE_DESCRIPTION = "Layer 3 Routed Interface Example" # Interface state can be set to up using: "up", "no shut" or "noshut" # Setting it to any other value will cause "shut" to be configured on # the interface INTERFACE_STATE = "no shut" 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 "no switchport" so the interface is L3 INTERFACE.set_switchport(no=True) # Set an IP address on the interface if INTERFACE_IP_ADDRESS != "": INTERFACE.set_ipaddress(INTERFACE_IP_ADDRESS) # Set the description on the interface INTERFACE.set_description(INTERFACE_DESCRIPTION) # Set the interface state
# The switchport mode, can be access or trunk INTERFACE_MODE = "access" # The access vlan for the port INTERFACE_ACCESS_VLAN = "200" # Interface state can be set to up using: "up", "no shut" or "noshut" # Setting it to any other value will cause "shut" to be configured on # the interface INTERFACE_STATE = "no shut" 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
username = "******" password = "******" NXAPITransport.init(target_url=target_url, username=username, password=password) ################### ################### # cli/clip/clid are changed a bit, but largely the same ################### print NXAPITransport.cli("show version") NXAPITransport.clip("show interface brief") NXAPITransport.clic("conf t ;interface eth4/1 ;no shut") print NXAPITransport.clid("show version") ################### # Below is exactly the same as the usage on the switch. Do whatever you # are already doing on the switch right now! ################### print Interface.interfaces() i = Interface("Ethernet4/1") print i.show(key="eth_mtu") i.set_description(d="ifx4/1")
target_url = "http://10.30.14.8/ins" username = "******" password = "******" NXAPITransport.init(target_url=target_url, username=username, password=password) ################### ################### # cli/clip/clid are changed a bit, but largely the same ################### print NXAPITransport.cli("show version") NXAPITransport.clip("show interface brief") NXAPITransport.clic("conf t ;interface eth4/1 ;no shut") print NXAPITransport.clid("show version") ################### # Below is exactly the same as the usage on the switch. Do whatever you # are already doing on the switch right now! ################### print Interface.interfaces() i = Interface("Ethernet4/1") print i.show(key="eth_mtu") i.set_description(d="ifx4/1")
# The dot1q native vlan TRUNK_NATIVE_VLAN = "6" # The allowed vlans on the trunk TRUNK_ALLOWED_VLANS = "15-20,100" # Interface state can be set to up using: "up", "no shut" or "noshut" # Setting it to any other value will cause "shut" to be configured on # the interface INTERFACE_STATE = "no shut" 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 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