CM Backend Reference¶
This module implements a CM backend. To initialize it, an agent,
typically a subclass of CmAgent
must be registered with
cmbackend_init()
. Once initialized, CM frontends can
send requests and they will be routed to the agent.
See also
Initialization¶
-
exos.api.cmbackend.
cmbackend_init
(agent, persistent_list=None, config_deps=None)[source]¶ Initialize the CM backend for this process. As actions and events are received, methods in agent will be called. persistent_list is a list of tables that should be saved in the EXOS config.
config_deps is an optional list of process names as strings. CM will not load this process’ config until these processes have loaded theirs and gone to the READY state.
Action Context¶
-
class
exos.api.cmbackend.
CmContext
(cmbe_context, op_cookie, vr_name=None)[source]¶ Context object for a CM backend request. An instance will be passed to each call into the agent.
-
params
¶ Dictionary of parameters passed in the request. This will be populated before the action is called.
-
fields
¶ Dictionary of response fields. This must be populated by the action.
-
dirty
¶ Desired state of the dirty bit after the action returns. It defaults to True for set and setop methods, but can be overridden by an agent. The dirty bit indicates if the configuration needs to be saved.
-
is_async
¶ True if this request is being handled asynchronously. If async, blocking calls can be made during processing.
-
is_save
¶ True if this request is part of a save operation.
-
is_load
¶ True if this request is part of a load operation.
-
is_getone
¶ True if this request is part of a getone operation.
-
is_getnext
¶ True if this request is part of a getnext operation.
-
vr_name
¶ The VR in which this action should be run. If
None
, then no VR context was set in the request.
-
Agent¶
-
class
exos.api.cmbackend.
CmAgent
(pool=<concurrent.futures.thread.ThreadPoolExecutor object>)[source]¶ Base class for CM agents.
-
__init__
(pool=<concurrent.futures.thread.ThreadPoolExecutor object>)[source]¶ Create a new CM agent. pool is the thread pool to use when calling events and actions. By default, the callback pool will be used.
Not all actions and events can be run asynchronously in the thread pool. If
CmContext.is_async()
returnFalse
, then the agent cannot call blocking methods without risking a deadlock.
-
event_load_start
()[source]¶ CM will begin loading our config after this event. At this point, the agent should initialize with a default config. Set actions will be called to provide deltas from the default. In these actions,
CmContext.is_load
will beTrue
.A load_start event will always be followed by a load_complete event.
-
event_load_complete
()[source]¶ CM has finished loading the module’s config. The agent should now make itself ready to handle backend requests. It should also call
ready()
.Always called after a load_start event.
-
event_save_start
()[source]¶ CM will start saving our config after this event. Get actions will be called to retrieve the config. In these actions,
CmContext.is_save
will beTrue
.A save_start event will always be followed by a save_complete event.
-