This page describes the step-by-step process of writing a client tool driver for a configuration element type. The included example describes an existing driver, and the process that was used to create it.
Pick a name for the driver. In this case, we picked the name RPM.
Create a file in src/lib/Bcfg2/Client/Tools with the same name (RPM.py)
Create a class in this file with the same name (class RPM)
Add any required executable programs to Bcfg2.Client.Tools.Tool.__execs__
Set Bcfg2.Client.Tools.Tool.__handles__ to a list of (<tag>, <type>) tuples. This determines which entries the Tool module can be used on. In this case, we set __handles__ = [('Package', 'rpm')].
Add verification support by defining a method named Verify<tag>. See Bcfg2.Client.Tools.Tool.Inventory() for details. This method should return True/False depending on current entry installation status. In the failure path, the current state of failing entry attributes should be set in the entry, to aid in auditing. (For example, if a file should be mode 644, and is currently mode 600, then set attribute current_mode=‘600’ in the input entry)
Add installation support by defining a method named Install<tag. See Bcfg2.Client.Tools.Tool.Install() for details. This method should return True/False depending on the results of the installation process.
If you are writing a tool to handle Package entries, PkgTool class has a generic mechanism for performing all-at-once installations, followed, in the case of failures, by single installations. See Bcfg2.Client.Tools.PkgTool.Install() for details.
Optionally, add support for removing extra entries by defining a Bcfg2.Client.Tools.Tool.Remove() method.
Optionally, add a Bcfg2.Client.Tools.Tool.FindExtra() method that locates entries not included in the configuration.
Package drivers require a Bcfg2.Client.Tools.PkgTool.RefreshPackages() method that updates the internal representation of the package database.
Bases: object
The base tool class. All tools subclass this.
Full paths to all executables the tool uses. When the tool is instantiated it will check to ensure that all of these files exist and are executable.
A list of 2-tuples of entries handled by this tool. Each 2-tuple should contain (<tag>, <type>), where <type> is the type attribute of the entry. If this tool handles entries with no type attribute, specify None.
A dict that describes the required attributes for entries handled by this tool. The keys are the names of tags. The values may either be lists of attribute names (if the same attributes are required by all tags of that name), or dicts whose keys are the type attribute and whose values are lists of attributes required by tags with that type attribute. In that case, the type attribute will also be required.
A list of entry names that will be treated as important and installed before other entries.
Parameters: | config (lxml.etree._Element) – The XML configuration for this client |
---|---|
Raises : | Bcfg2.Client.Tools.ToolInstantiationError |
Callback that is invoked when a bundle has been updated.
Parameters: | bundle (lxml.etree._Element) – The bundle that has been updated |
---|---|
Returns: | dict - A dict of the state of entries suitable for updating Bcfg2.Client.Client.states |
Callback that is invoked when a bundle has been updated.
Parameters: | bundle (lxml.etree._Element) – The bundle that has been updated |
---|---|
Returns: | dict - A dict of the state of entries suitable for updating Bcfg2.Client.Client.states |
Return a list of extra entries, i.e., entries that exist on the client but are not in the configuration.
Returns: | list of lxml.etree._Element |
---|
Install entries. ‘Install’ in this sense means either initially install, or update as necessary to match the specification.
This implementation of Bcfg2.Client.Tools.Tool.Install() calls a Install<tag> method to install each entry, where <tag> is the entry tag. E.g., a Path entry would be installed by calling InstallPath().
Parameters: | entries (list of lxml.etree._Element) – The entries to install |
---|---|
Returns: | dict - A dict of the state of entries suitable for updating Bcfg2.Client.Client.states |
Take an inventory of the system as it exists. This involves two steps:
This implementation of Bcfg2.Client.Tools.Tool.Inventory() calls a Verify<tag> method to verify each entry, where <tag> is the entry tag. E.g., a Path entry would be verified by calling VerifyPath().
Parameters: | structures (list of lxml.etree._Element) – The list of structures (i.e., bundles) to get entries from. If this is not given, all children of Bcfg2.Client.Tools.Tool.config will be used. |
---|---|
Returns: | dict - A dict of the state of entries suitable for updating Bcfg2.Client.Client.states |
Remove specified extra entries.
Parameters: | entries (list of lxml.etree._Element) – The entries to remove |
---|---|
Returns: | None |
Test if the entry is complete. This involves three things:
Parameters: |
|
---|---|
Returns: | bool - True if the entry can be verified, False otherwise. |
Build a list of all Path entries in the configuration. (This can be used to determine which paths might be modified from their original state, useful for verifying packages)
Returns: | list of lxml.etree._Element |
---|
Test if entry can be installed by calling Bcfg2.Client.Tools.Tool._entry_is_complete().
Parameters: | entry (lxml.etree._Element) – The entry to evaluate |
---|---|
Returns: | bool - True if the entry can be installed, False otherwise. |
Test if entry can be verified by calling Bcfg2.Client.Tools.Tool._entry_is_complete().
Parameters: | entry (lxml.etree._Element) – The entry to evaluate |
---|---|
Returns: | bool - True if the entry can be verified, False otherwise. |
An Bcfg2.Utils.Executor object for running external commands.
The XML configuration for this client
List of other tools (by name) that this tool conflicts with. If any of the listed tools are loaded, they will be removed at runtime with a warning.
This tool is deprecated, and a warning will be produced if it is used.
This tool is experimental, and a warning will be produced if it is used.
A list of extra entries that are not listed in the configuration
Get all entries that are handled by this tool.
Returns: | list of lxml.etree._Element |
---|
A list of all entries handled by this tool
Return True if the entry is handled by this tool.
Parameters: | entry (lxml.etree._Element) – Determine if this entry is handled. |
---|---|
Returns: | bool |
A logging.Logger object that will be used by this tool for logging
Return a list of attributes that were expected on an entry (from Bcfg2.Client.Tools.Tool.__req__), but not found.
Parameters: | entry (lxml.etree._Element) – The entry to find missing attributes on |
---|---|
Returns: | list of strings |
A list of entries that have been modified by this tool
The name of the tool. By default this uses Bcfg2.Client.Tools.ClassName to ensure that it is the same as the name of the class.
Bases: Bcfg2.Client.Tools.Tool
PkgTool provides a one-pass install with fallback for use with packaging systems. PkgTool makes a number of assumptions that may need to be overridden by a subclass. For instance, it assumes that packages are installed by a shell command; that only one version of a given package can be installed; etc. Nonetheless, it offers a strong base for writing simple package tools.
Return a list of extra entries, i.e., entries that exist on the client but are not in the configuration.
Returns: | list of lxml.etree._Element |
---|
Run a one-pass install where all required packages are installed with a single command, followed by single package installs in case of failure.
Parameters: | entries (list of lxml.etree._Element) – The entries to install |
---|---|
Returns: | dict - A dict of the state of entries suitable for updating Bcfg2.Client.Client.states |
Refresh the internal representation of the package database (Bcfg2.Client.Tools.PkgTool.installed).
Returns: | None |
---|
Verify the given Package entry.
Parameters: |
|
---|---|
Returns: | bool - True if the package verifies, false otherwise. |
A dict of installed packages; the keys should be package names and the values should be simple strings giving the installed version.
A tuple describing the format of the command to run to install a single package. The first element of the tuple is a string giving the format of the command, with a single ‘%s’ for the name of the package or packages to be installed. The second element is a tuple whose first element is the format of the name of the package, and whose second element is a list whose members are the names of attributes that will be used when formatting the package name format string.
The type attribute of Packages handled by this tool.
Bases: Bcfg2.Client.Tools.Tool
Base class for tools that handle Service entries
Parameters: | config (lxml.etree._Element) – The XML configuration for this client |
---|---|
Raises : | Bcfg2.Client.Tools.ToolInstantiationError |
Callback that is invoked when a bundle has been updated.
Parameters: | bundle (lxml.etree._Element) – The bundle that has been updated |
---|---|
Returns: | dict - A dict of the state of entries suitable for updating Bcfg2.Client.Client.states |
Install entries. ‘Install’ in this sense means either initially install, or update as necessary to match the specification.
This implementation of Bcfg2.Client.Tools.Tool.Install() calls a Install<tag> method to install each entry, where <tag> is the entry tag. E.g., a Path entry would be installed by calling InstallPath().
Parameters: | entries (list of lxml.etree._Element) – The entries to install |
---|---|
Returns: | dict - A dict of the state of entries suitable for updating Bcfg2.Client.Client.states |
Install a single service entry. See Bcfg2.Client.Tools.Tool.Install().
Parameters: | entry (lxml.etree._Element) – The Service entry to install |
---|---|
Returns: | bool - True if installation was successful, False otherwise |
Remove specified extra entries.
Parameters: | entries (list of lxml.etree._Element) – The entries to remove |
---|---|
Returns: | None |
Check the status a service.
Parameters: | service (lxml.etree._Element) – The service entry to modify |
---|---|
Returns: | bool - True if the status command returned 0, False otherwise |
Return the bootstatus attribute if it exists.
Parameters: | service (lxml.etree._Element) – The service entry |
---|---|
Returns: | string or None - Value of bootstatus if it exists. If bootstatus is unspecified and status is not ignore, return value of status. If bootstatus is unspecified and status is ignore, return None. |
Return a command that can be run to start or stop a service.
Parameters: |
|
---|---|
Returns: | string - The command to run |
Restart a service.
Parameters: | service (lxml.etree._Element) – The service entry to modify |
---|---|
Returns: | Bcfg2.Utils.ExecutorResult - The return value from Bcfg2.Utils.Executor.run |
List of services that have been restarted
Start a service.
Parameters: | service (lxml.etree._Element) – The service entry to modify |
---|---|
Returns: | Bcfg2.Utils.ExecutorResult - The return value from Bcfg2.Utils.Executor.run |
Stop a service.
Parameters: | service (lxml.etree._Element) – The service entry to modify |
---|---|
Returns: | Bcfg2.Utils.ExecutorResult - The return value from Bcfg2.Utils.Executor.run |