This tutorial shows how to access interfaces (physical/logical ports/links) of a network element and operations supported by onePK on these interfaces.
The code used in this tutorial is available in the NetworkInterfaceTutorial.py file located under <SDK Location>/python/tutorials/interfaces/NetworkInterfaceTutorial.py.
To connect to a network element, an application must have the following information available:
See Connecting to a Network Element tutorial.
Retrieve a list of network interfaces that matches the filter criteria. The list is returned as a collection of interface objects consisting of a list of networkInterface objects.
filter = InterfaceFilter(None,InterfaceTypes.ONEP_IF_TYPE_ETHERNET) networkInterfaces = network_element.get_interface_list(filter) print "\nPrinting all Ethernet interfaces..." for networkInterface in networkInterfaces: print "\t" + networkInterface.__str__()
Determine the hardware properties of the network interfaces. These properties do not change over the life of the interfaces as these hardware properties represent slot number and port number specifically.
intf = tutorial.get_an_interface() if intf == None: logger.error("No interfaces are available.") sys.exit(1) intfProperty = NetworkInterface.get_property(intf) print "\t" + intf.name + "\t Port" + str(intfProperty.port) + "\t Slot" + str(intfProperty.slot)
Get the status of each network interface.
print "\t Interface " + intf.name + " status is " + str(intf.get_status())
Get the configuration from each network interface.
#NOT supported #for networkInterface in networkInterfaces: # intfConfig = NetworkInterface.get_config(networkInterface) # print "\t" + intfConfig.display_name
Get the parent of each network interface.
for networkInterface in networkInterfaces: parentIntf = networkInterface.get_parent() print "\t" + parentIntf.__str__()
Get the subinterface of each network interface.
for networkInterface in networkInterfaces: parentIntf = networkInterface.get_parent() subIntfList = parentIntf.get_subinterface_list() for subIntf in subIntfList: print "\t" + subIntf.__str__()
Congratulations! You now know how to access various network interfaces and interface properties.