confd.maagic
index
/lab/build/tailf-src/confddoc.confdbasic.confd-6.4-x86_64/confd_dir/src/confd/pyapi/confd/maagic.py

Confd/NCS data access module.
 
This module implements classes and function for easy access to the data store.
There is no need to manually instantiate any of the classes herein. The only
functions that should be used are cd(), get_node() and get_root().

 
Modules
       
_confd
confd.childlist
collections
functools
confd.keypath
confd.maapi
numbers
sys
confd.tm

 
Classes
       
__builtin__.object
Enum
ListIterator
Node
Action
ActionParams
Case
Choice
Container
ListElement
PresenceContainer
Leaf
EmptyLeaf
NonEmptyLeaf
List
Root
exceptions.Exception(exceptions.BaseException)
BackendError
MaagicError

 
class Action(Node)
    Represents a tailf:action node.
 
 
Method resolution order:
Action
Node
__builtin__.object

Methods defined here:
__call__(self, params=None)
Make object callable. Calls request().
__init__(self, backend, cs_node, parent=None)
Initialize an Action node. Should not be called explicitly.
__repr__(self)
Get internal representation.
get_input(self)
Return a node tree representing the input node of this action.
get_output(self)
Return a node tree representing the output node of this action.
 
Note that this does not actually request the action.
Should not normally be called explicitly.
request(self, params=None)
Request the action and return the result as an ActionParams node.
 
Arguments:
params -- input parameters of the action (optional)

Methods inherited from Node:
__delattr__(self, name)
Python magic method.
__delitem__(self, name)
Python magic method.
__dir__(self)
Return a list of children available under this Node.
__getattr__(self, name)
Python magic method.
__getitem__(self, name)
Python magic method.
__int__(self)
Return the tag value of this node in the schema.
__iter__(self)
Iterate over children names under this Node.
__setattr__(self, name, value)
Python magic method.
__setitem__(self, name, value)
Python magic method.
__str__(self)
Return the name of this node in the schema.

Data descriptors inherited from Node:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class ActionParams(Node)
    Represents the input or output parameters of a tailf:action.
 
The ActionParams node is the root of a tree representing either the input
or the output parameters of an action. Action parameters can be read and
set just like any other nodes in the tree.
 
 
Method resolution order:
ActionParams
Node
__builtin__.object

Methods defined here:
__init__(self, cs_node, parent, output=False)
Initialize an ActionParams node.
 
Should not be called explicitly. Use 'get_input()' on an Action node
to retrieve its input parameters or 'request()' to request the action
and obtain the output parameters.

Methods inherited from Node:
__delattr__(self, name)
Python magic method.
__delitem__(self, name)
Python magic method.
__dir__(self)
Return a list of children available under this Node.
__getattr__(self, name)
Python magic method.
__getitem__(self, name)
Python magic method.
__int__(self)
Return the tag value of this node in the schema.
__iter__(self)
Iterate over children names under this Node.
__setattr__(self, name, value)
Python magic method.
__setitem__(self, name, value)
Python magic method.
__str__(self)
Return the name of this node in the schema.

Data descriptors inherited from Node:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class BackendError(exceptions.Exception)
    Exception type used within maagic backends.
 
 
Method resolution order:
BackendError
exceptions.Exception
exceptions.BaseException
__builtin__.object

Data descriptors defined here:
__weakref__
list of weak references to the object (if defined)

Methods inherited from exceptions.Exception:
__init__(...)
x.__init__(...) initializes x; see help(type(x)) for signature

Data and other attributes inherited from exceptions.Exception:
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T

Methods inherited from exceptions.BaseException:
__delattr__(...)
x.__delattr__('name') <==> del x.name
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__getslice__(...)
x.__getslice__(i, j) <==> x[i:j]
 
Use of negative indices is not supported.
__reduce__(...)
__repr__(...)
x.__repr__() <==> repr(x)
__setattr__(...)
x.__setattr__('name', value) <==> x.name = value
__setstate__(...)
__str__(...)
x.__str__() <==> str(x)
__unicode__(...)

Data descriptors inherited from exceptions.BaseException:
__dict__
args
message

 
class Case(Node)
    Represents a case node.
 
If this case node has any nested choice nodes, those will appear as
children of this object.
 
 
Method resolution order:
Case
Node
__builtin__.object

Methods defined here:
__eq__(self, other)
Check for equality.
 
Case node is considered equal to the following objects:
- Any number type object that matches the tag value of this case
- Any string object that matches the yang name of this case
- Any object with string and int representations that both match those
  of this case.
__init__(self, backend, cs_node, cs_case, parent)
Initialize a Case node. Should not be called explicitly.
__int__(self)
Get int representation (tag value).
__ne__(self, other)
Check for inequality.
__repr__(self)
Get internal representation.
__str__(self)
Get string representation.

Methods inherited from Node:
__delattr__(self, name)
Python magic method.
__delitem__(self, name)
Python magic method.
__dir__(self)
Return a list of children available under this Node.
__getattr__(self, name)
Python magic method.
__getitem__(self, name)
Python magic method.
__iter__(self)
Iterate over children names under this Node.
__setattr__(self, name, value)
Python magic method.
__setitem__(self, name, value)
Python magic method.

Data descriptors inherited from Node:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class Choice(Node)
    Represents a choice node.
 
 
Method resolution order:
Choice
Node
__builtin__.object

Methods defined here:
__init__(self, backend, cs_node, cs_choice, parent)
Initialize a Choice node. Should not be called explicitly.
__int__(self)
Get int representation (tag value).
__repr__(self)
Get internal representation.
__str__(self)
Get string representation.
get_value(self)
Return the currently selected case of this choice.
 
The case is returned as a Case node. If no case is selected for this
choice, None is returned.

Methods inherited from Node:
__delattr__(self, name)
Python magic method.
__delitem__(self, name)
Python magic method.
__dir__(self)
Return a list of children available under this Node.
__getattr__(self, name)
Python magic method.
__getitem__(self, name)
Python magic method.
__iter__(self)
Iterate over children names under this Node.
__setattr__(self, name, value)
Python magic method.
__setitem__(self, name, value)
Python magic method.

Data descriptors inherited from Node:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class Container(Node)
    Represents a yang container.
 
A (non-presence) container node or a list element, contains other nodes.
 
 
Method resolution order:
Container
Node
__builtin__.object

Methods defined here:
__init__(self, backend, cs_node, parent=None)
Initialize Container node. Should not be called explicitly.
__repr__(self)
Get internal representation.
delete(self)
Delete the container.
 
Deletes all nodes inside the container. The container itself is not
affected as it carries no state of its own.

Methods inherited from Node:
__delattr__(self, name)
Python magic method.
__delitem__(self, name)
Python magic method.
__dir__(self)
Return a list of children available under this Node.
__getattr__(self, name)
Python magic method.
__getitem__(self, name)
Python magic method.
__int__(self)
Return the tag value of this node in the schema.
__iter__(self)
Iterate over children names under this Node.
__setattr__(self, name, value)
Python magic method.
__setitem__(self, name, value)
Python magic method.
__str__(self)
Return the name of this node in the schema.

Data descriptors inherited from Node:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class EmptyLeaf(Leaf)
    Represents a leaf with the type "empty".
 
 
Method resolution order:
EmptyLeaf
Leaf
Node
__builtin__.object

Methods defined here:
__bool__(self)
Return True if this leaf exists in the data tree.
__init__(self, backend, cs_node, parent=None)
Initialize an EmptyLeaf node. Should not be called explicitly.
__nonzero__(self)
Return True if this leaf exists in the data tree.
create(self)
Create and return this leaf in the data tree.
delete(self)
Delete this leaf from the data tree.
exists(self)
Return True if this leaf exists in the data tree.

Methods inherited from Leaf:
__repr__(self)
Get internal representation.

Methods inherited from Node:
__delattr__(self, name)
Python magic method.
__delitem__(self, name)
Python magic method.
__dir__(self)
Return a list of children available under this Node.
__getattr__(self, name)
Python magic method.
__getitem__(self, name)
Python magic method.
__int__(self)
Return the tag value of this node in the schema.
__iter__(self)
Iterate over children names under this Node.
__setattr__(self, name, value)
Python magic method.
__setitem__(self, name, value)
Python magic method.
__str__(self)
Return the name of this node in the schema.

Data descriptors inherited from Node:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class Enum(__builtin__.object)
    Simple represention of a yang enumeration instance.
 
Contains the string and integer representation of the enumeration.
An Enum object supports comparisons with other 'Enum' objects as well as
with other objects. For equality checks, strings, numbers, 'Enum' objects
and 'Value' objects are allowed. For relational operators,
all of the above except strings are acceptable.
 
Attributes:
string -- string representation of the enumeration
value -- integer representation of the enumeration
 
  Methods defined here:
__eq__(self, other)
Check enumeration for equality with another object.
 
The enumeraion is considered equal to the other object if one of the
following is true:
- 'other' is a number type and is equal to 'self.value'
- 'other' is a string and is equal to 'self.string'
- 'other' is a 'Value' object of type ENUM and its value value
  is equal to 'self.value'
- 'other' is also an 'Enum' and has the same string and value
  attributes as self
__ge__(self, other)
x.__ge__(y) <==> x>=y
__gt__(self, other)
x.__gt__(y) <==> x>y
__init__(self, string, value)
Initialize an Enum object from a given string and integer.
 
Note that an Enum object has no connection to the yang model and will
not check that the given value matches the string representation
according to the schema. Normally it is not necessary to create
Enum objects using this constructor as enum leaves can be set using
strings alone.
 
Arguments:
string -- string representation of the enumeration
value -- integer representation of the enumeration
__int__(self)
Return the integer representation of the enumeration.
__le__(self, other)
x.__le__(y) <==> x<=y
__lt__(self, other)
Compare enumeration to another object.
 
The value attribute of the enumeration is compared to one of the
following (the first one that is applicable):
- 'other' itself if 'other' is a number
- 'int(other)' if 'other' is a Value object
- 'other.value' if 'other' is an Enum object
__ne__(self, other)
Check for inequality.
__repr__(self)
Get internal representation.
__str__(self)
Return the string representation of the enumeration.

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class Leaf(Node)
    Base class for leaf nodes, subclassed by NonEmptyLeaf and EmptyLeaf.
 
 
Method resolution order:
Leaf
Node
__builtin__.object

Methods defined here:
__init__(self, backend, cs_node, parent=None)
Initialize Leaf node. Should not be called explicitly.
__repr__(self)
Get internal representation.
delete(self)
Delete this leaf from the data tree.

Methods inherited from Node:
__delattr__(self, name)
Python magic method.
__delitem__(self, name)
Python magic method.
__dir__(self)
Return a list of children available under this Node.
__getattr__(self, name)
Python magic method.
__getitem__(self, name)
Python magic method.
__int__(self)
Return the tag value of this node in the schema.
__iter__(self)
Iterate over children names under this Node.
__setattr__(self, name, value)
Python magic method.
__setitem__(self, name, value)
Python magic method.
__str__(self)
Return the name of this node in the schema.

Data descriptors inherited from Node:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class List(Node)
    Represents a list node.
 
A list can be treated mostly like a python dictionary. It supports
indexing, iteration, the len function, and the in and del operators.
New items must, however, be created explicitly using the 'create' method.
 
 
Method resolution order:
List
Node
__builtin__.object

Methods defined here:
__contains__(self, keys)
Check if list has an item matching 'keys'.
 
Called when checking for existence using 'in' and 'not in'.
__delitem__(self, keys)
Delete list item matching 'keys'.
 
Called when deleting an item from the list. Example:
    del mylist['key1']
__getitem__(self, keys)
Get a specific list item.
 
Get a specific item from the list using [] notation.
Return a ListElement representing the contents of the list at 'keys'.
__init__(self, backend, cs_node, parent=None)
Initialize a List node. Should not be called explicitly.
__iter__(self)
Python magic method.
 
Return an iterator for the list. This method will be called e.g.
when iterating the list like this:
    for item in mylist: ...
__len__(self)
Get the length of the list.
 
Called when using 'len'.
__repr__(self)
Get internal representation.
__setitem__(self, key, value)
Raise an error.
create(self, *keys)
Create and return a new list item with the key '*keys'.
 
Arguments can be a single 'maapi.Key' object or one value for each key
in the list. For a keyless in-memory list (eg in action parameters),
no argument should be given.
delete(self)
Delete the entire list.
exists(self, keys)
Check if list has an item matching 'keys'.
keys(self)
Return all keys in the list.
 
Note that this will immediately retrieve every key value from the CDB.
For a long list this could be a time-consuming operation.
 
Not available for in-memory lists.
move(self, key, where, to=None)
Move the item with key 'key' in an ordered-by user list.
 
The destination is given by the arguments 'where' and 'to'.
 
Arguments:
key -- key of the element that is to be moved
where -- one of '_ncs.maapi.BEFORE', '_ncs.maapi.AFTER',
         '_ncs.maapi.FIRST', or '_ncs.maapi.LAST'
 
Keyword arguments:
to -- key of the destination item for relative moves, only applicable
      if 'where' is either 'BEFORE' or 'AFTER'.

Methods inherited from Node:
__delattr__(self, name)
Python magic method.
__dir__(self)
Return a list of children available under this Node.
__getattr__(self, name)
Python magic method.
__int__(self)
Return the tag value of this node in the schema.
__setattr__(self, name, value)
Python magic method.
__str__(self)
Return the name of this node in the schema.

Data descriptors inherited from Node:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class ListElement(Container)
    Represents a list element.
 
This is a Container object with a specialized __repr__() method.
 
 
Method resolution order:
ListElement
Container
Node
__builtin__.object

Methods defined here:
__repr__(self)
Get internal representation.

Methods inherited from Container:
__init__(self, backend, cs_node, parent=None)
Initialize Container node. Should not be called explicitly.
delete(self)
Delete the container.
 
Deletes all nodes inside the container. The container itself is not
affected as it carries no state of its own.

Methods inherited from Node:
__delattr__(self, name)
Python magic method.
__delitem__(self, name)
Python magic method.
__dir__(self)
Return a list of children available under this Node.
__getattr__(self, name)
Python magic method.
__getitem__(self, name)
Python magic method.
__int__(self)
Return the tag value of this node in the schema.
__iter__(self)
Iterate over children names under this Node.
__setattr__(self, name, value)
Python magic method.
__setitem__(self, name, value)
Python magic method.
__str__(self)
Return the name of this node in the schema.

Data descriptors inherited from Node:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class ListIterator(__builtin__.object)
    List iterator.
 
An instance of this class will be returned when iterating a list.
 
  Methods defined here:
__del__(self)
Destructor. Destroy internal object.
__enter__(self)
Context manger entry point.
__exit__(self, type_, value, tb)
Context manger exit point.
__init__(self, l)
Initialize this object.
 
An instance of this class will be created when iteration of a
list starts. Should not be called explicitly.
__iter__(self)
Return iterator (which is self).
__next__(self)
Iterator next.
delete(self)
Delete the iterator.
next(self)
Get the next value from the iterator.

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class MaagicError(exceptions.Exception)
    Exception type used within maagic.
 
 
Method resolution order:
MaagicError
exceptions.Exception
exceptions.BaseException
__builtin__.object

Data descriptors defined here:
__weakref__
list of weak references to the object (if defined)

Methods inherited from exceptions.Exception:
__init__(...)
x.__init__(...) initializes x; see help(type(x)) for signature

Data and other attributes inherited from exceptions.Exception:
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T

Methods inherited from exceptions.BaseException:
__delattr__(...)
x.__delattr__('name') <==> del x.name
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__getslice__(...)
x.__getslice__(i, j) <==> x[i:j]
 
Use of negative indices is not supported.
__reduce__(...)
__repr__(...)
x.__repr__() <==> repr(x)
__setattr__(...)
x.__setattr__('name', value) <==> x.name = value
__setstate__(...)
__str__(...)
x.__str__() <==> str(x)
__unicode__(...)

Data descriptors inherited from exceptions.BaseException:
__dict__
args
message

 
class Node(__builtin__.object)
    Base class of all nodes in the configuration tree.
 
Contains magic overrides that make children in the yang tree appear as
attributes of the Node object and as elements in the list 'self'.
 
Attributes:
_name -- the yang name of this node
_path -- the keypath of this node in string form
_parent -- the parent of this node (or None if this node has no parent)
_cs_node -- the schema node of this node (or None if this node is not in
            the schema)
 
  Methods defined here:
__delattr__(self, name)
Python magic method.
__delitem__(self, name)
Python magic method.
__dir__(self)
Return a list of children available under this Node.
__getattr__(self, name)
Python magic method.
__getitem__(self, name)
Python magic method.
__init__(self, backend, cs_node, parent=None, is_root=False)
Initialize a Node object. Should not be called explicitly.
__int__(self)
Return the tag value of this node in the schema.
__iter__(self)
Iterate over children names under this Node.
__setattr__(self, name, value)
Python magic method.
__setitem__(self, name, value)
Python magic method.
__str__(self)
Return the name of this node in the schema.

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class NonEmptyLeaf(Leaf)
    Represents a leaf with a type other than "empty".
 
 
Method resolution order:
NonEmptyLeaf
Leaf
Node
__builtin__.object

Methods defined here:
__bool__(self)
Return true if this leaf exists in the data tree.
__init__(self, backend, cs_node, parent=None)
Initialize a NonEmptyLeaf node. Should not be called explicitly.
__nonzero__(self)
Return true if this leaf exists in the data tree.
__repr__(self)
Get internal representation.
delete(self)
Delete this leaf from the data tree.
exists(self)
Check if leaf exists.
 
Return True if this leaf exists (has a value) in the data tree.
get_value(self)
Return the value of this leaf.
 
The value is returned as the most appropriate python data type.
get_value_object(self)
Return the value of this leaf as a Value object.
set_cache(self, value)
Set the cached value of this leaf without updating the data tree.
 
Use of this method is strongly discouraged.
set_value(self, value)
Set the value of this leaf.
 
Arguments:
value -- the value to be set. If 'value' is not a Value object, it will
         be converted to one using Value.str2val.
update_cache(self, force=False)
Read this leaf's value from the data tree and store it in the cache.
 
There is no need to call this method explicitly.

Methods inherited from Node:
__delattr__(self, name)
Python magic method.
__delitem__(self, name)
Python magic method.
__dir__(self)
Return a list of children available under this Node.
__getattr__(self, name)
Python magic method.
__getitem__(self, name)
Python magic method.
__int__(self)
Return the tag value of this node in the schema.
__iter__(self)
Iterate over children names under this Node.
__setattr__(self, name, value)
Python magic method.
__setitem__(self, name, value)
Python magic method.
__str__(self)
Return the name of this node in the schema.

Data descriptors inherited from Node:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class PresenceContainer(Container)
    Represents a presence container.
 
 
Method resolution order:
PresenceContainer
Container
Node
__builtin__.object

Methods defined here:
__bool__(self)
Return true if this presence container exists in the data tree.
__init__(self, backend, cs_node, parent=None)
Initialize a PresenceContainer. Should not be called explicitly.
__nonzero__(self)
Return true if this presence container exists in the data tree.
__repr__(self)
Get internal representation.
create(self)
Create and return this presence container in the data tree.
delete(self)
Delete this presence container from the data tree.
exists(self)
Return true if the presence container exists in the data tree.

Methods inherited from Node:
__delattr__(self, name)
Python magic method.
__delitem__(self, name)
Python magic method.
__dir__(self)
Return a list of children available under this Node.
__getattr__(self, name)
Python magic method.
__getitem__(self, name)
Python magic method.
__int__(self)
Return the tag value of this node in the schema.
__iter__(self)
Iterate over children names under this Node.
__setattr__(self, name, value)
Python magic method.
__setitem__(self, name, value)
Python magic method.
__str__(self)
Return the name of this node in the schema.

Data descriptors inherited from Node:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class Root(Node)
    Represents the root node in the configuration tree.
 
The root node is not represented in the schema, it is added for convenience
and can contain the top level nodes from any number of namespaces as
children.
 
 
Method resolution order:
Root
Node
__builtin__.object

Methods defined here:
__init__(self, backend=None, namespaces=None)
Initialize a Root node.
 
Should not be called explicitly. Instead, use the function
'get_root()'.
 
Arguments:
backend -- backend to use, or 'None' for an in-memory tree
namespaces -- which namespaces to include in the tree
__int__(self)
Return the number 0.
__repr__(self)
Get internal representation.
__str__(self)
Return the string "(root)".

Methods inherited from Node:
__delattr__(self, name)
Python magic method.
__delitem__(self, name)
Python magic method.
__dir__(self)
Return a list of children available under this Node.
__getattr__(self, name)
Python magic method.
__getitem__(self, name)
Python magic method.
__iter__(self)
Iterate over children names under this Node.
__setattr__(self, name, value)
Python magic method.
__setitem__(self, name, value)
Python magic method.

Data descriptors inherited from Node:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
Functions
       
as_pyval(mobj, name_type=3, include_oper=False, enum_as_string=True)
Convert maagic object to python value.
 
The types are converted as follows:
 
    * List is converted to list.
    * Container is converted to to dict.
    * Leaf is converted to python value.
    * EmptyLeaf is converted to bool.
 
name_type is one of NODE_NAME_SHORT, NODE_NAME_FULL,
NODE_NAME_PY_SHORT and NODE_NAME_PY_FULL and controls dictionary
key names.
 
If include_oper is False and and a oper Node is
passed None is returned.
cd(node, path)
Return the node at path 'path', starting from node 'node'.
 
Arguments:
path -- relative or absolute keypath as a string, 'HKeypathRef' or
        a 'Nodeobject
get_node(backend, path, shared=False)
Return the node at path 'path' using 'backend'.
 
Arguments:
backend -- Transaction object, Maapi object or None
path -- relative or absolute keypath as a string, 'HKeypathRef' or
        a 'Nodeobject
shared -- if set to 'True', fastmap-friendly maapi calls, such as
          shared_set_elem, will be used within the returned tree.
get_root(backend=None, shared=False)
Return a Root object for 'backend'.
 
If 'backend' is a Transaction object, the returned Maagic object can be
used to read and write transactional data. When 'backend' is a Maapi
object you cannot read and write data, however, you may use the Maagic
object to call an action (that doesn't require a transaction).
'backend' may also be None (default) in which case the returned Maagic
object is not connected to NCS in any way. You can still use the maagic
object to build an in-memory tree which may be converted to an array
of TagValue objects.
 
Arguments:
backend -- Transaction object, Maapi object or None
shared -- if set to 'True', fastmap-friendly maapi calls, such as
          shared_set_elem, will be used within the returned tree.

 
Data
        NODE_NAME_FULL = 0
NODE_NAME_PY_FULL = 2
NODE_NAME_PY_SHORT = 3
NODE_NAME_SHORT = 1