acibaseobject module¶
This module implements the Base Class for creating all of the ACI Objects.
-
class
acitoolkit.acibaseobject.
BaseACIObject
(name=None, parent=None)¶ Bases:
acitoolkit.aciSearch.AciSearch
This class defines functionality common to all ACI objects. Functions may be overwritten by inheriting classes.
Constructor initializes the basic object and should be called by the init routines of inheriting subclasses.
Parameters: - name – String containing the name of the object instance
- parent – Parent object within the acitoolkit object model.
-
add_child
(obj)¶ Add a child to the children list.
Parameters: obj – Child object to add to the children list of the called object.
-
add_tag
(tag)¶ Assign this object a particular tag. Tags are strings that can be used to classify objects. More than 1 tag can be assigned to an object.
Parameters: tag – string containing the tag to assign to this object or an instance of _Tag
-
attach
(item)¶ Attach the object to the other object.
Parameters: item – Object to be attached.
-
static
check_session
(session)¶ This will check that the session is of type Session and raise exception if it not
Parameters: session – the session to check Returns:
-
delete_tag
(tag)¶ Mark a particular tag as being deleted from this object.
Parameters: tag – string containing the tag to delete from this object or an instance of _Tag
-
detach
(item)¶ Detach the object from the other object. A relationship is either ‘attached’, ‘detached’, or does not exist. A detached relationship will cause the relationship to be deleted when pushed to the APIC.
Parameters: item – Object to be detached.
-
find
(search_object)¶ This will check to see if self is a match with
search_object
and then call find on all of the children of search. If there is a match, a list containing self and any matches found by the children will be returned as a list.The criteria for a match is that all attributes of
self
are compared to all attributes of search_object. Ifsearch_object.<attr>
exists and is the same asself.<attr>
orsearch_object.<attr>
is ‘None’, then that attribute matches. If all such attributes match, then there is a match and self will be returned in the result.If there is an attribute of
search_object
that does not exist inself
, it will be considered a mismatch. If there is an attribute ofself
that does not exist insearch_object
, it will be ignored.Parameters: search_object – ACI object to search Returns: List of objects
-
classmethod
get
(session, toolkit_class, apic_class, parent=None, tenant=None, query_target_type='subtree')¶ Generic classmethod to get all of a particular APIC class.
Parameters: - session – the instance of Session used for APIC communication
- toolkit_class – acitoolkit class to return
- apic_class – String containing class name from the APIC object model.
- parent – Object to assign as the parent to the created objects.
- tenant – Tenant object to assign the created objects.
- query_target_type – type of the query either self,children,subtree
-
get_all_attached
(attached_class, status='attached', relation_type=None)¶ Get all of the relations of objects belonging to the specified class with the specified status.
Parameters: - attached_class – The class that is the subject of the search.
- status – Valid values are ‘attached’ and ‘detached’. Default is ‘attached’.
-
get_all_attachments
(attached_class, status='attached', relation_type=None)¶ Get all of the attachments to an object belonging to the specified class with the specified status.
Parameters: - attached_class – The class that is the subject of the search.
- status – Valid values are ‘attached’ and ‘detached’. Default is ‘attached’.
-
get_attributes
(name=None)¶ Will return the value of the named attribute in a dictionary format. If no name is given, then it will return all attributes.
Note that attributes that start with _ (underbar) will NOT be included unless explicitly named
This method should be over-written as appropriate by inheriting objects to handle how their local attributes are implemented.
This is intended to normalize how all attributes on all objects can be accessed since the implementations were not consistent.
Parameters: name – optional name of attribute to return Returns: dictionary of attributes and their values
-
get_child
(child_type, child_name)¶ Gets a specific immediate child of this object
Parameters: - child_type – Class of the child to return
- child_name – Name of the child to return
Returns: The specific instance of child_type or None if not found
-
get_children
(only_class=None)¶ Get a list of the immediate child objects of this object.
Parameters: only_class – Optional parameter that will be used to limit the objects returned to only those belonging to the class passed in this parameter. Returns: List of children objects.
-
classmethod
get_deep
(full_data, working_data, parent=None, limit_to=(), subtree='full', config_only=False)¶ Gets all instances of this class from the APIC and gets all of the children as well.
Parameters: - full_data –
- working_data –
- parent –
- limit_to –
- subtree –
- config_only –
-
classmethod
get_deep_apic_classes
(include_concrete=False)¶ Get all the apic classes needed for this acitoolkit class and all of its children. :return: list of all apic classes
-
get_dn_from_attributes
(attributes)¶ Will get the dn from the attributes or construct it using the dn of the parent plus the rn. Failing those, it will return None
Parameters: attributes – Returns: String containing dn or None
-
classmethod
get_event
(session)¶ Gets the event that is pending for this class. Events are returned in the form of objects. Objects that have been deleted are marked as such.
Parameters: session – the instance of Session used for APIC communication
-
classmethod
get_fault
(session, extension='')¶ Gets the fault that is pending for this class. Faults are returned in the form of objects. Objects that have been deleted are marked as such.
Parameters: session – the instance of Session used for APIC communication
-
get_from_json
(data, parent=None)¶ returns a Tenant object from a json
-
get_interfaces
(status='attached')¶ Get all of the interface relations. Note that multiple classes are considered “interfaces” such as Interface, L2Interface, L3Interface, etc.
Parameters: status – Valid values are ‘attached’ and ‘detached’. Default is ‘attached’. Returns: List of interfaces that this object has relations and the status matches.
-
get_json
(obj_class, attributes=None, children=None, get_children=True)¶ Get the JSON representation of this class in the actual APIC Object Model.
Parameters: - obj_class – Object Class Name within the APIC model.
- attributes – Additional attributes that should be set in the JSON.
- children – Children objects to traverse as well.
- get_children – Indicates whether the children objects should be included.
Returns: JSON dictionary to be pushed to the APIC.
-
get_parent
()¶ Returns: Parent of this object.
-
static
get_table
(aci_object, title='')¶ Abstract method that should be replaced by a version that is specific to the object
Parameters: - aci_object –
- title – String containing the table title
Returns: list of Table objects
Get the tags assigned to this object.
Returns: List of tag instances
-
has_attachment
(item)¶ Indicates whether this object is attached to the item/ :returns: True or False, True indicates the object is attached.
-
has_child
(obj)¶ Check for existence of a child in the children list
Parameters: obj – Child object that is the subject of the check. Returns: True or False, True indicates that it does indeed have the obj object as a child.
-
has_detachment
(item)¶ Indicates whether the object is detached from this item. :returns: True or False, True indicates the object is detached.
-
classmethod
has_events
(session, extension='')¶ Check for pending events from the APIC that pertain to instances of this class.
Parameters: session – the instance of Session used for APIC communication Returns: True or False. True if there are events pending.
-
has_parent
()¶ returns True if this object has a parent
Returns: bool
-
has_tag
(tag)¶ Checks whether this object has a particular tag assigned.
Parameters: tag – string containing the tag name or an instance of _Tag Returns: True or False. True indicates the object has this tag assigned.
Checks whether this object has any tags assigned at all.
Returns: True or False. True indicates the object has at least one tag assigned.
-
info
()¶ Node information summary.
Returns: Formatted string that has a summary of all of the info gathered about the node.
-
infoList
()¶ Node information. Returns a list of (attr, value) tuples.
Returns: list of [(attr, value),]
-
is_attached
(item)¶ Indicates whether the item is attached to this object/ :returns: True or False, True indicates the item is attached.
-
is_deleted
()¶ Check if the object has been deleted.
Returns: True or False, True indicates the object has been deleted.
-
is_detached
(item)¶ Indicates whether the item is detached from this object.
Returns: True or False, True indicates the item is detached.
-
static
is_interface
()¶ Indicates whether this object is considered an Interface. The default is False.
Returns: False
-
mark_as_deleted
()¶ Mark the object as deleted. This will cause the JSON status to be set to deleted.
-
classmethod
mask_class_from_graphs
()¶ Mask (hide) this class from graph creation
Returns: False indicating that this class should not be masked.
-
populate_children
(deep=False, include_concrete=False)¶ Populates all of the children and then calls populate_children of those children if deep is True. This method should be overridden by any object that does have children.
If include_concrete is True, then if the object has concrete objects below it, i.e. is a switch, then also populate those conrete object.
Parameters: - include_concrete – True or False. Default is False
- deep – True or False. Default is False.
-
remove_child
(obj)¶ Remove a child from the children list
Parameters: obj – Child object that is to be removed.
-
remove_tag
(tag)¶ Remove a particular tag from being assigned to this object. Note that this does not delete the tag from the APIC.
Parameters: tag – string containing the tag to remove from this object or an instance of _Tag
-
set_parent
(parent_obj)¶ Set the parent object
Parameters: parent_obj – Instance of the parent object Returns: None
-
classmethod
subscribe
(session, extension='', only_new=False)¶ Subscribe to events from the APIC that pertain to instances of this class.
Parameters: - session – the instance of Session used for APIC communication
- only_new – Boolean indicating whether to get all events or only the new events. All events (indicated by setting only_new to False) will queue a create event for all of the currently existing objects. Setting only_new to True will only queue events that occur after the initial subscribe. The default has only_new set to False.
-
subscribe_to_fault_instances_subtree
(session, extension='', deep=False)¶ Subscribe to faults instances for the whole subtree.
Parameters: - session – the instance of Session used for APIC communication
- extension – Optional string that can be used to extend the URL
- only_new – Boolean indicating whether to get all events or only the new events. All events (indicated by setting only_new to False) will queue a create event for all of the currently existing objects. Setting only_new to True will only queue events that occur after the initial subscribe. The default has only_new set to False.
-
classmethod
unsubscribe
(session)¶ Unsubscribe for events from the APIC that pertain to instances of this class.
Parameters: session – the instance of Session used for APIC communication
-
update_db
(session, subscribed_classes, deep=False)¶ Parameters: - session – Session class instance representing the connection to the APIC
- subscribed_classes – List of subscribed classes
- deep – Boolean indicating whether to go deep or not. Default is False
Returns: List of subscribed classes
-
class
acitoolkit.acibaseobject.
BaseACIPhysModule
(pod, node, slot, parent=None)¶ Bases:
acitoolkit.acibaseobject.BaseACIPhysObject
BaseACIPhysModule: base class for modules
Initialize the basic object. This should be called by the init routines of inheriting subclasses.
Parameters: - pod – pod id of module
- node – node id of module
- slot – slot id of module
- parent – optional parent object
-
classmethod
get_obj
(session, apic_classes, parent_node)¶ Gets all of the Nodes from the APIC. This is called by the module specific get() methods. The parameters passed include the APIC object class, apic_classes, so that this will work for different kinds of modules.
Parameters: - parent_node – parent object or node id
- session – APIC session to use when retrieving the nodes
- apic_classes – The object class in APIC to retrieve
Returns: list of module objects derived from the specified apic_classes
-
get_serial
()¶ Returns the serial number. :returns: serial number string
-
get_slot
()¶ Gets slot id
Returns: slot id
-
class
acitoolkit.acibaseobject.
BaseACIPhysObject
(name='', parent=None, pod=None)¶ Bases:
acitoolkit.acibaseobject.BaseACIObject
Base class for physical objects
-
add_child
(child_obj)¶ Add a child to the children list. All children must be unique so it will first delete the child if it already exists.
Parameters: child_obj – a child object to be added as a child to this object. This will be put into the _children list. Returns: None
-
classmethod
check_parent
(parent)¶ If a parent is specified, it will check that it is the correct class of parent If not, then an exception is raised. :param parent: :return:
-
classmethod
exists
(session, phys_obj)¶ Check if an apic phys_obj exists on the APIC. Returns True if the phys_obj does exist.
Parameters: - session – APIC session to use when accessing the APIC controller.
- phys_obj – The object that you are checking for.
Returns: True if the phys_obj exists, False if it does not.
-
get_children
(child_type=None)¶ Returns the list of children. If childType is provided, then it will return all of the children of the matching type.
Parameters: child_type – This optional parameter will cause this method to return only those children that match the type of childType. If this parameter is ommitted, then all of the children will be returned. Returns: list of children
-
classmethod
get_deep
(session, include_concrete=False)¶ Will return the atk object and the entire tree under it. :param session: APIC session to use :param include_concrete: flag to indicate that concrete objects should also be included :return:
-
get_json
()¶ Returns json representation of the object
Returns: JSON of contained Interfaces
-
get_name
()¶ Gets name.
Returns: Name string
-
get_node
()¶ Gets node id
Returns: id of node
-
get_pod
()¶ Gets pod_id :returns: id of pod
-
get_serial
()¶ Gets serial number.
Returns: serial number string
-
get_type
()¶ Gets physical object type
Returns: type string of the object.
-
static
get_url
(fmt='json')¶ Get the URL used to push the configuration to the APIC if no fmt parameter is specified, the format will be ‘json’ otherwise it will return ‘/api/mo/uni.’ with the fmt string appended.
Parameters: fmt – optional fmt string Returns: Nothing - physical objects are not modifiable
-
-
class
acitoolkit.acibaseobject.
BaseInterface
(name, parent=None)¶ Bases:
acitoolkit.acibaseobject.BaseACIObject
Abstract class used to provide base functionality to other Interface classes.
-
get_port_channel_selector_json
(port_name)¶ Get the JSON for the Port Channel selector
Parameters: port_name – String containing the port name Returns: Dictonary containing the JSON for the Port Channel selector
-
get_port_selector_json
()¶ Returns the port selector.
Returns:
-
static
is_dn_vpc
(dn)¶ Check if the DN is a VPC
Parameters: dn – String containing the DN Returns: True if the the DN is a VPC. False otherwise.
-
-
class
acitoolkit.acibaseobject.
BaseRelation
(item, status, relation_type=None)¶ Bases:
object
Class for all basic relations.
A relation consists of the following elements:
Parameters: - item – The object to which the relationship applies
- status – The status of the relationship. Valid values are ‘attached’ and ‘detached’
- relation_type – Optional additional information to distinguish the relationship. Used in cases where more than 1 type of relation exists.
-
is_attached
()¶ Returns: True or False indicating whether the relation is attached. If a relation is detached, it will be deleted from the APIC when the configuration is pushed.
-
is_detached
()¶ Returns: True or False indicating whether the relation is detached. If a relation is detached, it will be deleted from the APIC when the configuration is pushed.
-
set_as_detached
()¶ Sets the relation status to ‘detached’