The Cfg plugin offers multiple handlers to handle different entries in different ways. Writing a new Cfg handler is a relatively simple way to add significant new features to Cfg.
Each new Cfg handler must be contained in its own module in Bcfg2.Server.Plugins.Cfg, and the module and class name must be identical. The name should start with Cfg, and should clearly indicate which of the handler types it is. A handler class may implement more than one handler type.
There are several different types of Cfg handlers. A new handler must inherit either from one of these classes, or from an existing handler.
Bases: Bcfg2.Server.Plugins.Cfg.CfgBaseFileMatcher
CfgGenerators generate the initial content of a file. Every valid Bcfg2.Server.Plugins.Cfg.CfgEntrySet must have at least one file handled by a CfgGenerator. Moreover, each CfgEntrySet must have one unambiguously best handler for each client. See Bcfg2.Server.Plugin.helpers.EntrySet for more details on how the best handler is chosen.
Parameters: |
|
---|
get_data() returns the initial data of a file.
Parameters: |
|
---|---|
Returns: | string - the contents of the entry |
Bases: Bcfg2.Server.Plugins.Cfg.CfgBaseFileMatcher
CfgCreator handlers create static entry data if no generator was found to generate any. A CfgCreator runs at most once per client, writes its data to disk as a static file, and is not called on subsequent runs by the same client.
Parameters: | name (string) – The full path to the file |
---|
Whether or not the files handled by this handler are permitted to have specificity indicators in their filenames – e.g., .H_client.example.com or .G10_foogroup. By default CfgInfo handlers do not allow specificities
Create new data for the given entry and write it to disk using Bcfg2.Server.Plugins.Cfg.CfgCreator.write_data().
Parameters: |
|
---|---|
Returns: | string - The contents of the entry |
Raises : |
Get the filename where the new data will be written. If host is given, it will be host-specific. It will be group-specific if group and prio are given. If neither host nor group is given, the filename will be non-specific. In general, this will be called as:
self.get_filename(**self.get_specificity(metadata))
Parameters: |
|
---|---|
Returns: | string - the filename |
Write the new data to disk. If host is given, it is written as a host-specific file, or as a group-specific file if group and prio are given. If neither host nor group is given, it will be written as a non-specific file. In general, this will be called as:
self.write_data(data, **self.get_specificity(metadata))
Parameters: |
|
---|---|
Returns: | None |
Raises : |
Bases: Bcfg2.Server.Plugins.Cfg.CfgBaseFileMatcher
CfgFilters modify the initial content of a file after it has been generated by a Bcfg2.Server.Plugins.Cfg.CfgGenerator.
Parameters: |
|
---|
Return new data for the entry, based on the initial data produced by the Bcfg2.Server.Plugins.Cfg.CfgGenerator.
Parameters: |
|
---|---|
Returns: | string - the new contents of the entry |
Bases: Bcfg2.Server.Plugins.Cfg.CfgBaseFileMatcher
CfgInfo handlers provide metadata (owner, group, paranoid, etc.) for a file entry.
Parameters: | name (string) – The full path to the file |
---|
Whether or not the files handled by this handler are permitted to have specificity indicators in their filenames – e.g., .H_client.example.com or .G10_foogroup. By default CfgInfo handlers do not allow specificities
Assign the appropriate attributes to the entry, modifying it in place.
Parameters: |
|
---|---|
Returns: | None |
Bases: Bcfg2.Server.Plugins.Cfg.CfgBaseFileMatcher
CfgVerifier handlers validate entry data once it has been generated, filtered, and info applied. Validation can be enabled or disabled in the configuration. Validation can apply to the contents of an entry, the attributes on it (e.g., owner, group, etc.), or both.
Parameters: |
|
---|
Perform entry contents. validation.
Parameters: |
|
---|---|
Returns: | None |
Raises : |
In addition to the interfaces defined above, all Cfg handlers inherit from CfgBaseFileMatcher.
Bases: Bcfg2.Server.Plugin.helpers.SpecificData
CfgBaseFileMatcher is the parent class for all Cfg handler objects.
param name: The full path to the file type name: string param specific: A Bcfg2.Server.Plugin.helpers.Specificity object describing what clients this file applies to. type specific: Bcfg2.Server.Plugin.helpers.Specificity
The set of filenames handled by this handler. If __basenames__ is the empty list, then the basename of each CfgEntrySet is used – i.e., the name of the directory that contains the file is used for the basename.
This handler only handles files with the listed extensions (which come after CfgBaseFileMatcher.__specific__ indicators).
This handler ignores all files with the listed extensions. A file that is ignored by a handler will not be handled by any other handlers; that is, a file is ignored if any handler ignores it. Ignoring a file is not simply a means to defer handling of that file to another handler.
Whether or not the files handled by this handler are permitted to have specificity indicators in their filenames – e.g., .H_client.example.com or .G10_foogroup.
Cfg handlers are checked in ascending order of priority to see if they handle a given event. If this explicit priority is not set, then CfgPlaintextGenerator.CfgPlaintextGenerator would match against nearly every other sort of generator file if it comes first. It’s not necessary to set __priority__ on handlers where CfgBaseFileMatcher.__specific__ is False, since they don’t have a potentially open-ended regex
Flag to indicate a deprecated handler.
Flag to indicate an experimental handler.
Get a compiled regular expression to match filenames (not full paths) that this handler handles.
Parameters: | basename (string) – The base filename to use if CfgBaseFileMatcher.__basenames__ is not defined (i.e., the name of the directory that contains the files the regex will be applied to) |
---|---|
Returns: | compiled regex |
Return True if this handler handles the file described by event. This is faster than just applying CfgBaseFileMatcher.get_regex() because it tries to do non-regex matching first.
Parameters: |
|
---|---|
Returns: | bool - True if this handler handles the file listed in the event, False otherwise. |
Return True if this handler ignores the file described by event. See CfgBaseFileMatcher.__ignore__ for more information on how ignoring files works.
Parameters: |
|
---|---|
Returns: | bool - True if this handler handles the file listed in the event, False otherwise. |
Cfg handlers may produce the following exceptions:
Bases: exceptions.Exception
Raised by Bcfg2.Server.Plugins.Cfg.CfgVerifier.verify_entry() when an entry fails verification
Bases: exceptions.Exception
Raised by Bcfg2.Server.Plugins.Cfg.CfgCreator.create_data() when data creation fails
In addition, Cfg handlers may produce the following base plugin exceptions:
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: Bcfg2.Server.Plugins.Cfg.CfgGenerator
CfgPlaintextGenerator is a Bcfg2.Server.Plugins.Cfg.CfgGenerator that handles plain text (i.e., non-templated) Cfg files. The base Generator class already implements this functionality, so CfgPlaintextGenerator doesn’t need to do anything itself.
Parameters: |
|
---|
Bases: Bcfg2.Server.Plugins.Cfg.CfgGenerator
The CfgGenshiGenerator allows you to use the Genshi templating system to generate Cfg files.
Parameters: |
|
---|
get_data() returns the initial data of a file.
Parameters: |
|
---|---|
Returns: | string - the contents of the entry |
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 |
Error-handling in Genshi is pretty obtuse. This regex is used to extract the first line of the code block that raised an exception in a Genshi template so we can provide a decent error message that actually tells the end user where an error occurred.
Bases: Bcfg2.Server.Plugins.Cfg.CfgGenerator
The CfgCheetahGenerator allows you to use the Cheetah templating system to generate Cfg files.
Parameters: |
|
---|
get_data() returns the initial data of a file.
Parameters: |
|
---|---|
Returns: | string - the contents of the entry |
Cheetah.Template.Template compiler settings
Bases: Bcfg2.Server.Plugins.Cfg.CfgGenerator
The CfgJinja2Generator allows you to use the Jinja2 templating system to generate Cfg files.
Parameters: |
|
---|
get_data() returns the initial data of a file.
Parameters: |
|
---|---|
Returns: | string - the contents of the entry |
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 |
Bases: Bcfg2.Server.Plugins.Cfg.CfgGenerator
CfgEncryptedGenerator lets you encrypt your plaintext Cfg files on the server.
Bases: Bcfg2.Server.Plugins.Cfg.CfgGenshiGenerator.CfgGenshiGenerator
CfgEncryptedGenshiGenerator lets you encrypt your Genshi Cfg files on the server
Bases: Bcfg2.Server.Plugins.Cfg.CfgCheetahGenerator.CfgCheetahGenerator, Bcfg2.Server.Plugins.Cfg.CfgEncryptedGenerator.CfgEncryptedGenerator
CfgEncryptedCheetahGenerator lets you encrypt your Cheetah Cfg files on the server
Parameters: |
|
---|
get_data() returns the initial data of a file.
Parameters: |
|
---|---|
Returns: | string - the contents of the entry |
Bases: Bcfg2.Server.Plugins.Cfg.CfgJinja2Generator.CfgJinja2Generator, Bcfg2.Server.Plugins.Cfg.CfgEncryptedGenerator.CfgEncryptedGenerator
CfgEncryptedJinja2Generator lets you encrypt your Jinja2 Cfg files on the server
Parameters: |
|
---|
get_data() returns the initial data of a file.
Parameters: |
|
---|---|
Returns: | string - the contents of the entry |
Bases: Bcfg2.Server.Plugins.Cfg.CfgGenerator, Bcfg2.Server.Plugin.helpers.StructFile
The CfgAuthorizedKeysGenerator generates authorized_keys files based on an XML specification of which SSH keypairs should granted access.
Parameters: |
|
---|
get_data() returns the initial data of a file.
Parameters: |
|
---|---|
Returns: | string - the contents of the entry |
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 |
Bases: Bcfg2.Server.Plugins.Cfg.XMLCfgCreator
The CfgPrivateKeyCreator creates SSH keys on the fly.
Create data for the given entry on the given client
Parameters: |
|
---|---|
Returns: | string - The private key data |
Bases: Bcfg2.Server.Plugins.Cfg.CfgCreator, Bcfg2.Server.Plugin.helpers.StructFile
The CfgPublicKeyCreator creates SSH public keys on the fly. It is invoked by CfgPrivateKeyCreator.CfgPrivateKeyCreator to handle the creation of the public key, and can also call CfgPrivateKeyCreator.CfgPrivateKeyCreator to trigger the creation of a keypair when a public key is created.
No text content on any tags, so encryption support disabled
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 |
Bases: Bcfg2.Server.Plugins.Cfg.CfgInfo
Bcfg2.Server.Plugins.Cfg.Cfg handler that supplies a default set of file metadata
Parameters: | name (string) – The full path to the file |
---|
Assign the appropriate attributes to the entry, modifying it in place.
Parameters: |
|
---|---|
Returns: | None |
Bases: Bcfg2.Server.Plugins.Cfg.CfgInfo
CfgInfoXML handles info.xml files for Cfg
Parameters: | name (string) – The full path to the file |
---|
Whether or not the files handled by this handler are permitted to have specificity indicators in their filenames – e.g., .H_client.example.com or .G10_foogroup. By default CfgInfo handlers do not allow specificities
Assign the appropriate attributes to the entry, modifying it in place.
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 |
Bases: Bcfg2.Server.Plugins.Cfg.CfgVerifier
Invoke an external script to verify Cfg file contents
Parameters: |
|
---|
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 |
Perform entry contents. validation.
Parameters: |
|
---|---|
Returns: | None |
Raises : |
These other objects comprise the remainder of the Cfg plugin, and are included for completeness.
Bases: Bcfg2.Server.Plugin.helpers.EntrySet
Handle a collection of host- and group-specific Cfg files with multiple different Cfg handlers in a single directory.
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.
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 entry metadata to the entry with the best CfgInfo handler
Parameters: |
|
---|---|
Returns: | None |
Handle the creation of a file on the filesystem and the creation of a Cfg handler object in this CfgEntrySet to track it.
Parameters: |
|
---|---|
Returns: | None |
Raises : |
Get all handlers of the given type for the given metadata.
Parameters: |
|
---|---|
Returns: | list of Cfg handler classes |
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 entry_init() or the appropriate child handler object.
Parameters: | event (Bcfg2.Server.FileMonitor.Event) – An event that applies to a file handled by this CfgEntrySet |
---|---|
Returns: | None |
Bases: Bcfg2.Server.Plugin.helpers.GroupSpool, Bcfg2.Server.Plugin.interfaces.PullTarget
The Cfg plugin provides a repository to describe configuration file contents for clients. In its simplest form, the Cfg repository is just a directory tree modeled off of the directory tree on your client machines.
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
alias of SpecificData
alias of CfgEntrySet
Return True if the given entry can be generated for the given metadata; False otherwise
Parameters: |
|
---|---|
Returns: | bool |
Get the Bcfg2.Server.Plugins.Cfg.Cfg plugin object created by the Bcfg2 core. This is provided so that the handler objects can access it as necessary, since the existing Bcfg2.Server.Plugin.helpers.GroupSpool and Bcfg2.Server.Plugin.helpers.EntrySet classes have no facility for passing it otherwise.