diff options
-rw-r--r-- | schemas/metadata.xsd | 5 | ||||
-rw-r--r-- | src/lib/Server/Plugins/ExtraGroups.py | 42 |
2 files changed, 47 insertions, 0 deletions
diff --git a/schemas/metadata.xsd b/schemas/metadata.xsd index 58f9e8029..0ac4204b5 100644 --- a/schemas/metadata.xsd +++ b/schemas/metadata.xsd @@ -21,6 +21,11 @@ <xsd:attribute type='xsd:string' name='name' use='required'/> </xsd:complexType> </xsd:element> + <xsd:element name='Client'> + <xsd:complexType> + <xsd:attribute type='xsd:string' name='name' use='required'/> + </xsd:complexType> + </xsd:element> <xsd:element name='Group' > <xsd:complexType> <xsd:attribute name='name' use='required'/> diff --git a/src/lib/Server/Plugins/ExtraGroups.py b/src/lib/Server/Plugins/ExtraGroups.py new file mode 100644 index 000000000..e2a9a5591 --- /dev/null +++ b/src/lib/Server/Plugins/ExtraGroups.py @@ -0,0 +1,42 @@ +""" +The ExtraGroups plugin allows for assigning <Client>s to <Group>s in the +Metadata/groups.xml file. + +Written by Holger Weiss <holger@ZEDAT.FU-Berlin.DE>. +""" + +import os +import lxml.etree +import Bcfg2.Server.Plugin + +class ExtraGroups(Bcfg2.Server.Plugin.Plugin, Bcfg2.Server.Plugin.Connector): + name = 'ExtraGroups' + version = '1' + + def __init__(self, core, datastore): + Bcfg2.Server.Plugin.Plugin.__init__(self, core, datastore) + Bcfg2.Server.Plugin.Connector.__init__(self) + self.groups_xml = os.path.dirname(self.data) + '/Metadata/groups.xml' + + def get_additional_groups(self, metadata): + try: + xdata = lxml.etree.parse(self.groups_xml) + except lxml.etree.XMLSyntaxError: + self.logger.error('Failed to parse %s' % self.groups_xml) + return + includes = [ent.get('href') for ent in + xdata.findall('./{http://www.w3.org/2001/XInclude}include')] + if includes: + try: + xdata.xinclude() + except lxml.etree.XIncludeError: + self.logger.error('Failed to process XInclude for file %s' % + self.groups_xml) + extra_groups = [] + for group in xdata.xpath('//Groups/Group'): + if metadata.hostname in [item.get('name') + for item in group.findall('./Client')]: + extra_groups.append(group.get('name')) + extra_groups.extend([item.get('name') + for item in group.findall('./Group')]) + return extra_groups |