""" The ExtraGroups plugin allows for assigning s to s in the Metadata/groups.xml file. Written by Holger Weiss . """ 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