Table Of Contents
Working with Mediator Framework
Framework Overview
Configurable Nodes
Configuring Nodes
configure()
configuration()
Starting and Stopping Nodes
start()
stop()
Getting and Setting Attributes
getattr()
setattr()
hasattr()
Composite Nodes
About Composite Nodes
Working with Node Children
has_child()
get_child()
children_nodes()
children_names()
Getting and Setting Node Values
get()
set()
Working with Mediator Framework
This chapter describes the Mediator framework and includes the following sections:
•
Framework Overview
•
Configurable Nodes
•
Composite Nodes
•
Getting and Setting Node Values
Framework Overview
Mediator framework is the software application that provides the core function of the Mediator. The framework gives the Mediator its multiprotocol exchange capabilities, including the following:
•
Assembling a running system from configuration data.
•
Getting and setting values.
•
Processing raw data.
•
Presenting data from disparate sources in a uniform format.
•
Making data easily available to end users.
•
Providing services such as data logging and HTTP services.
•
Providing an environment for custom system configuration.
•
Providing an environment for developing custom solutions.
There are two types of framework nodes:
•
Configurable Nodes
•
Composite Nodes
All nodes inherit framework from one of two base node types. The composite node may hold child nodes; configurable nodes, on the other hand, are leaf nodes in the hierarchy. The composite node data type is an extension to the configurable node, so all the methods discussed for configurable nodes apply to composite nodes as well.
For more information on the framework, see the Cisco Network Building Mediator Release 3.x.x User Guide.
Configurable Nodes
This section explains the operations that you can perform with the configurable nodes and includes the following topics:
•
Starting and Stopping Nodes
•
Getting and Setting Attributes
Configuring Nodes
This section lists the standard APIs used for configurable nodes and includes the following topics:
•
configure()
•
configuration()
configure()
This API function allows the client to configure those parameters or attributes of the node that have been specified as configurable.
Inputs
Requires a single hash map type parameter providing name/value pairs for configurable attributes of the node. The values are usually primitive type, and the appropriate conversions are applied internally. Certain parameters will require explicit values, whereas others may have default values. The proper mechanism for configuring a parent node and name is via this method.
Outputs
No return value.
Note
Invocations of configure() which modify the configuration of a node in the framework are never persisted. Each time the framework starts or restarts, only the configuration information specified in the Broadway XML configuration file is used.
Examples
>>> a=as_node('services/network/http_server')
>>> a.configure({'name': 'http_server', 'parent': '/services/network', 'thread_c': '3',
'ip': '', '__node_id__': '471', 'enabled': '0', 'maintenance_interval': '25',
'zombie_timeout': '600', 'authentication': 'form', 'debug': '0', 'port': '80',
'user_manager': '/services/User%20Manager'})
configuration()
This API function allows the client to query a node for configured attributes.
Inputs
Accepts no parameters.
Outputs
Returns a hash map analogous to the hash map with which the node was configured.
Examples
>>> a=as_node('/services/time/local/second')
{'debug': '0', 'enabled': '1', 'name': 'second', 'parent': '/services/time/local'}
Starting and Stopping Nodes
This section lists the standard APIs used for starting and stopping nodes and includes the following topics:
•
start()
•
stop()
start()
This API function allows the client to perform node-specific implementation to initialized configured nodes.
Inputs
Accepts no parameters.
Outputs
No return value.
Examples
stop()
This API function allows the client to perform node-specific implementation to clean up node resources, stop associated processes, and scheduled entries.
Inputs
Accepts no parameters.
Outputs
No return value.
Examples
a.stop()
Getting and Setting Attributes
This section lists the standard APIs used for getting and setting attributes and includes the following topics:
•
getattr()
•
setattr()
•
hasattr()
getattr()
This API function provides the client with a method-based mechanism for retrieving arbitrary named attributes of a node.
Inputs
Requires single parameter naming attribute to retrieve.
Outputs
Returns value of attribute if it exists.
Examples
>>> a=as_node('services/network/http_server')
setattr()
This API function provides the client with a method-based mechanism for setting the value of arbitrarily named attributes of a node.
Inputs
Requires two parameters: name of attribute to be set, and the value it should be set to.
Outputs
No return value.
Examples
>>> a=as_node('services/network/http_server')
>>> a.setattr('enabled',1)
hasattr()
This API function provides the client with a method-based mechanism for querying the node about the existence of attributes.
Inputs
Requires single parameter: name of attribute to check on.
Outputs
Returns Boolean value indicating whether the attribute exists.
Examples
>>> a=as_node('services/network/http_server')
Composite Nodes
This section describes the extended operations that you can perform with the composite nodes and includes the following topics:
•
About Composite Nodes
•
Working with Node Children
About Composite Nodes
Composite Node extends the actions of the configurable nodes such that their invocation propagates to all the node descendants. Starting or stopping a parent node automatically starts and stops each of the child nodes in the parent also.
Working with Node Children
This section lists the standard APIs used for manipulating node children and includes the following topics:
•
has_child()
•
get_child()
•
children_nodes()
•
children_names()
has_child()
This API function allows the client to query the node for existence of a child node based on the node name.
Inputs
Requires on parameter: name of child node to check for.
Outputs
Returns Boolean value indicating whether child with specified name exists.
Examples
>>> a=as_node('services/time/local')
>>> a.has_child('second')
get_child()
This API function allows the client to query the node for a child node reference by name.
Inputs
Requires one parameter: the name of the child node to get.
Outputs
Returns child node instance if one exists.
Note
Although this method is part of the composite node API, invoking it remotely over XML-RPC will result in an error. It is described here for completeness.
children_nodes()
This API function allows the client to query the node for a list of child nodes.
Inputs
Accepts no parameters.
Outputs
Returns list of child node instances.
Note
Although this method is part of the composite node API, invoking it remotely over XML-RPC will result in an error. It is described here for completeness.
Examples
children_nodes()
>>> a=as_node('services/time/local')
[<mpx.service.time.time_attribute.TimeAttribute object at 0x1062abb0>,
<mpx.service.time.time_attribute.TimeAttribute object at 0x1062ab70>,
<mpx.service.time.time_attribute.TimeAttribute object at 0x1062ac10>,
<mpx.service.time.time_attribute.MilliSeconds object at 0x1062ab30>,
<mpx.service.time.time_attribute.TimeAttribute object at 0x1062abf0>,
<mpx.service.time.time_attribute.TimeAttribute object at 0x1062ab50>,
<mpx.service.schedule.scheduler.Schedules object at 0x10d7af70>,
<mpx.service.time.time_attribute.TimeAttribute object at 0x1062ab90>,
<mpx.service.time.time_attribute.TimeAttribute object at 0x1062abd0>]
children_names()
This API function allows the client to query the node for a list of child node names.
Inputs
Accepts no parameter.
Outputs
Returns list of child node names.
Examples
children_names()
>>> a=as_node('services/time/local')
['hour', 'month', 'second', 'milliseconds', 'weekday', 'year', 'time_schedules_1', 'day',
'minute']
Getting and Setting Node Values
This section lists the additional API functions that you can perform with the composite nodes, these functions are not defined by the base classes. This section includes the following topics:
•
get()
•
set()
get()
This API allows the client to get the current value of a point node.
Inputs
Accepts no parameters.
Outputs
Returns current value of node.
Examples
>>> a=as_node('interfaces/relay1')
set()
This API allows the client to set the current value of a point node.
Inputs
Requires single parameter: new value of node.
Outputs
No return value.
Examples
>>> a=as_node('interfaces/relay1')