Global Methods
set_global_vrf
Sets the global VRF. Any new sockets that are created (using socket.socket) will automatically be set to this VRF (including sockets used by other python libraries).
Note: a global method
set_global_vrf(vrf)
Example:
>>> from cisco.vrf import *
>>> set_global_vrf('management')
Arguments:
- vrf: VRF name (string) or the VRF ID (int).
Returns: Nothing
get_global_vrf
Gets the global VRF number
Note: a global method
get_global_vrf(vrf)
Example:
>>> from cisco.vrf import *
>>> get_global_vrf()
2
Arguments: None
Returns: VRF ID as an integer
VRF Class
Use this object to create or delete a VRF on the switch, to add or remove interfaces to a VRF or to check whether a VRF exists.
class VRF(object)
Example:
>>> from cisco.vrf import *
>>> vrf_instance = VRF('management')
Arguments:
- vrf: VRF name (string) or the VRF ID (int). If the VRF is specified as an integer only VRF values corresponding to an existing VRF will be accepted because it is not possible to create a VRF using an ID.
Returns: VRF object on success
get_vrf_id_by_name
Returns the VRF ID associated with the specified VRF name.
Note: a static method
get_vrf_id_by_name(target_vrf_name)
Example:
>>> vrf_instance.get_vrf_id_by_name("default")
1
Arguments:
- target_vrf_name: The VRF name whose ID number is to be found.
Returns:
- integer: The ID of the VRF associated with the specified VRF name.
Raises:
- ValueError: Invalid VRF name specified
get_vrf_name_by_id
Returns the VRF name associated with the specified VRF ID.
Note: a static method
get_vrf_name_by_id(target_vrf_id)
Example:
>>> vrf_instance.get_vrf_name_by_id(2)
'management'
Arguments:
- target_vrf_id: The VRF number whose name is to be found.
Returns:
- string: The name of the VRF associated with the specified VRF ID.
Raises:
- ValueError: Invalid VRF id specified
add_interface
Sets the VRF membership of the specified interface to this VRF.
add_interface(self, if_name, **args)
Example:
>>> vrf_instance = VRF('floor1')
>>> vrf_instance.create()
>>> vrf_instance.add_interface('Ethernet 1/1')
True
Arguments:
- if_name: A string specifying the interface name
Optional Arguments:
- no: A boolean, set to True to remove this VRF from the specified interface's VRF membership.
Returns: True on success
create
Creates a VRF
create(self, **args)
Example:
>>> vrf_instance = VRF('floor1')
>>> vrf_instance.create()
True
Arguments: None
Optional Arguments:
- no: A boolean, set to true to delete the VRF
Returns: True on success
delete
Deletes a VRF
delete(self)
Example:
>>> vrf_instance = VRF('floor1')
>>> vrf_instance.delete()
True
Arguments: None
Returns: True on success
exists
Checks whether this VRF exists.
exists(self)
Example:
>>> vrf_instance = VRF('floor1')
>>> if not vrf_instance.exists():
... vrf_instance.create()
...
True
Arguments: None
Returns:
- True if this VRF exists.
- False if it does not exist.
get_name
Gets the name of this VRF.
get_name(self)
Example:
>>> vrf_instance = VRF('floor1')
>>> vrf_instance.get_name()
floor1
Arguments: None
Returns: The name of this VRF as a string.
remove_interface
Removes this VRF from the VRF membership of the specified interface.
remove_interface(self, if_name)
Example:
>>> vrf_instance.delete_interface('Ethernet 1/1')
True
Arguments:
- if_name: A string specifying the interface name
Returns: True on success