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

Experimental stuff.
 
This module contains experimental and totally unsupported things that
may change or disappear at any time in the future. If used, it must be
explicitly imported.

 
Modules
       
confd.log
_confd
_confd.cdb
logging
confd.maagic
os
Queue
select
socket
sys
threading
confd.tm
traceback

 
Classes
       
__builtin__.object
DataCallbacks
Query
threading.Thread(threading._Verbose)
Subscriber
OperSubscriber
TwoPhaseSubscriber

 
class DataCallbacks(__builtin__.object)
    High-level API for implementing data callbacks.
 
Higher level abstraction for the DP API. Currently supports read
operations only, as such it is suitable for config false; data.
 
Registered callbacks are searched for in registration order. Most
specific points must be registered first.
 
args parameter to handler callbacks is a dictionary with keys
matching list names in the keypath. If multiple lists with the
same name exists the keys are named list-0, list-1 etc where 0 is
the top-most list with name list. Values in the dictionary are
python types (.as_pyval()), if the list has multiple keys it is
set as a list else the single key value is set.
 
Example args for keypath
/root/single-key-list{name}/conflict{first}/conflict{second}/multi{1 one}
 
    {'single-key-list': 'name',
     'conflict-0': 'first',
     'conflict-1': 'second',
     'multi': [1, 'one']}
 
Example handler and registration:
 
    class Handler(object):
        def get_object(self, kp, args):
            return {'leaf1': 'value', 'leaf2': 'value'}
 
        def get_next(self, kp, args, next):
            return None
 
        def count(self):
            return 0
 
    dcb = DataCallbacks(log)
    dcb.register('/namespace:container', Handler())
    _confd.dp.register_data_cb(dd.ctx(), example_ns.callpoint_handler, dcb)
 
  Methods defined here:
__init__(self, log)
cb_exists_optional(self, tctx, kp)
low-level cb_exists_optional implementation
cb_get_elem(self, tctx, kp)
low-level cb_elem implementation
cb_get_next(self, tctx, kp, next)
low-level cb_get_next implementation
cb_get_next_object(self, tctx, kp, next)
low-level cb_get_next_object implementation
cb_get_object(self, tctx, kp)
low-level cb_get_object implementation
cb_num_instances(self, tctx, kp)
low-level cb_num_instances implementation
register(self, path, handler)
Register data handler for path.
 
If handler is a type it will be instantiated with the DataCallbacks
log as the only parameter.
 
The following methods will be called on the handler:
 
    get_object(kp, args)
        Return single object as dictionary.
 
    get_next(kp, args, next)
        Return next object as dictionary, list of dictionaries can be
        returned to use result caching reducing the amount of calls
        required.
 
    count(kp, args)
        Return number of elements in list.

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

Data and other attributes defined here:
Pattern = <class 'confd.experimental.Pattern'>
Pattern matching key-path, internal to DataCallbacks
RegisterPoint = <class 'confd.experimental.RegisterPoint'>
Registered handler point, internal to DataCallbacks

 
class OperSubscriber(Subscriber)
    CDB Subscriber for oper data.
 
Use this class when subscribing on operational data. In all other means
the behavior is the same as for Subscriber().
 
 
Method resolution order:
OperSubscriber
Subscriber
threading.Thread
threading._Verbose
__builtin__.object

Methods defined here:
__init__(self, app=None, log=None, host='127.0.0.1', port=4565)
Initialize an OperSubscriber.

Methods inherited from Subscriber:
init(self)
Custom initialization.
 
Override this method to do custom initialization without needing
to override __init__.
register(self, path, iter_obj=None, iter_flags=1, priority=0, flags=0)
Register an iterator object at a specific path.
 
Setting 'iter_obj' to None will internally use 'self' as the iterator
object which means that Subscriber needs to be sub-classed.
run(self)
Main processing loop.
start(self)
Start the subscriber.
stop(self)
Stop the subscriber.

Methods inherited from threading.Thread:
__repr__(self)
getName(self)
isAlive(self)
isDaemon(self)
is_alive = isAlive(self)
join(self, timeout=None)
setDaemon(self, daemonic)
setName(self, name)

Data descriptors inherited from threading.Thread:
daemon
ident
name

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

 
class Query
    Class encapsulating a MAAPI query operation.
 
Supports the pattern of executing a query and iterating over the result
sets as they are requested. The class handles the calls to query_start,
query_result and query_stop, which means that one can focus on describing
the query and handle the result.
 
Example query:
 
with Query(trans, 'device', '/devices', ['name', 'address', 'port'],
           result_as=ncs.QUERY_TAG_VALUE) as q:
    for r in q:
        print(r)
 
  Methods defined here:
__enter__(self)
Python magic method.
__exit__(self, exc_type, exc_value, traceback)
Python magic method.
__init__(self, trans, expr, context_node, select, chunk_size=1000, initial_offset=1, result_as=3, sort=[])
Initialize a Query.
__iter__(self)
Return a query result iterator.
__next__(self)
Return next object.
next(self)
Get the next query result row.
stop(self)
Stop the running query.
 
Any resources associated with the query will be released.

 
class Subscriber(threading.Thread)
    CDB Subscriber for config data.
 
Supports the pattern of collecting changes and then handle the changes in
a separate thread. For each subscription point a handler object must be
registered. The following methods will be called on the handler:
 
    pre_iterate() (optional)
        Called just before iteration starts, may return a state object
        which will be passed on to the iterate method. If not implemented,
        the state object will be None.
 
    iterate(kp, op, oldv, newv, state) (mandatory)
        Called for each change in the change set.
 
    post_iterate(state) (optional)
        Runs in a separate thread once iteration has finished and the
        subscription socket has been synced. Will receive the final state
        object from iterate() as an argument.
 
    should_iterate() (optional)
        Called to check if the subscriber wants to iterate. If this method
        returns False, neither pre_iterate() nor iterate() will be called.
        Can e.g. be used by HA slaves to skip iteration. If not
        implemented, pre_iterate() and iterate() will always be called.
 
    should_post_iterate(state) (optional)
        Called to determine whether post_iterate() should be called
        or not. It is recommended to implement this method to prevent
        the subscriber from calling post_iterate() when not needed.
        Should return True if post_iterate() should run, otherwise False.
        If not implemented, post_iterate() will always be called.
 
Example iterator object:
 
    class MyIter(object):
        def pre_iterate(self):
            return []
 
        def iterate(self, kp, op, oldv, newv, state):
            if op is ncs.MOP_VALUE_SET:
                state.append(newv)
            return ncs.ITER_RECURSE
 
        def post_iterate(self, state):
            for item in state:
                print(item)
 
        def should_post_iterate(self, state):
            return state != []
 
The same handler may be registered for multiple subscription points.
In that case, pre_iterate() will only be called once, followed by iterate
calls for all subscription points, and finally a single call to
post_iterate().
 
 
Method resolution order:
Subscriber
threading.Thread
threading._Verbose
__builtin__.object

Methods defined here:
__init__(self, app=None, log=None, host='127.0.0.1', port=4565, subtype=1, name='')
Initialize a Subscriber.
init(self)
Custom initialization.
 
Override this method to do custom initialization without needing
to override __init__.
register(self, path, iter_obj=None, iter_flags=1, priority=0, flags=0)
Register an iterator object at a specific path.
 
Setting 'iter_obj' to None will internally use 'self' as the iterator
object which means that Subscriber needs to be sub-classed.
run(self)
Main processing loop.
start(self)
Start the subscriber.
stop(self)
Stop the subscriber.

Methods inherited from threading.Thread:
__repr__(self)
getName(self)
isAlive(self)
isDaemon(self)
is_alive = isAlive(self)
join(self, timeout=None)
setDaemon(self, daemonic)
setName(self, name)

Data descriptors inherited from threading.Thread:
daemon
ident
name

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

 
class TwoPhaseSubscriber(Subscriber)
    CDB Subscriber for config data with support for aborting transactions.
 
Subscriber that is capable of aborting transactions during the
prepare phase of a transaction.
 
The following methods will be called on the handler in addition to
the methods described in Subscriber:
 
prepare(kp, op, oldv, newv, state) (mandatory)
    Called in the transaction prepare phase. If an exception occurs
    during the invocation of prepare the transaction is aborted.
 
cleanup(state) (optional)
    Called after a prepare failure if available. Use to cleanup
    resources allocated by prepare.
 
abort(kp, op, oldv, newv, state) (mandatory)
    Called if another subscriber aborts the transaction and this
    transaction has been prepared.
 
Methods are called in the following order:
 
1. should_iterate -> pre_iterate ( -> cleanup, on exception)
2. should_iterate -> iterate -> post_iterate
3. should_iterate -> abort, if transaction is aborted by other subscriber
 
 
Method resolution order:
TwoPhaseSubscriber
Subscriber
threading.Thread
threading._Verbose
__builtin__.object

Methods defined here:
__init__(self, name, app=None, log=None, host='127.0.0.1', port=4565)
register(self, path, iter_obj=None, iter_flags=1, priority=0, flags=0)

Methods inherited from Subscriber:
init(self)
Custom initialization.
 
Override this method to do custom initialization without needing
to override __init__.
run(self)
Main processing loop.
start(self)
Start the subscriber.
stop(self)
Stop the subscriber.

Methods inherited from threading.Thread:
__repr__(self)
getName(self)
isAlive(self)
isDaemon(self)
is_alive = isAlive(self)
join(self, timeout=None)
setDaemon(self, daemonic)
setName(self, name)

Data descriptors inherited from threading.Thread:
daemon
ident
name

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