acibaseobject module

This module implements the Base Class for creating all of the ACI Objects.

class acitoolkit.acibaseobject.BaseACIObject(name, parent=None)

Bases: object

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
attach(item)

Attach the object to the other object.

Parameters:item – Object to be attached.
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. If search_object.<attr> exists and is the same as self.<attr> or search_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 in self, it will be considered a mismatch. If there is an attribute of self that does not exist in search_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)

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.
get_all_attached(attached_class, status='attached')

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')

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_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)

Gets all instances of this class from the APIC and gets all of the children as well.

Parameters:
  • full_data
  • working_data
  • parent
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
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.
get_tags()

Get the tags assigned to this object.

Returns:List of tag strings
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)

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_tag(tag)

Checks whether this object has a particular tag assigned.

Parameters:tag – string containing the tag
Returns:True or False. True indicates the object has this tag assigned.
has_tags()

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.

populate_children(deep=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

Parameters: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.

Parameters:tag – string containing the tag to assign to this object
classmethod subscribe(session)

Subscribe to events from the APIC that pertain to instances of this class.

Parameters:session – the instance of Session used for APIC communication
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
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’