pyaoscx.interface module

class pyaoscx.interface.Interface(session, name, uri=None, ip6_addresses=[], **kwargs)

Bases: pyaoscx.pyaoscx_module.PyaoscxModule

Provide configuration management for Interface on AOS-CX devices.

add_ipv4_address(ip_address)
Configure a Interface object to add a new IPv4 address to it and
calls apply(), applying changes inside Switch.
Parameters:ip_address – IPv4 address to assign to the interface. Example: “1.1.1.1”
Returns:True if object was changed.
add_ipv6_address(ip_address, address_type='global-unicast')
Configure a Interface object to append a IPv6 address to its
ip6_addresses list and apply changes.
Parameters:
  • ip_address – IPv6 address to assign to the interface. A Ipv6 object is also accepted. Example: ‘2001:db8::11/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff’
  • address_type – Type of Address. Defaults to global-unicast.
Returns:

Ipv6 object.

add_port_to_lag(interface)
Configure a Port as a LAG member, and also enable the port. Add port
to list of interfaces inside Interface object.
Parameters:interface – Alphanumeric name of the interface. A Interface object is also accepted.
Returns:True if object was changed.
add_vlan_trunks(vlan_trunk_ids)
Add specified VLANs to a trunk port. By default, this will also set
the port to have ‘no routing’ and if there is not a native VLAN, will set the native VLAN to VLAN 1.
Parameters:vlan_trunk_ids – Dictionary of VLANs to specify as allowed on the trunk port. If empty, the interface will allow all VLANs on the trunk.
Returns:True if object was changed.
admin_state
apply()
Main method used to update or create a Interface or Port table entry.
Checks whether the Interface exists in the switch. Calls self.update() if Interface is being updated. Calls self.create() if a Interface table entry is being created.
Return modified:
 Boolean, True if object was created or modified.
base_uri = 'system/interfaces'
clear_acl(acl_type, acl_direction)

Clear an interface’s ACL.

Parameters:acl_type – Type of ACL: options are ‘aclv4_out’, ‘aclv4_in’, ‘aclv6_in’, or ‘aclv6_out’.
Returns:True if object was changed.
configure_l2(phys_ports=None, ipv4=None, vlan_ids_list=None, vlan_tag=1, lacp=None, description=None, fallback_enabled=None, mc_lag=None, vlan_mode='native-untagged', trunk_allowed_all=False, native_vlan_tag=True)
Configure an Interface object, set the attributes to a L2 LAG and
apply() changes inside Switch.
Parameters:
  • phys_ports – List of physical ports to aggregate (e.g. [“1/1/1”, “1/1/2”, “1/1/3”]) or list of Interface Objects.
  • ipv4 – Optional list of IPv4 address to assign to the interface. If more than one is specified, all addresses except for the first are added as secondary_ip4. Defaults to nothing if not specified. Example: [‘1.1.1.1’, ‘2.2.2.2’]
  • vlan_ids_list – Optional list of integer VLAN IDs or VLAN objects to add as trunk VLANS. Defaults to empty list if not specified.
  • vlan_tag – Optional VLAN ID or Vlan object to be added as vlan_tag. Defaults to VLAN 1.
  • lacp – Must be either “passive” or “active.” Does not change if not specified.
  • description – Optional description for the interface. Defaults to nothing if not specified.
  • fallback_enabled – Boolean to set the LAG’s LACP fallback mode.
  • mc_lag – Boolean to set the LAG as a multi-chassis LAG.
  • vlan_mode – Vlan mode on Interface, should be access or trunk Defaults to ‘native-untagged’.
  • trunk_allowed_all – Flag for vlan trunk allowed all on L2 interface, vlan_mode must be set to trunk.
  • native_vlan_tag – Flag for accepting only tagged packets on VLAN trunk native, vlan_mode must be set to trunk.
Returns:

True if object was changed.

configure_l3(phys_ports=None, ipv4=None, ipv6=None, vrf='default', lacp=None, description=None, fallback_enabled=None, mc_lag=None)
Configure an Interface object, if not materialized, materialize it and
then set the attributes to a L3 LAG and apply() changes inside Switch.
Parameters:
  • phys_ports – List of physical ports to aggregate (e.g. [“1/1/1”, “1/1/2”, “1/1/3”]) or list of Interface Objects.
  • ipv4 – Optional list of IPv4 address to assign to the interface. If more than one is specified, all addresses except for the first are added as secondary_ip4. Defaults to nothing if not specified. Example: [‘1.1.1.1’, ‘2.2.2.2’]
  • ipv6 – String list of IPv6 addresses to assign to the interface. Defaults to nothing if not specified. List of A Ipv6 objects is accepted. Example: [‘2001:db8::11/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff’]
  • vrf – VRF to attach the SVI to. Defaults to “default” if not specified. A Vrf object is also accepted.
  • lacp – Must be either “passive” or “active.” Does not change if not specified.
  • description – Optional description for the interface. Defaults to nothing if not specified.
  • fallback_enabled – Boolean to set the LAG’s LACP fallback mode.
  • mc_lag – Boolean to set the LAG as a multi-chassis LAG.
Returns:

True if object was changed.

configure_l3_ipv4_port(ip_address=None, port_desc=None, vrf='default')
Function will enable routing on the port and update the IPv4 address
if given.
Parameters:
  • ip_address – IPv4 address to assign to the interface. Defaults to nothing if not specified. Example: ‘1.1.1.1’
  • port_desc – Optional description for the interface. Defaults to nothing if not specified.
  • vrf – Name of the VRF to which the Port belongs. Defaults to “default” if not specified.
Returns:

True if object was changed.

configure_loopback(vrf, ipv4=None, description=None)
Configure an Interface object to create a Loopback Interface for a
logical L3 Interface. If the Loopback Interface already exists and an IPv4 address is given, this function will update the IPv4 address.
Parameters:
  • vrf – VRF to attach the Loopback to. Defaults to “default” if not specified.
  • ipv4 – IPv4 address to assign to the interface. Defaults to nothing if not specified. Example: ‘1.1.1.1’
  • description – Optional description for the interface. Defaults to nothing if not specified..
Returns:

True if object was changed.

configure_mclag_options(mc_lag=None, lacp_fallback=None)
Configure an Interface object, set its LAG attributes. Requires a
call to apply() afterwards.
Parameters:
  • mc_lag – Boolean to set the LAG as a multi-chassis LAG.
  • lacp_fallback – Boolean to set the LAG’s LACP fallback mode.
configure_speed_duplex(autoneg=None, speeds=None, duplex=None)

Configure the Interface speed and duplex mode.

Parameters:
  • speeds – List of allowed Interface speeds.
  • duplex – “full” for full duplex or “half” for half duplex.
  • autonegotiation – switch autonegotiation “on” or “off”.
Returns:

True if object changed.

configure_svi(vlan=None, ipv4=None, ipv6=None, vrf=None, description=None, int_type='vlan', user_config='up')

Configure a Interface table entry for a VLAN.

Parameters:
  • vlan – Numeric ID of VLAN A Vlan object is also accepted
  • ipv4 – Optional list of IPv4 address to assign to the interface. If more than one is specified, all addresses except for the first are added as secondary_ip4. Defaults to nothing if not specified. Example: [‘1.1.1.1’].
  • ipv6 – String list of IPv6 addresses to assign to the interface. Defaults to nothing if not specified. A Ipv6 object is also accepted. Example: [‘2001:db8::11/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff’]
  • vrf – VRF to attach the SVI to. Defaults to “default” if not specified. A Vrf object is also accepted.
  • description – Optional description for the interface. Defaults to nothing if not specified.
  • int_type – Type of interface; generally should be “vlan” for SVI’s. Defaults to vlan.
Returns:

True if object was changed.

configure_vsx(active_forwarding, vsx_sync, act_gw_mac, act_gw_ip)

Configure VSX IPv4 settings on a VLAN Interface.

Parameters:
  • active_forwarding – True or False Boolean to set VSX active forwarding.
  • vsx_sync – List of alphanumeric values to enable VSX configuration synchronization. The options are any combination of ‘active-gateways’, ‘irdp’, and ‘policies’. VSX Sync is mainly used in the Primary.
  • act_gw_mac – Alphanumeric value of the Virtual MAC address for the interface active gateway. Example: ‘01:02:03:04:05:06’
  • act_gw_ip – Alphanumeric value of the Virtual IP address for the interface active gateway. Example: ‘1.1.1.1’
Returns:

True if object was changed.

configure_vxlan(source_ipv4=None, description=None, dest_udp_port=4789)
Configure VXLAN table entry for a logical L3 Interface. If the VXLAN
Interface already exists and an IPv4 address is given, the function will update the IPv4 address.
Parameters:
  • source_ipv4 – Optional source IPv4 address to assign to the VXLAN interface. Defaults to nothing if not specified. Example: ‘1.1.1.1’.
  • description – Optional description for the interface. Defaults to nothing if not specified.
  • dest_udp_port – Optional Destination UDP Port that the VXLAN will use. Default is set to 4789.
Returns:

True if object was changed.

create()
Perform a POST call to create an Interface Object. Only returns if no
exception is raised.

:return True if entry was created inside Device.

delete()

Perform DELETE call to delete Interface table entry.

delete_ipv6_address(ip_address)

Given a IPv6 address, delete that address from the current Interface.

Parameters:ip_address – IPv6 address to assign to the interface. A Ipv6 object is also accepted. Example: ‘2001:db8::11/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff’.
delete_vlan(vlan)

Delete a VLAN from a trunk port.

Parameters:vlan – Numeric ID of VLAN to delete from the trunk port. A Vlan object is also accepted.
Returns:True if successfully deleted.
delete_vsx_configuration()

Delete VSX IPv4 settings on a VLAN Interface.

Returns:True if object was changed.
classmethod from_response(session, response_data)
Create an Interface object given a response_data related to the
Interface object.
Parameters:
  • cls – Object’s class.
  • session – pyaoscx.Session object used to represent a logical connection to the device.
  • response_data – The response must be a dictionary of the form: { “<interface_name>”: URL }, with URL: “/rest/v10.04/system/interfaces/<interface_name>”
Returns:

Interface object.

classmethod from_uri(session, uri)

Create an Interface object given a interface URI.

Parameters:
  • cls – Object’s class.
  • session – pyaoscx.Session object used to represent a logical connection to the device.
  • uri – a String with a URI.
Return name, interface_obj:
 

tuple containing both the Interface’s name and an Interface object.

get(depth=None, selector=None)

Perform a GET call to retrieve data for a Interface table entry.

Parameters:
  • depth – Integer deciding how many levels into the API JSON that references will be returned.
  • selector – Alphanumeric option to select specific information to return.
Returns:

Returns True if no exception is raised.

classmethod get_all(session)

Perform a GET call to retrieve all system Interfaces and create. a dictionary containing each Interface as a Interface Object.

Parameters:
  • cls – Object’s class.
  • session – pyaoscx.Session object used to represent a logical connection to the device.
Returns:

Dictionary containing Interface’s name as key and a Interface objects as values.

classmethod get_facts(session)

Perform a GET call to retrieve all Interfaces and their data.

Parameters:
  • cls – Class reference.
  • session – pyaoscx.Session object used to represent a logical connection to the device.
Return facts:

Dictionary containing Interface IDs as keys and Interface objects as values.

get_info_format()
Method used to obtain correct object format for referencing inside
other objects.

return: Object format depending on the API Version.

get_uri()

Method used to obtain the specific Interface URI.

return: Object’s URI.

indices = ['name']
initialize_interface_entry()

Initialize Interface to its default state.

Returns:True if object was changed.
ip6_addresses
Attribute descriptor class to keep track of a list that contains
pyaoscx_module objects simulating a Reference to a resource. If the list changes, then every pyaoscx_module object has to be changed.
modified
mtu
port_security_disable()

Disable port security on the specified interface.

Returns:True if the object was changed.
port_security_enable(client_limit=None, sticky_mac_learning=None, allowed_mac_addr=None, allowed_sticky_mac_addr=None, violation_action=None, violation_recovery_time=None, violation_shutdown_recovery_enable=None)

Enable port security on an specified Interface.

Parameters:
  • client_limit – Integer with the maximum amount of MAC addresses that can connect to the port.
  • sticky_mac_learning – Boolean, If sticky MAC learning should be enabled.
  • allowed_mac_addr – The list of allowed MAC addresses, each MAC address is a string, or a netaddr.EUI object.
  • allowed_sticky_mac_addr – A dictionary where each key is a MAC address (string or netaddr.EUI), and the value is a list of integers, where each integer is a VLAN id.
  • action (violation) – Action to take when unauthorized MACs try to connect.
  • violation_recovery_time – integer with Time in seconds to wait for recovery.
  • violation_shutdown_recovery_enable – Enable recovering from violation shut down.
Returns:

True if the object was changed.

remove_port_from_lag(interface)
Remove a Port from LAG, and also disable the port. Remove port from
list of interfaces inside Interface object.
Parameters:interface – Alphanumeric name of the interface. A Interface object is also accepted
Returns:True if object was changed.
resource_uri_name = 'interfaces'
set_active_gateway(ip_address, gateway_mac)

Update Active Gateway of a Interface.

Parameters:
  • ip_address – IPv4 address to assign to the interface. Example: ‘1.1.1.1’.
  • gateway_mac – Active Gateway MAC address to assign to the interface. Example: ‘01:02:03:04:05:06’.
Returns:

True if object was changed.

set_native_vlan(vlan, tagged=True)
Set a VLAN to be the native VLAN on the trunk. Also gives the option to
set the VLAN as tagged.
Parameters:
  • vlan – Numeric ID of VLAN to add to trunk port. A Vlan object is also accepted
  • tagged – Boolean to determine if True, the native VLAN will be set as the tagged VLAN. If False, the VLAN will be set as the native untagged VLAN. Defaults to True.
Returns:

True if object was changed.

set_untagged_vlan(vlan)

Set the untagged VLAN on an access port.

Parameters:vlan – Numeric ID of VLAN to set on access port. A Vlan object is also accepted.
Returns:True if object was changed.
set_vlan_mode(vlan_mode)
Set an L2 interface’s VLAN mode. The options are ‘native-tagged’,
‘native-untagged’, or ‘access’.
Parameters:vlan_mode – A string, either ‘native-tagged’, ‘native-untagged’, or ‘access’, specifying the desired VLAN mode.
Returns:True if object was changed.
update()
Perform a PUT call to apply changes to an existing Interface or Port
table entry.
Return modified:
 True if Object was modified and a PUT request was made.
update_acl_in(acl_name, list_type)
Perform GET and PUT calls to apply ACL on an interface. This function
specifically applies an ACL to Ingress traffic of the interface.
Parameters:
  • acl_name – Alphanumeric String that is the name of the ACL
  • list_type – Alphanumeric String of IPv4, IPv6 or MAC to specify the type of ACL.
Returns:

True if object was changed.

update_acl_out(acl_name, list_type)
Perform GET and PUT calls to apply ACL on an interface. This function
specifically applies an ACL to Egress traffic of the interface, which must be a routing interface.
Parameters:
  • acl_name – Alphanumeric String that is the name of the ACL.
  • list_type – Alphanumeric String of IPv4, IPv6 or MAC to specify the type of ACL.
Returns:

True if object was changed.

update_interface_qos(qos)

Update QoS attached to this Interface.

Parameters:qos – string to define a QoS to operate on this interface. Use None to remove the Qos attached to this interface.
Returns:True if object was changed.
update_interface_qos_rate(qos_rate)
Update the rate limit values configured for
broadcast/multicast/unknown unicast traffic.
Parameters:qos_rate – dict of the rate limit values; should have the format [‘<type of traffic>’] = <value><unit> e.g. { ‘unknown-unicast’: ‘100pps’, ‘broadcast’: 200pps, ‘multicast’: ‘200pps’ }.
Returns:True if object was changed.
update_interface_qos_trust_mode(qos_trust_mode, cos_override=None, dscp_override=None)

Update the QoS trust mode of this port.

Parameters:
  • qos_trust_mode – string to define the QoS trust mode for the interface. It can be either “cos”, “dscp” or “none”. To set the interface to use the global configuration use “global” instead.
  • cos_override – integer with the COS entry id to associate with the interface instead of automatic values. In range [0,7]
  • dscp_override – integer with the DSCP entry id to associate with the interface instead of the automatic values. In the range [0,63].
Returns:

True if object was changed.

update_interface_queue_profile(queue_profile)

Update the Queue Profile for this interface.

Parameters:queue_profile – Queue Profile name for this Interface. None is used to remove an existing Queue Profile.
Returns:True if object was changed.
update_ospf_interface_authentication(vrf, auth_type, digest_key, auth_pass)
Perform PUT calls to update an Interface with OSPF to have
authentication.
Parameters:
  • vrf – Alphanumeric name of the VRF the OSPF ID belongs to.
  • auth_type – Alphanumeric type of authentication, chosen between ‘md5’, ‘null’, and ‘text’.
  • digest_key – Integer between 1-255 that functions as the digest key for the authentication method.
  • auth_pass – Alphanumeric text for the authentication password. Note that this will be translated to a base64 String in the configuration and json.
Returns:

True if object was changed.

update_ospf_interface_type(vrf, interface_type='pointtopoint')
Update the Interface’s OSPFv2 type, as well as enable routing on the
interface.
Parameters:
  • vrf – Alphanumeric name of the VRF the OSPF ID belongs to.
  • interface_type – Alphanumeric type of OSPF interface. The options are ‘broadcast’, ‘loopback’, ‘nbma’, ‘none’, ‘pointomultipoint’, ‘pointopoint’, and ‘virtuallink’. Defaults to ‘pointtopoint’.
Returns:

True if object was changed.

was_modified()

Getter method for the __modified attribute.

Returns:Boolean True if the object was recently modified.