The configuration module

This configuration module (called cmod) is dedicated to configuration storage and export.

Every Pyrame module can register in the cmod and store its configuration parameters. The modules are stored in a tree representing the arborescence of the system.

The cmod contains at any time a copy of the configuration of all the modules and it can generate xml files containing all the parameters to be used with calxml.

API

cmd_cmod.reload_default_cmod()[source]

reload the default parameters file

cmd_cmod.load_config_file_cmod(filename)[source]

load a configuration from an xml file

cmd_cmod.gener_config_cmod()[source]

extract the configuration from the tree and aggregate it in a XML file

cmd_cmod.gener_configb64_cmod()[source]

extract the configuration from the tree and aggregate it in a XML file encoded in base 64

cmd_cmod.apply_phase_cmod(dev_name, phase_name, params='')[source]

apply a phase with name phase_name on the subtree with root dev_name. params is an empty string or a json dictionary containing values that can be passed to modules during the phase

cmd_cmod.transition_cmod(dev_name, goto, transition_name, transition_fallback, params='')[source]

Use transition_name to a system described by the loaded configuration. If the transition fails, use transition_fallback. The optional JSON-encoded params value adds named parameters to the phases.

cmd_cmod.command_cmod(dev_name, async, func, *params)[source]

apply a command on a device. If async is true, the command is done asynchronously.

cmd_cmod.set_param_cmod(dev_name, param_name, param_value)[source]

add or modify a parameter for a device

cmd_cmod.get_param_cmod(dev_name, param_name)[source]

get a parameter from a device

cmd_cmod.get_type_cmod(dev_name)[source]

find the type of a device

cmd_cmod.get_ip_cmod(dev_name)[source]

find the ip of a device

cmd_cmod.get_location_cmod(dev_name)[source]

get ip and type of a device

cmd_cmod.get_name_list_cmod(dev_type)[source]

get the list of all device names of a dev_type

cmd_cmod.get_name_sublist_cmod(dev_type, parent_name)[source]

get the list of device names of a dev_type type with parent_name parent

cmd_cmod.exec_apc(node, phase_name, ext_params, fin)[source]

this function apply a a phase to a device

How to use it?

First load the configuration file with load_config_cmod. Then use transition_cmod to make the state machine do a transition.

How does it works?

The module uses the following algorithm to parse the configuration and apply phases. Every time a new module instance is found while parsing, the module:

  • searches in the module API for the name phasename_modulename
  • gets the parameters name of this function
  • gets the parameters values from the xml configuration or from the defaults file.
  • executes the function on the corresponding module with the parameters
  • continues with all the child modules
  • searches in the module API for the name phasename_fin_modulename
  • executes the function on the corresponding module with the parameters

As you can see, two different functions are called for every module: one when the module is first found and another after finding all its child modules.

Example

Imagine we want to initialize a setup with a network switch and two connected cards. We have to initialize the switch with its port number as a parameter, then set the ip address for the two cards and finally calculate the MAC table on the switch. We will implement three functions.

def init_switch(switch_nb_port):
  init_ports(nb_port)

def init_nic(nic_ip):
  setup_ip(nic_ip)

def init_fin_switch():
  calc_mac_table()

Then create an xml file like this:

<switch name="sw">
  <param name="switch_nb_port">6</param>
  <nic name="nic1">
    <param name="nic_ip">192.168.0.1</param>
  </nic>
  <nic name="nic2">
    <param name="nic_ip">192.168.0.2</param>
  </nic>
</switch>

When the init phase is applied, these functions will be called in this order:

  • init_switch(“6”)
  • init_nic(“192.168.0.1”)
  • init_nic(“192.168.0.1”)
  • init_fin_switch()

Note that all parameters are strings. If a function does not exists (like init_fin_nic in the example), it is simply ignored.