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:

Initialize an Application object.

Not designed to be instantiated directly; these objects are created by NCS.

Members:

chevron-rightAPP_WORKER_STOP_TIMEOUT_Shashtag
chevron-rightadd_running_thread(...)hashtag

Method:

chevron-rightcreate_daemon(...)hashtag

Method:

Name the underlying dp.Daemon object (deprecated)

chevron-rightcritical(...)hashtag

Method:

chevron-rightdebug(...)hashtag

Method:

chevron-rightdel_running_thread(...)hashtag

Method:

chevron-righterror(...)hashtag

Method:

chevron-rightexception(...)hashtag

Method:

chevron-rightinfo(...)hashtag

Method:

chevron-rightreg_finish(...)hashtag

Method:

chevron-rightregister_action(...)hashtag

Method:

Register an action callback class.

Call this method to register 'action_cls' as the action callback class for action point 'actionpoint'. 'action_cls' should be a subclass of dp.Action. If the optional argument 'init_args' is supplied it will be passed in to the init() method of the subclass.

Arguments:

  • actionpoint -- actionpoint (str)

  • action_cls -- action callback class

  • init_args -- initial arguments (optional)

chevron-rightregister_fun(...)hashtag

Method:

Register custom start and stop functions.

Call this method to register a start and stop function that will be called with a dp.Daemon.State during application setup.

Example start and stop functions:

Arguments:

  • start_fun -- start function (fun)

  • stop_fun -- stop function (fun)

chevron-rightregister_nano_service(...)hashtag

Method:

Register a nano service callback class.

Call this method to register 'nano_service_cls' as the nano service callback class for service point 'servicepoint'. 'nano service_cls' should be a subclass of NanoService. If the optional argument 'init_args' is supplied it will be passed in to the init() method of the subclass.

Arguments:

  • servicepoint -- servicepoint (str)

  • componenttype -- nano plan component(str)

  • state -- nano plan state (str)

  • service_cls -- service callback class

  • init_args -- initial arguments (optional)

chevron-rightregister_service(...)hashtag

Method:

Register a service callback class.

Call this method to register 'service_cls' as the service callback class for service point 'servicepoint'. 'service_cls' should be a subclass of Service. If the optional argument 'init_args' is supplied it will be passed in to the init() method of the subclass.

Arguments:

  • servicepoint -- servicepoint (str)

  • service_cls -- service callback class

  • init_args -- initial arguments (optional)

chevron-rightregister_trans_cb(...)hashtag

Method:

Register a transaction callback class.

If a custom transaction callback implementation is needed, call this method with the transaction callback class as the 'trans_cb_cls' argument.

Arguments:

  • trans_cb_cls -- transaction callback class

chevron-rightregister_validation(...)hashtag

Method:

Register a validation callback class.

Call this method to register 'validation_cls' as the validation callback class for validation point 'validationpoint'. 'validation_cls' should be a subclass of ValidationPoint. If the optional argument 'init_args' is supplied it will be passed in to the init() method of the subclass.

Arguments:

  • validationpoint -- validationpoint (str)

  • validation_cls -- validation callback class

  • init_args -- initial arguments (optional)

chevron-rightset_log_level(...)hashtag

Method:

Set log level for all workers (only relevant for _ProcessAppWorker)

Arguments:

  • log_level -- logging level, using logging.Logger (int)

chevron-rightset_self_assign_warning(...)hashtag

Method:

Set self assign warning for all workers.

Arguments:

  • warning -- warning type (alarm, log, off). (string)

chevron-rightsetup(...)hashtag

Method:

Application setup method.

Override this method to register actions and services. Any other initialization could also be done here. If the call to this method throws an exception the teardown method will be immediately called and the application shutdown.

chevron-rightteardown(...)hashtag

Method:

Application teardown method.

Override this method to clean up custom resources allocated in setup().

chevron-rightunreg_finish(...)hashtag

Method:

chevron-rightwarning(...)hashtag

Method:

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.

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:

chevron-rightcreate(...)hashtag

Static method:

Decorator for the cb_nano_create callback.

Using this decorator alters the signature of the cb_create callback and passes in maagic.Node objects for root and service. The maagic.Node objects received in 'root' and 'service' are backed by a MAAPI connection with the FASTMAP handle attached. To update 'proplist' simply return it from this function.

Example of a decorated cb_create:

Callback arguments:

  • tctx - transaction context (TransCtxRef)

  • root -- root node (maagic.Node)

  • service -- service node (maagic.Node)

  • plan -- current plan node (maagic.Node)

  • component -- plan component active for this invokation

  • state -- plan component state active for this invokation

  • proplist - properties (list(tuple(str, str)))

  • compproplist - component properties (list(tuple(str, str)))

chevron-rightdelete(...)hashtag

Static method:

Decorator for the cb_nano_delete callback.

Using this decorator alters the signature of the cb_delete callback and passes in maagic.Node objects for root and service. The maagic.Node objects received in 'root' and 'service' are backed by a MAAPI connection with the FASTMAP handle attached. To update 'proplist' simply return it from this function.

Example of a decorated cb_create:

Callback arguments:

  • tctx - transaction context (TransCtxRef)

  • root -- root node (maagic.Node)

  • service -- service node (maagic.Node)

  • plan -- current plan node (maagic.Node)

  • component -- plan component active for this invokation

  • state -- plan component state active for this invokation

  • proplist - properties (list(tuple(str, str)))

  • compproplist - component properties (list(tuple(str, str)))

chevron-rightinit(...)hashtag

Method:

Custom initialization.

When registering a service using Application this method will be called with the 'init_args' passed into the register_service() function.

chevron-rightmaapihashtag

Readonly property

chevron-rightstart(...)hashtag

Method:

Start NanoService

chevron-rightstop(...)hashtag

Method:

Stop NanoService

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.

Initialize a PlanComponent.

Members:

chevron-rightappend_state(...)hashtag

Method:

Append a new state to this plan component.

The state status will be initialized to 'ncs:not-reached'.

chevron-rightset_failed(...)hashtag

Method:

Set state status to 'ncs:failed'.

chevron-rightset_reached(...)hashtag

Method:

Set state status to 'ncs:reached'.

chevron-rightset_status(...)hashtag

Method:

Set state status.

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.

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:

chevron-rightcreate(...)hashtag

Static method:

Decorator for the cb_create callback.

Using this decorator alters the signature of the cb_create callback and passes in maagic.Node objects for root and service. The maagic.Node objects received in 'root' and 'service' are backed by a MAAPI connection with the FASTMAP handle attached. To update 'proplist' simply return it from this function.

Example of a decorated cb_create:

Callback arguments:

  • tctx - transaction context (TransCtxRef)

  • root -- root node (maagic.Node)

  • service -- service node (maagic.Node)

  • proplist - properties (list(tuple(str, str)))

chevron-rightinit(...)hashtag

Method:

Custom initialization.

When registering a service using Application this method will be called with the 'init_args' passed into the register_service() function.

chevron-rightmaapihashtag

Readonly property

chevron-rightpost_modification(...)hashtag

Static method:

Decorator for the cb_post_modification callback.

For details see Service.pre_modification decorator.

chevron-rightpre_modification(...)hashtag

Static method:

Decorator for the cb_pre_modification callback.

Using this decorator alters the signature of the cb_pre_modification. callback and passes in a maagic.Node object for root. This method is invoked outside FASTMAP. To update 'proplist' simply return it from this function.

Example of a decorated cb_pre_modification:

Callback arguments:

  • tctx - transaction context (TransCtxRef)

  • op -- operation (int)

  • kp -- keypath (HKeypathRef)

  • root -- root node (maagic.Node)

  • proplist - properties (list(tuple(str, str)))

chevron-rightstart(...)hashtag

Method:

Start Service

chevron-rightstop(...)hashtag

Method:

Stop Service

Last updated

Was this helpful?