diff options
author | Alexander Sulfrian <alexander.sulfrian@fu-berlin.de> | 2015-07-22 18:39:32 +0200 |
---|---|---|
committer | Alexander Sulfrian <alexander.sulfrian@fu-berlin.de> | 2015-08-26 19:12:30 +0200 |
commit | 6851a2931869aa9d9181b7b2d95f048aa5415a23 (patch) | |
tree | 5d56dbf8ecc48ff6a9f1970d91445366e34534f0 /src/lib/Bcfg2/Server/Plugin/helpers.py | |
parent | c7e67299381df961ff8274e9b53827c2bddbb47b (diff) | |
download | bcfg2-6851a2931869aa9d9181b7b2d95f048aa5415a23.tar.gz bcfg2-6851a2931869aa9d9181b7b2d95f048aa5415a23.tar.bz2 bcfg2-6851a2931869aa9d9181b7b2d95f048aa5415a23.zip |
Rules: New options replace_name to replace %{name} in attributes
If you use the regex feature of Rules/Defaults you may need the real name
of the matched entry in an attribute (for example home of POSIXUser).
You can now enable replace_name for rules or defaults and %{name} will be
replaces in the attribues of the Element before adding them to the target
entry.
This allows you to write something like that in Defaults to assing a default
home directory somewhere else to all users with unset home:
<POSIXUser name='.*' home='/somewhere/%{name}'/>
Diffstat (limited to 'src/lib/Bcfg2/Server/Plugin/helpers.py')
-rw-r--r-- | src/lib/Bcfg2/Server/Plugin/helpers.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/lib/Bcfg2/Server/Plugin/helpers.py b/src/lib/Bcfg2/Server/Plugin/helpers.py index 3b62a3217..6b521dfd6 100644 --- a/src/lib/Bcfg2/Server/Plugin/helpers.py +++ b/src/lib/Bcfg2/Server/Plugin/helpers.py @@ -1064,6 +1064,20 @@ class PrioDir(Plugin, Generator, XMLDirectoryBacked): data = candidate break + self._apply(entry, data) + + def _apply(self, entry, data): + """ Apply all available values from data onto entry. This + sets the available attributes (for all attribues unset in + the entry), adds all children and copies the text from data + to entry. + + :param entry: The entry to apply the changes + :type entry: lxml.etree._Element + :param data: The entry to get the data from + :type data: lxml.etree._Element + """ + if data.text is not None and data.text.strip() != '': entry.text = data.text for item in data.getchildren(): |