ncs.application Module
Module for building NCS applications.
Functions
get_device
get_device(node, name)
Get a device node by name.
Returns a maagic node representing a device.
Arguments:
node -- any maagic node with a Transaction backend or a Transaction object
name -- the device name (string)
Returns:
device node (maagic.Node)
get_ned_id
get_ned_id(device)
Get the ned-id of a device.
Returns the ned-id as a string or None if not found.
Arguments:
device -- a maagic node representing the device (maagic.Node)
Returns:
ned_id (str)
Classes
class Application
Class for easy implementation of an NCS application.
This class is intended to be sub-classed and used as a 'component class' inside an NCS package. It will be instantiated by NCS when the package is loaded. The setup() method should to be implemented to register service- and action callbacks. When NCS stops or an error occurs, teardown() will be called. A 'log' attribute is available for logging.
Example application:
from ncs.application import Application, Service, NanoService
from ncs.dp import Action, ValidationPoint
class FooService(Service):
@Service.create
def cb_create(self, tctx, root, service, proplist):
# service code here
class FooNanoService(NanoService):
@NanoService.create
def cb_nano_create(self, tctx, root, service, plan, component,
state, proplist, compproplist):
# service code here
class FooAction(Action):
@Action.action
def cb_action(self, uinfo, name, kp, input, output):
# action code here
class FooValidation(ValidationPoint):
@ValidationPoint.validate
def cb_validate(self, tctx, keypath, value, validationpoint):
# validation code here
class MyApp(Application):
def setup(self):
self.log.debug('MyApp start')
self.register_service('myservice-1', FooService)
self.register_service('myservice-2', FooService, 'init_arg')
self.register_nano_service('nano-1', 'myserv:router',
'myserv:ntp-initialized',
FooNanoService)
self.register_action('action-1', FooAction)
self.register_validation('validation-1', FooValidation)
def teardown(self):
self.log.debug('MyApp finish')
Application(*args, **kwds)
Initialize an Application object.
Not designed to be instantiated directly; these objects are created by NCS.
Members:
class NanoService
NanoService callback.
This class makes it easy to create and register nano service callbacks by subclassing it and implementing some of the nano service callbacks.
NanoService(daemon, servicepoint, componenttype, state, log=None, init_args=None)
Initialize this object.
The 'daemon' argument should be a Daemon instance. 'servicepoint' is the name of the tailf:servicepoint to manage. Argument 'log' can be any log object, and if not set the Daemon log will be used. 'init_args' may be any object that will be passed into init() when this object is constructed. Lastly, the low-level function dp.register_nano_service_cb() will be called.
When creating a service callback using Application.register_nano_service there is no need to manually initialize this object as it is then done automatically.
Members:
class PlanComponent
Service plan component.
The usage of this class is in conjunction with a service that uses a reactive FASTMAP pattern. With a plan the service states can be tracked and controlled.
A service plan can consist of many PlanComponent's. This is operational data that is stored together with the service configuration.
PlanComponent(planpath, name, component_type)
Initialize a PlanComponent.
Members:
class Service
Service callback.
This class makes it easy to create and register service callbacks by subclassing it and implementing some of the service callbacks.
Service(daemon, servicepoint, log=None, init_args=None)
Initialize this object.
The 'daemon' argument should be a Daemon instance. 'servicepoint' is the name of the tailf:servicepoint to manage. Argument 'log' can be any log object, and if not set the Daemon log will be used. 'init_args' may be any object that will be passed into init() when this object is constructed. Lastly, the low-level function dp.register_service_cb() will be called.
When creating a service callback using Application.register_service there is no need to manually initialize this object as it is then done automatically.
Members:
Last updated
Was this helpful?