While the Bcfg2 server provides a good interface for representing general system configurations, its plugin interface offers the ability to implement configuration interfaces and representation tailored to problems encountered by a particular site. This chapter describes what plugins are good for, what they can do, and how to implement them.
Several plugins themselves have pluggable backends, and for narrow cases you may want to develop a backend for an existing plugin rather than an entirely new plugin. See the following pages for more information:
Bcfg2 plugins are loadable python modules that the Bcfg2 server loads at initialization time. These plugins can contribute to the functions already offered by the Bcfg2 server or can extend its functionality. In general, plugins will provide some portion of the configuration for clients, with a data representation that is tuned for a set of common tasks. Much of the core functionality of Bcfg2 is implemented by several plugins, however, they are not special in any way; new plugins could easily supplant one or all of them.
Bcfg2.Server.Plugin contains server plugin base classes, interfaces, exceptions, and helper objects. This module is split into a number of submodules to make it more manageable, but it imports all symbols from the submodules, so with the exception of some documentation it’s not necessary to use the submodules. E.g., you can (and should) do:
from Bcfg2.Server.Plugin import Plugin
...rather than:
from Bcfg2.Server.Plugin.base import Plugin
A plugin must implement at least one of the interfaces described below. Each interface is available as a class in Bcfg2.Server.Plugin. In most cases, a plugin must also inherit from Bcfg2.Server.Plugin.base.Plugin, which is the base Plugin object (described below). Some of the interfaces listed below are themselves Plugin objects, so your custom plugin would only need to inherit from the plugin type.
Bases: Bcfg2.Logger.Debuggable
The base class for all Bcfg2 Server plugins.
Parameters: | core (Bcfg2.Server.Core) – The Bcfg2.Server.Core initializing the plugin |
---|---|
Raises : | OSError if adding a file monitor failed; Bcfg2.Server.Plugin.exceptions.PluginInitError on other errors |
List of names of methods to be exposed as XML-RPC functions, if applicable to the child class
Plugin conflicts with the list of other plugin names
Whether or not to automatically create a data directory for this plugin
Log a message at the debug level.
Parameters: | |
---|---|
Returns: | None |
Plugin is deprecated and will be removed in a future release. Use of this plugin will produce a log message alerting the administrator that an experimental plugin is in use.
Plugin is experimental. Use of this plugin will produce a log message alerting the administrator that an experimental plugin is in use.
Perform any tasks necessary to create an initial Bcfg2 repository.
Parameters: | repo (string) – The path to the Bcfg2 repository on the filesystem |
---|---|
Returns: | None |
The name of the plugin.
Plugins of the same type are processed in order of ascending sort_order value. Plugins with the same sort_order are sorted alphabetically by their name.
Turn debugging output on or off.
Returns: | bool - The new value of the debug flag |
---|
With the exceptions of Bcfg2.Server.Plugin.interfaces.Statistics and Bcfg2.Server.Plugin.interfaces.ThreadedStatistics, the plugin interfaces listed below do not inherit from Plugin; they simply provide interfaces that a given plugin may or must implement.
Interface definitions for Bcfg2 server plugins
Bases: object
ClientACLs are used to grant or deny access to different XML-RPC calls based on client IP or metadata.
Check if the given IP address is authorized to make the named XML-RPC call.
Parameters: |
|
---|---|
Returns: | bool or None - True to allow, False to deny, None to defer to metadata ACLs |
Check if the given client is authorized to make the named XML-RPC call.
Parameters: |
|
---|---|
Returns: | bool |
Bases: object
ClientRunHooks can hook into various parts of a client run to perform actions at various times without needing to pretend to be a different plugin type.
Invoked at the end of a client run, immediately after GoalValidator plugins have been run and just before the configuration is returned to the client.
Parameters: | metadata (Bcfg2.Server.Plugins.Metadata.ClientMetadata) – The client metadata object |
---|---|
Returns: | None |
Invoked after statistics are processed for a client.
Parameters: | metadata (Bcfg2.Server.Plugins.Metadata.ClientMetadata) – The client metadata object |
---|---|
Returns: | None |
Invoked at the start of a client run, after all probe data has been received and decision lists have been queried (if applicable), but before the configuration is generated.
Parameters: | metadata (Bcfg2.Server.Plugins.Metadata.ClientMetadata) – The client metadata object |
---|---|
Returns: | None |
Bases: object
Connector plugins augment client metadata instances with additional data, additional groups, or both.
Return arbitrary additional data for the given ClientMetadata object. By convention this is usually a dict object, but doesn’t need to be.
Parameters: | metadata (Bcfg2.Server.Plugins.Metadata.ClientMetadata) – The client metadata |
---|---|
Returns: | dict |
Return a list of additional groups for the given client. Each group can be either the name of a group (a string), or a Bcfg2.Server.Plugins.Metadata.MetadataGroup object that defines other data besides just the name. Note that you cannot return a Bcfg2.Server.Plugins.Metadata.MetadataGroup object that clobbers a group defined by another plugin; the original group will be used instead. For instance, assume the following in Metadata/groups.xml:
<Groups>
...
<Group name="foo" public="false"/>
</Groups>
You could not subsequently return a Bcfg2.Server.Plugins.Metadata.MetadataGroup object with public=True; a warning would be issued, and the original (non-public) foo group would be used.
Parameters: | metadata (Bcfg2.Server.Plugins.Metadata.ClientMetadata) – The client metadata |
---|---|
Returns: | list of strings or Bcfg2.Server.Plugins.Metadata.MetadataGroup objects. |
Bases: object
Decision plugins produce decision lists for affecting which entries are actually installed on clients.
Return a list of tuples of (<entry type>, <entry name>) to be used as the decision list for the given client in the specified mode.
Parameters: |
|
---|---|
Returns: | list of tuples |
Bases: object
Generator plugins contribute to literal client configurations. That is, they generate entry contents.
An entry is generated in one of two ways:
HandleEntry is the slow path method for binding configuration binding requests. It is called if the Entries dict does not contain a method for binding the entry, and HandlesEntry() returns True.
Parameters: |
|
---|---|
Returns: | lxml.etree._Element - The fully bound entry |
Raises : |
HandlesEntry is the slow path method for routing configuration binding requests. It is called if the Entries dict does not contain a method for binding the entry.
Parameters: |
|
---|---|
Returns: | bool - Whether or not this plugin can handle the entry |
Raises : |
Bases: object
GoalValidator plugins can modify the concretely-bound configuration of a client as a last stage before the configuration is sent to the client.
Given a monolithic XML document of the full configuration, modify the document in-place.
Parameters: |
|
---|---|
Returns: | None |
Raises : | Bcfg2.Server.Plugin.exceptions:ValidationError |
Bases: object
Metadata plugins handle initial metadata construction, accumulating data from Connector plugins, and producing Bcfg2.Server.Plugins.Metadata.ClientMetadata objects.
Authenticate the given client.
Parameters: | |
---|---|
Returns: | bool - True if the authenticate succeeds, False otherwise |
Return a Bcfg2.Server.Plugins.Metadata.ClientMetadata object that fully describes everything the Metadata plugin knows about the named client.
Parameters: | client_name (string) – The hostname of the client |
---|---|
Returns: | Bcfg2.Server.Plugins.Metadata.ClientMetadata |
Add arbitrary data from a Connector plugin to the given metadata object.
Parameters: |
|
---|---|
Returns: | None |
Add groups from a Connector plugin to the given metadata object.
Parameters: |
|
---|---|
Returns: | None |
Resolve the canonical name of this client. If this method is not implemented, the hostname claimed by the client is used. (This may be a security risk; it’s highly recommended that you implement resolve_client if you are writing a Metadata plugin.)
Parameters: | |
---|---|
Returns: | string - canonical client hostname |
Raises : | Bcfg2.Server.Plugin.exceptions.MetadataRuntimeError, Bcfg2.Server.Plugin.exceptions.MetadataConsistencyError |
Set the profile for the named client to the named profile group.
Parameters: | |
---|---|
Returns: | None |
Raises : | Bcfg2.Server.Plugin.exceptions.MetadataRuntimeError, Bcfg2.Server.Plugin.exceptions.MetadataConsistencyError |
Set the version for the named client to the specified version string.
Parameters: | |
---|---|
Returns: | None |
Raises : | Bcfg2.Server.Plugin.exceptions.MetadataRuntimeError, Bcfg2.Server.Plugin.exceptions.MetadataConsistencyError |
Return a string containing a graphviz document that maps out the Metadata for bcfg2-admin viz
Parameters: | |
---|---|
Returns: | string |
Bases: object
Probing plugins can collect data from clients and process it.
Return a list of probes for the given client. Each probe should be an lxml.etree._Element object that adheres to the following specification. Each probe must the following attributes:
The text of the XML tag should be the contents of the probe, i.e., the code that will be run on the client.
Parameters: | metadata (Bcfg2.Server.Plugins.Metadata.ClientMetadata) – The client metadata |
---|---|
Returns: | list of lxml.etree._Element objects |
Process data returned from the probes for the given client. datalist is a list of lxml.etree._Element objects, each of which is a single tag; the name attribute holds the unique name of the probe that was run, and the text contents of the tag hold the results of the probe.
Parameters: |
|
---|---|
Returns: | None |
Bases: Bcfg2.Server.Plugin.base.Plugin
Statistics plugins handle statistics for clients. In general, you should avoid using Statistics and use ThreadedStatistics instead.
Parameters: | core (Bcfg2.Server.Core) – The Bcfg2.Server.Core initializing the plugin |
---|---|
Raises : | OSError if adding a file monitor failed; Bcfg2.Server.Plugin.exceptions.PluginInitError on other errors |
List of names of methods to be exposed as XML-RPC functions, if applicable to the child class
Process the given XML statistics data for the specified client.
Parameters: |
|
---|---|
Returns: | None |
Bases: object
Structure Plugins contribute to abstract client configurations. That is, they produce lists of entries that will be generated for a client.
Build a list of lxml.etree._Element objects that will be added to the top-level <Configuration> tag of the client configuration. Consequently, each object in the list returned by BuildStructures() must consist of a container tag (e.g., <Bundle> or <Independent>) which contains the entry tags. It must not return a list of entry tags.
Parameters: | metadata (Bcfg2.Server.Plugins.Metadata.ClientMetadata) – The client metadata |
---|---|
Returns: | list of lxml.etree._Element objects |
Bases: object
StructureValidator plugins can modify the list of structures after it has been created but before the entries have been concretely bound.
Given a list of structures (i.e., of tags that contain entry tags), modify that list or the structures in it in-place.
Parameters: |
|
---|---|
Returns: | None |
Raises : |
Bases: object
TemplateDataProvider plugins provide variables to templates for use in rendering.
Bases: object
Threaded plugins use threads in any way. The thread must be started after daemonization, so this class implements a single method, start_threads(), that can be used to start threads after daemonization of the server core.
Start this plugin’s threads after daemonization.
Returns: | None |
---|---|
Raises : | Bcfg2.Server.Plugin.exceptions.PluginInitError |
Bases: Bcfg2.Server.Plugin.interfaces.Statistics, Bcfg2.Server.Plugin.interfaces.Threaded, threading.Thread
ThreadedStatistics plugins process client statistics in a separate thread.
Process the given XML statistics data for the specified client object. This differs from the Statistics.process_statistics() method only in that ThreadedStatistics first adds the data to a queue, and then processes them in a separate thread.
Parameters: |
|
---|---|
Returns: | None |
Bases: Bcfg2.Server.Plugin.base.Plugin
Version plugins interact with various version control systems.
param core: The Bcfg2.Server.Core initializing the plugin type core: Bcfg2.Server.Core raises: OSError if adding a file monitor failed; Bcfg2.Server.Plugin.exceptions.PluginInitError on other errors
- Debuggable.__rmi__ = ['toggle_debug', 'set_debug']¶
List of names of methods to be exposed as XML-RPC functions, if applicable to the child class
The path to the VCS metadata file or directory, relative to the base of the Bcfg2 repository. E.g., for Subversion this would be ”.svn”
Plugins can expose XML-RPC functions that can then be called with bcfg2-admin xcmd. Note that there is absolutely no access control beyond the initial authentication, so take care to not expose any data or behavior via XML-RPC that you would not want all of your clients to be able to see or use.
To expose a function, simply add its name to the __rmi__ class attribute. (RMI stands for “Remote Method Invocation.”) Consider this example from the Packages plugin:
class Packages(Bcfg2.Server.Plugin.Plugin,
Bcfg2.Server.Plugin.StructureValidator,
Bcfg2.Server.Plugin.Generator,
Bcfg2.Server.Plugin.Connector,
Bcfg2.Server.Plugin.ClientRunHooks):
name = 'Packages'
conflicts = ['Pkgmgr']
__rmi__ = Bcfg2.Server.Plugin.Plugin.__rmi__ + ['Refresh', 'Reload']
def Refresh(self):
self._load_config(force_update=True)
return True
def Reload(self):
self._load_config()
return True
This exposes two functions, Refresh and Reload, in addition to any default methods that are already exposed. To call one of these functions, you could run:
bcfg2-admin xcmd Packages.Refresh
New in version 1.3.0.
In Bcfg2 1.3.0, some limited Server-side Caching was introduced. If you are writing a Bcfg2.Server.Plugin.interfaces.Connector plugin that implements Bcfg2.Server.Plugin.interfaces.Connector.get_additional_groups() or Bcfg2.Server.Plugin.interfaces.Connector.get_additional_data(), then you need to be able to invalidate the server metadata cache in order to be compatible with the cautious or aggressive caching modes.
The two attributes you need to know about are:
Bcfg2.Server.Plugin.base.Plugin objects have access to the Bcfg2.Server.Core object as self.core. In general, you’ll be interested in the Bcfg2.Server.Cache.Cache.expire() method; if called with no arguments, it expires all cached data; if called with one string argument, it expires cached data for the named client.
It’s important, therefore, that your Connector plugin can either track when changes are made to the data or group membership it reports, and expire cached data appropriately when in cautious or aggressive mode; or prudently flag an incompatibility with those two modes.
For examples, see:
New in version 1.3.0.
Statistics can and should track execution time statistics using Bcfg2.Server.Statistics. This module tracks execution time for the server core and for plugins, and exposes that data via bcfg2-admin perf. This data can be invaluable for locating bottlenecks or other performance issues.
The simplest way to track statistics is to use the Bcfg2.Server.Statistics.track_statistics() decorator to decorate functions that you would like to track execution times for:
from Bcfg2.Server.Statistics import track_statistics
@track_statistics()
def do_something(self, ...):
...
This will track the execution time of do_something.
More granular usage is possible by using time.time() to manually determine the execution time of a given event and calling Bcfg2.Server.Statistics.Statistics.add_value() with an appropriate statistic name.
Module for tracking execution time statistics from the Bcfg2 server core. This data is exposed by Bcfg2.Server.Core.BaseCore.get_statistics().
Bases: object
A single named statistic, tracking minimum, maximum, and average execution time, and number of invocations.
Parameters: |
|
---|
Add a value to the statistic, recalculating the various metrics.
Parameters: | value (int or float) – The value to add to this statistic |
---|
Get a tuple of all the stats tracked on this named item. The tuple is in the format:
(<name>, (min, max, average, number of values))
This makes it very easy to cast to a dict in Statistics.display().
Returns: | tuple |
---|
Bases: object
A collection of named Statistic objects.
Add a value to the named Statistic. This just proxies to Statistic.add_value() or the Statistic constructor as appropriate.
Parameters: |
---|
Return a dict of all Statistic object values. Keys are the statistic names, and values are tuples of the statistic metrics as returned by Statistic.get_value().
A module-level Statistics objects used to track all execution time metrics for the server.
Bases: object
Decorator that tracks execution time for the given method with Bcfg2.Server.Statistics for reporting via bcfg2-admin perf
Parameters: | name (string) – The name under which statistics for this function will be tracked. By default, the name will be the name of the function concatenated with the name of the class the function is a member of. |
---|
Helper classes for Bcfg2 server plugins
Bases: Bcfg2.Server.Plugin.base.Plugin
Provides capabilities for a plugin to read and write to a database. The plugin must add an option to flag database use with something like:
This must be done manually due to various limitations in Python.
Whether or not the backend database must acquire a thread lock before writing, because it does not allow multiple threads to write.
Log a message at the debug level.
Parameters: | |
---|---|
Returns: | None |
Decorator to be used by a method of a DatabaseBacked plugin that will update database data.
Perform any tasks necessary to create an initial Bcfg2 repository.
Parameters: | repo (string) – The path to the Bcfg2 repository on the filesystem |
---|---|
Returns: | None |
Perform shutdown tasks for the plugin
Returns: | None |
---|
Turn debugging output on or off.
Returns: | bool - The new value of the debug flag |
---|
Bases: Bcfg2.Server.Plugin.interfaces.TemplateDataProvider
A base Bcfg2.Server.Plugin.interfaces.TemplateDataProvider that provides default data for text and XML templates.
Note that, since Cheetah and Genshi text templates treat the path variable differently, this is overridden, by Bcfg2.Server.Plugins.Cfg.CfgCheetahGenerator.DefaultCheetahDataProvider and Bcfg2.Server.Plugins.Cfg.CfgGenshiGenerator.DefaultGenshiDataProvider, respectively.
Bases: Bcfg2.Logger.Debuggable
DirectoryBacked objects represent a directory that contains files, represented by objects of the type listed in __child__, and other directories recursively. It monitors for new files and directories to be added, and creates new objects as required to track those.
Parameters: | data (string) – The path to the data directory that will be monitored |
---|
The type of child objects to create for files contained within the directory that is tracked. Default is Bcfg2.Server.Plugin.helpers.FileBacked
Handle FAM events.
This method is invoked by the FAM when it detects a change to a filesystem object we have requsted to be monitored.
This method manages the lifecycle of events related to the monitored objects, adding them to our list of entries and creating objects of type __child__ that actually do the domain-specific processing. When appropriate, it propogates events those objects by invoking their HandleEvent method in turn.
Parameters: | event (Bcfg2.Server.FileMonitor.Event) – FAM event that caused this entry to be added. |
---|---|
Returns: | None |
Add a new directory to the FAM for monitoring.
Parameters: | relative (string) – Path name to monitor. This must be relative to the plugin’s directory. An empty string value (“”) will cause the plugin directory itself to be monitored. |
---|---|
Returns: | None |
Add a new file to our tracked entries, and to our FAM for monitoring.
Parameters: |
|
---|---|
Returns: | None |
Log a message at the debug level.
Parameters: | |
---|---|
Returns: | None |
self.entries contains information about the files monitored by this object. The keys of the dict are the relative paths to the files. The values are the objects (of type __child__) that handle their contents.
self.handles contains information about the directories monitored by this object. The keys of the dict are the values returned by the initial fam.AddMonitor() call (which appear to be integers). The values are the relative paths of the directories.
Preemptively ignore files whose names (not paths) match this compiled regex. ignore can be set to None to ignore no files. If a file is encountered that does not match patterns or ignore, then a warning will be produced.
Only track and include files whose names (not paths) match this compiled regex.
Turn debugging output on or off.
Returns: | bool - The new value of the debug flag |
---|
Bases: Bcfg2.Logger.Debuggable
EntrySets deal with a collection of host- and group-specific files (e.g., Bcfg2.Server.Plugin.helpers.SpecificData objects) in a single directory. EntrySets are usually used as part of Bcfg2.Server.Plugin.helpers.GroupSpool objects.
Parameters: |
|
---|
The entry_type callable must have the following signature:
entry_type(filepath, specificity)
Where the parameters are:
Parameters: |
|
---|
Additionally, the object returned by entry_type must have a specific attribute that is sortable (e.g., a Bcfg2.Server.Plugin.helpers.Specificity object).
See Bcfg2.Server.Plugin.helpers.SpecificData for an example of a class that can be used as an entry_type.
processed as a string that contains a regular expression (i.e., not a compiled regex object) if basename_is_regex is True, and all files that match the regex will be cincluded in the EntrySet. If basename_is_regex is False, then it will be considered a plain string and filenames must match exactly.
Return the single most specific matching entry from the set of matching entries. You can use get_matching() to get all matching entries.
Parameters: |
|
---|---|
Returns: | a single object from the list of matching entry_type objects |
Raises : | Bcfg2.Server.Plugin.exceptions.PluginExecutionError if no matching entries are found |
Return the single best fully-bound entry from the set of available entries for the specified client.
Parameters: |
|
---|---|
Returns: | lxml.etree._Element - the fully-bound entry |
Bind the metadata for the given client in the base info.xml for this EntrySet to the entry.
Parameters: |
|
---|---|
Returns: | None |
Log a message at the debug level.
Parameters: | |
---|---|
Returns: | None |
Handle the creation of a file on the filesystem and the creation of an object in this EntrySet to track it.
Parameters: |
|
---|---|
Returns: | None |
Raises : |
Get a list of all entries that apply to the given client. This gets all matching entries; for example, there could be an entry that applies to all clients, multiple group-specific entries, and a client-specific entry, all of which would be returned by get_matching(). You can use best_matching() to get the single best matching entry.
Parameters: | metadata (Bcfg2.Server.Plugins.Metadata.ClientMetadata) – The client metadata to get matching entries for |
---|---|
Returns: | list – all matching entry_type objects (see the constructor docs for more details) |
Dispatch a FAM event to the appropriate function or child entry_type object. This will probably be handled by a call to update_metadata(), reset_metadata(), entry_init(), or to the entry_type handle_event() function.
Parameters: | event (Bcfg2.Server.FileMonitor.Event) – An event that applies to a file handled by this EntrySet |
---|---|
Returns: | None |
Preemptively ignore files whose names (not paths) match this compiled regex. ignore cannot be set to None. If a file is encountered that does not match the basename argument passed to the constructor or ignore, then a warning will be produced.
Reset metadata to defaults if info.xml is removed.
Parameters: | event (Bcfg2.Server.FileMonitor.Event) – An event that applies to an info handled by this EntrySet |
---|---|
Returns: | None |
specific is a regular expression that is used to determine the specificity of a file in this entry set. It must have three named groups: hostname, prio (the priority of a group-specific file), and group. The base regex is constructed from the basename argument. It can be overridden on a per-entry basis in entry_init().
Construct a Bcfg2.Server.Plugin.helpers.Specificity object from a filename and regex. See specific for details on the regex.
Parameters: |
|
---|---|
Returns: | Object representing the specificity of the file |
Return type: | |
Raises : | Bcfg2.Server.Plugin.exceptions.SpecificityError if the regex does not match the filename |
Turn debugging output on or off.
Returns: | bool - The new value of the debug flag |
---|
Process changes to or creation of info.xml files for the EntrySet.
Parameters: | event (Bcfg2.Server.FileMonitor.Event) – An event that applies to an info handled by this EntrySet |
---|---|
Returns: | None |
Bases: Bcfg2.Logger.Debuggable
This object caches file data in memory. FileBacked objects are principally meant to be used as a part of Bcfg2.Server.Plugin.helpers.DirectoryBacked.
Parameters: | name (string) – The full path to the file to cache and monitor |
---|
HandleEvent is called whenever the FAM registers an event.
Parameters: | event (Bcfg2.Server.FileMonitor.Event) – The event object |
---|---|
Returns: | None |
Index() is called by HandleEvent() every time the data changes, and parses the data into usable data as required.
A string containing the raw data in this file
Log a message at the debug level.
Parameters: | |
---|---|
Returns: | None |
The FAM object used to receive notifications of changes
The full path to the file
Explicitly enable or disable debugging.
Returns: | bool - The new value of the debug flag |
---|
Turn debugging output on or off.
Returns: | bool - The new value of the debug flag |
---|
Bases: Bcfg2.Server.Plugin.base.Plugin, Bcfg2.Server.Plugin.interfaces.Generator
A GroupSpool is a collection of Bcfg2.Server.Plugin.helpers.EntrySet objects – i.e., a directory tree, each directory in which may contain files that are specific to groups/clients/etc.
Parameters: | core (Bcfg2.Server.Core) – The Bcfg2.Server.Core initializing the plugin |
---|---|
Raises : | OSError if adding a file monitor failed; Bcfg2.Server.Plugin.exceptions.PluginInitError on other errors |
List of names of methods to be exposed as XML-RPC functions, if applicable to the child class
Add a FAM monitor to a new directory and set the appropriate event handler.
Parameters: | relative (string) – The path to the directory relative to the base data directory of the GroupSpool object. |
---|---|
Returns: | None |
HandleEntry is the slow path method for binding configuration binding requests. It is called if the Entries dict does not contain a method for binding the entry, and HandlesEntry() returns True.
Parameters: |
|
---|---|
Returns: | lxml.etree._Element - The fully bound entry |
Raises : |
HandleEvent is the event dispatcher for GroupSpool objects. It receives all events and dispatches them the appropriate handling object (e.g., one of the es_cls objects in entries), function (e.g., add_entry()), or behavior (e.g., deleting an entire entry set).
Parameters: | event (Bcfg2.Server.FileMonitor.Event) – An event that applies to a file or directory handled by this GroupSpool |
---|---|
Returns: | None |
HandlesEntry is the slow path method for routing configuration binding requests. It is called if the Entries dict does not contain a method for binding the entry.
Parameters: |
|
---|---|
Returns: | bool - Whether or not this plugin can handle the entry |
Raises : |
This method handles two functions:
Parameters: | event (Bcfg2.Server.FileMonitor.Event) – An event that applies to a file or directory handled by this GroupSpool |
---|---|
Returns: | None |
Log a message at the debug level.
Parameters: | |
---|---|
Returns: | None |
entries is a dict whose keys are event_id() return values and whose values are es_cls objects. It ties the directories handled by this GroupSpools to the es_cls objects that handle each directory.
The entry type (i.e., the XML tag) handled by this GroupSpool object.
es_child_cls is a callable that will be used as the entry_type argument to the es_cls callable. It must return objects that will represent individual files in the GroupSpool. For instance, Bcfg2.Server.Plugin.helpers.SpecificData.
alias of object
es_cls is a callable that must return objects that will be used to represent directories (i.e., sets of entries) within the GroupSpool. E.g., Bcfg2.Server.Plugin.helpers.EntrySet. The returned object must implement a callable called bind_entry that has the same signature as EntrySet.bind_entry.
alias of EntrySet
Return a string that can be used to relate the event unambiguously to a single es_cls object in the entries dict. In practice, this means:
Parameters: | event (Bcfg2.Server.FileMonitor.Event) – An event that applies to a file or directory handled by this GroupSpool |
---|---|
Returns: | string |
Return the full path to the filename affected by an event. Bcfg2.Server.FileMonitor.Event objects just contain the filename, not the full path, so this function reconstructs the fill path based on the path to the es_cls object that handles the event.
Parameters: | event (Bcfg2.Server.FileMonitor.Event) – An event that applies to a file or directory handled by this GroupSpool |
---|---|
Returns: | string |
filename_pattern is used as the basename argument to the es_cls callable. It may or may not be a regex, depending on the EntrySet.basename_is_regex setting.
Perform any tasks necessary to create an initial Bcfg2 repository.
Parameters: | repo (string) – The path to the Bcfg2 repository on the filesystem |
---|---|
Returns: | None |
Perform shutdown tasks for the plugin
Returns: | None |
---|
Turn debugging output on or off.
Returns: | bool - The new value of the debug flag |
---|
Bases: Bcfg2.Server.Plugin.helpers.StructFile
InfoXML files contain Group, Client, and Path tags to set the metadata (permissions, owner, etc.) of files.
Bind the matching file metadata for this client and entry to the entry.
Parameters: |
|
---|---|
Returns: | None |
HandleEvent is called whenever the FAM registers an event.
Parameters: | event (Bcfg2.Server.FileMonitor.Event) – The event object |
---|---|
Returns: | None |
Index() is called by HandleEvent() every time the data changes, and parses the data into usable data as required.
Implementation of Bcfg2.Server.Plugin.helpers.StructFile.Match() that considers Path tags to allow info.xml files to set different file metadata for different file paths.
Implementation of Bcfg2.Server.Plugin.helpers.StructFile.XMLMatch() that considers Path tags to allow info.xml files to set different file metadata for different file paths.
Add a FAM monitor to a file that has been XIncluded.
Parameters: | fpath (string) – The full path to the file to monitor |
---|---|
Returns: | None |
Log a message at the debug level.
Parameters: | |
---|---|
Returns: | None |
Explicitly enable or disable debugging.
Returns: | bool - The new value of the debug flag |
---|
Turn debugging output on or off.
Returns: | bool - The new value of the debug flag |
---|
Bases: object
A database model mixin that all database models used by Bcfg2.Server.Plugin.helpers.DatabaseBacked plugins must inherit from. This is just a mixin; models must also inherit from django.db.models.Model to be valid Django models.
Bases: Bcfg2.Server.Plugin.base.Plugin, Bcfg2.Server.Plugin.interfaces.Generator, Bcfg2.Server.Plugin.helpers.XMLDirectoryBacked
PrioDir handles a directory of XML files where each file has a set priority.
The type of child objects to create for files contained within the directory that is tracked. Default is Bcfg2.Server.Plugin.helpers.PriorityStructFile
Parameters: | core (Bcfg2.Server.Core) – The Bcfg2.Server.Core initializing the plugin |
---|---|
Raises : | OSError if adding a file monitor failed; Bcfg2.Server.Plugin.exceptions.PluginInitError on other errors |
List of names of methods to be exposed as XML-RPC functions, if applicable to the child class
Bind the attributes that apply to an entry to it. The entry is modified in-place.
Parameters: |
|
---|---|
Returns: | None |
HandleEntry is the slow path method for binding configuration binding requests. It is called if the Entries dict does not contain a method for binding the entry, and HandlesEntry() returns True.
Parameters: |
|
---|---|
Returns: | lxml.etree._Element - The fully bound entry |
Raises : |
Handle FAM events.
This method is invoked by the FAM when it detects a change to a filesystem object we have requsted to be monitored.
This method manages the lifecycle of events related to the monitored objects, adding them to our list of entries and creating objects of type __child__ that actually do the domain-specific processing. When appropriate, it propogates events those objects by invoking their HandleEvent method in turn.
Parameters: | event (Bcfg2.Server.FileMonitor.Event) – FAM event that caused this entry to be added. |
---|---|
Returns: | None |
HandlesEntry is the slow path method for routing configuration binding requests. It is called if the Entries dict does not contain a method for binding the entry.
Parameters: |
|
---|---|
Returns: | bool - Whether or not this plugin can handle the entry |
Raises : |
Add a new directory to the FAM for monitoring.
Parameters: | relative (string) – Path name to monitor. This must be relative to the plugin’s directory. An empty string value (“”) will cause the plugin directory itself to be monitored. |
---|---|
Returns: | None |
Add a new file to our tracked entries, and to our FAM for monitoring.
Parameters: |
|
---|---|
Returns: | None |
Log a message at the debug level.
Parameters: | |
---|---|
Returns: | None |
Perform any tasks necessary to create an initial Bcfg2 repository.
Parameters: | repo (string) – The path to the Bcfg2 repository on the filesystem |
---|---|
Returns: | None |
Perform shutdown tasks for the plugin
Returns: | None |
---|
Turn debugging output on or off.
Returns: | bool - The new value of the debug flag |
---|
Bases: Bcfg2.Server.Plugin.helpers.StructFile
A StructFile where each file has a priority, given as a top-level XML attribute.
HandleEvent is called whenever the FAM registers an event.
Parameters: | event (Bcfg2.Server.FileMonitor.Event) – The event object |
---|---|
Returns: | None |
Index() is called by HandleEvent() every time the data changes, and parses the data into usable data as required.
Return matching fragments of the data in this file. A tag is considered to match if all <Group> and <Client> tags that are its ancestors match the metadata given. Since tags are included unmodified, it’s possible for a tag to itself match while containing non-matching children. Consequently, only the tags contained in the list returned by Match() (and not their descendents) should be considered to match the metadata.
Match() returns matching fragments in document order.
Parameters: | metadata (Bcfg2.Server.Plugins.Metadata.ClientMetadata) – Client metadata to match against. |
---|---|
Returns: | list of lxml.etree._Element objects |
Return a rebuilt XML document that only contains the matching portions of the original file. A tag is considered to match if all <Group> and <Client> tags that are its ancestors match the metadata given. Unlike Match(), the document returned by XMLMatch will only contain matching data. All <Group> and <Client> tags will have been stripped out.
The new document produced by XMLMatch() is not necessarily in the same order as the original document.
Parameters: | metadata (Bcfg2.Server.Plugins.Metadata.ClientMetadata) – Client metadata to match against. |
---|---|
Returns: | lxml.etree._Element |
Add a FAM monitor to a file that has been XIncluded.
Parameters: | fpath (string) – The full path to the file to monitor |
---|---|
Returns: | None |
Log a message at the debug level.
Parameters: | |
---|---|
Returns: | None |
Explicitly enable or disable debugging.
Returns: | bool - The new value of the debug flag |
---|
Turn debugging output on or off.
Returns: | bool - The new value of the debug flag |
---|
Bases: Bcfg2.Logger.Debuggable
A file that is specific to certain clients, groups, or all clients.
Parameters: |
|
---|
Log a message at the debug level.
Parameters: | |
---|---|
Returns: | None |
Handle a FAM event. Note that the SpecificData object itself has no FAM, so this must be produced by a parent object (e.g., Bcfg2.Server.Plugin.helpers.EntrySet).
Parameters: | event (Bcfg2.Server.FileMonitor.Event) – The event that applies to this file |
---|---|
Returns: | None |
Raises : | Bcfg2.Server.Plugin.exceptions.PluginExecutionError |
Explicitly enable or disable debugging.
Returns: | bool - The new value of the debug flag |
---|
Turn debugging output on or off.
Returns: | bool - The new value of the debug flag |
---|
Bases: Bcfg2.Compat.CmpMixin
Represent the specificity of an object; i.e., what client(s) it applies to. It can be group- or client-specific, or apply to all clients.
Specificity objects are sortable; objects that are less specific are considered less than objects that are more specific. Objects that apply to all clients are the least specific; objects that apply to a single client are the most specific. Objects that apply to groups are sorted by priority.
Parameters: |
|
---|
Exactly one of {all|group|hostname} should be given.
Return True if the object described by this Specificity object applies to the given client. That is, if this Specificity applies to all clients, or to a group the client is a member of, or to the client individually.
Parameters: | metadata (Bcfg2.Server.Plugins.Metadata.ClientMetadata) – The client metadata |
---|---|
Returns: | bool |
Bases: Bcfg2.Server.Plugin.helpers.XMLFileBacked
StructFiles are XML files that contain a set of structure file formatting logic for handling <Group> and <Client> tags.
If __identifier__ is not None, then it must be the name of an XML attribute that will be required on the top-level tag of the file being cached
Determine if an XML element matches the other arguments.
The first argument is always the XML element to match, and the second will always be a single Bcfg2.Server.Plugins.Metadata.ClientMetadata object representing the metadata to match against. Subsequent arguments are as given to Bcfg2.Server.Plugin.helpers.StructFile.Match() or Bcfg2.Server.Plugin.helpers.StructFile.XMLMatch(). In the base StructFile implementation, there are no additional arguments; in classes that inherit from StructFile, see the Match() and XMLMatch() method signatures.
HandleEvent is called whenever the FAM registers an event.
Parameters: | event (Bcfg2.Server.FileMonitor.Event) – The event object |
---|---|
Returns: | None |
Index() is called by HandleEvent() every time the data changes, and parses the data into usable data as required.
Return matching fragments of the data in this file. A tag is considered to match if all <Group> and <Client> tags that are its ancestors match the metadata given. Since tags are included unmodified, it’s possible for a tag to itself match while containing non-matching children. Consequently, only the tags contained in the list returned by Match() (and not their descendents) should be considered to match the metadata.
Match() returns matching fragments in document order.
Parameters: | metadata (Bcfg2.Server.Plugins.Metadata.ClientMetadata) – Client metadata to match against. |
---|---|
Returns: | list of lxml.etree._Element objects |
Return a rebuilt XML document that only contains the matching portions of the original file. A tag is considered to match if all <Group> and <Client> tags that are its ancestors match the metadata given. Unlike Match(), the document returned by XMLMatch will only contain matching data. All <Group> and <Client> tags will have been stripped out.
The new document produced by XMLMatch() is not necessarily in the same order as the original document.
Parameters: | metadata (Bcfg2.Server.Plugins.Metadata.ClientMetadata) – Client metadata to match against. |
---|---|
Returns: | lxml.etree._Element |
Add a FAM monitor to a file that has been XIncluded.
Parameters: | fpath (string) – The full path to the file to monitor |
---|---|
Returns: | None |
Log a message at the debug level.
Parameters: | |
---|---|
Returns: | None |
Whether or not to enable encryption
Explicitly enable or disable debugging.
Returns: | bool - The new value of the debug flag |
---|
Turn debugging output on or off.
Returns: | bool - The new value of the debug flag |
---|
Bases: Bcfg2.Server.Plugin.helpers.DirectoryBacked
Bcfg2.Server.Plugin.helpers.DirectoryBacked for XML files.
Parameters: | data (string) – The path to the data directory that will be monitored |
---|
The type of child objects to create for files contained within the directory that is tracked. Default is Bcfg2.Server.Plugin.helpers.XMLFileBacked
Handle FAM events.
This method is invoked by the FAM when it detects a change to a filesystem object we have requsted to be monitored.
This method manages the lifecycle of events related to the monitored objects, adding them to our list of entries and creating objects of type __child__ that actually do the domain-specific processing. When appropriate, it propogates events those objects by invoking their HandleEvent method in turn.
Parameters: | event (Bcfg2.Server.FileMonitor.Event) – FAM event that caused this entry to be added. |
---|---|
Returns: | None |
Add a new directory to the FAM for monitoring.
Parameters: | relative (string) – Path name to monitor. This must be relative to the plugin’s directory. An empty string value (“”) will cause the plugin directory itself to be monitored. |
---|---|
Returns: | None |
Add a new file to our tracked entries, and to our FAM for monitoring.
Parameters: |
|
---|---|
Returns: | None |
Log a message at the debug level.
Parameters: | |
---|---|
Returns: | None |
Only track and include files whose names (not paths) match this compiled regex.
Turn debugging output on or off.
Returns: | bool - The new value of the debug flag |
---|
Bases: Bcfg2.Server.Plugin.helpers.FileBacked
This object parses and caches XML file data in memory. It can be used as a standalone object or as a part of Bcfg2.Server.Plugin.helpers.XMLDirectoryBacked
Parameters: |
|
---|
If __identifier__ is set, then a top-level tag with the specified name will be required on the file being cached. Its value will be available as label. To disable this behavior, set __identifier__ to None.
HandleEvent is called whenever the FAM registers an event.
Parameters: | event (Bcfg2.Server.FileMonitor.Event) – The event object |
---|---|
Returns: | None |
Index() is called by HandleEvent() every time the data changes, and parses the data into usable data as required.
Add a FAM monitor to a file that has been XIncluded.
Parameters: | fpath (string) – The full path to the file to monitor |
---|---|
Returns: | None |
If create is set, then it overrides the create argument to the constructor.
Log a message at the debug level.
Parameters: | |
---|---|
Returns: | None |
All entries in this file. By default, all immediate children of the top-level XML tag.
Extra FAM monitors set by this object for files included by XInclude.
“Extra” files included in this file by XInclude.
The label of this file. This is determined from the top-level tag in the file, which must have an attribute specified by __identifier__.
Explicitly enable or disable debugging.
Returns: | bool - The new value of the debug flag |
---|
Whether or not to monitor this file for changes.
Turn debugging output on or off.
Returns: | bool - The new value of the debug flag |
---|
The raw XML data contained in the file as an lxml.etree.ElementTree object, with XIncludes processed.
Bind the file metadata in the given Bcfg2.Server.Plugin.helpers.InfoXML object to the given entry.
Parameters: |
|
---|---|
Returns: | None |
Raises : |
Get the default Path entry metadata from the config.
Returns: | dict of metadata attributes and their default values |
---|
Get all template variables for a text (i.e., Cfg) template
Get all template variables for an XML template
A Genshi filter that removes comments from the stream. This function is a generator.
Parameters: | stream (genshi.core.Stream) – The Genshi stream to remove comments from |
---|---|
Returns: | tuple of (kind, data, pos), as when iterating through a Genshi stream |
Bases: object
Mixin to add a debugging interface to an object
Parameters: | name (string) – The name of the logger object to get. If none is supplied, the full name of the class (including module) will be used. |
---|
Log a message at the debug level.
Parameters: | |
---|---|
Returns: | None |
Explicitly enable or disable debugging.
Returns: | bool - The new value of the debug flag |
---|
Turn debugging output on or off.
Returns: | bool - The new value of the debug flag |
---|
Exceptions for Bcfg2 Server Plugins.
Bases: exceptions.Exception
This error gets raised when metadata is internally inconsistent.
Bases: exceptions.Exception
This error is raised when the metadata engine is called prior to reading enough data, or for other Bcfg2.Server.Plugin.interfaces.Metadata errors.
Bases: exceptions.Exception
Error raised in case of Bcfg2.Server.Plugin.base.Plugin execution errors.
Bases: exceptions.Exception
Error raised in cases of Bcfg2.Server.Plugin.base.Plugin initialization errors.
Bases: exceptions.Exception
Thrown by Bcfg2.Server.Plugin.helpers.Specificity in case of filename parse failure.
Bases: exceptions.Exception
Exception raised by Bcfg2.Server.Plugin.interfaces.StructureValidator and Bcfg2.Server.Plugin.interfaces.GoalValidator objects