def setDescriptors(dmd): """ Set the property descriptors on the ZenPropertyManager class. The transformerFactories parameter is a dictionary that maps a property type to a callable factory that produces instances with transformForGet and transformForSet methods. """ zprops = set() # copy the core zProps for prop_id, propt_default_value, prop_type in Z_PROPERTIES: zprops.add((prop_id, prop_type)) # add zProps from zenpacks from Products.ZenUtils.PkgResources import pkg_resources for zpkg in pkg_resources.iter_entry_points('zenoss.zenpacks'): # fromlist is typically ZenPacks.zenoss fromlist = zpkg.module_name.split('.')[:-1] module = __import__(zpkg.module_name, globals(), locals(), fromlist) if hasattr(module, 'ZenPack'): for prop_id, propt_default_value, prop_type in module.ZenPack.packZProperties: zprops.add((prop_id, prop_type)) # add zProps from dmd.Devices to catch any that are undefined elsewhere for prop_id in dmd.Devices.zenPropertyIds(): prop_type = dmd.Devices.getPropertyType(prop_id) if (prop_id, prop_type) not in zprops: log.debug('Property {prop_id} is deprecated. It should be removed from the system.'.format(prop_id=prop_id)) zprops.add((prop_id, prop_type)) monkeypatchDescriptors(zprops, dmd.propertyTransformers)
def setDescriptors(dmd): """ Set the property descriptors on the ZenPropertyManager class. The transformerFactories parameter is a dictionary that maps a property type to a callable factory that produces instances with transformForGet and transformForSet methods. """ zprops = set() # copy the core zProps for prop_id, propt_default_value, prop_type in Z_PROPERTIES: zprops.add((prop_id, prop_type)) # add zProps from zenpacks from Products.ZenUtils.PkgResources import pkg_resources for zpkg in pkg_resources.iter_entry_points('zenoss.zenpacks'): # fromlist is typically ZenPacks.zenoss fromlist = zpkg.module_name.split('.')[:-1] module = __import__(zpkg.module_name, globals(), locals(), fromlist) if hasattr(module, 'ZenPack'): for prop_id, propt_default_value, prop_type in module.ZenPack.packZProperties: zprops.add((prop_id, prop_type)) # add zProps from dmd.Devices to catch any that are undefined elsewhere for prop_id in dmd.Devices.zenPropertyIds(): prop_type = dmd.Devices.getPropertyType(prop_id) if (prop_id, prop_type) not in zprops: log.debug( 'Property {prop_id} is deprecated. It should be removed from the system.' .format(prop_id=prop_id)) zprops.add((prop_id, prop_type)) monkeypatchDescriptors(zprops, dmd.propertyTransformers)
def setDescriptors(dmd): """ Set the property descriptors on the ZenPropertyManager class. The transformerFactories parameter is a dictionary that maps a property type to a callable factory that produces instances with transformForGet and transformForSet methods. """ zprops = set() # copy the core zProps # Z_PROPERTIES = id, defaultValue, type , label, description for item in Z_PROPERTIES: id = item[0] type = item[2] zprops.add((id, type)) Z_PROPERTY_META_DATA[id] = dict() Z_PROPERTY_META_DATA[id]['type'] = type Z_PROPERTY_META_DATA[id]['defaultValue'] = item[1] if len(item) >= 4: Z_PROPERTY_META_DATA[id]['label'] = item[3] if len(item) >= 5: Z_PROPERTY_META_DATA[id]['description'] = item[4] # add zProps from zenpacks from Products.ZenUtils.PkgResources import pkg_resources for zpkg in pkg_resources.iter_entry_points('zenoss.zenpacks'): # fromlist is typically ZenPacks.zenoss fromlist = zpkg.module_name.split('.')[:-1] module = __import__(zpkg.module_name, globals(), locals(), fromlist) if hasattr(module, 'ZenPack'): for prop_id, propt_default_value, prop_type in module.ZenPack.packZProperties: zprops.add((prop_id, prop_type)) if hasattr(module.ZenPack, 'packZProperties_data'): Z_PROPERTY_META_DATA.update(module.ZenPack.packZProperties_data) # check for category to update for key, value in module.ZenPack.packZProperties_data.iteritems(): # if zproperties are only defined in data zprops.add((key, value.get('type'))) if value.get('category'): setzPropertyCategory(key, value.get('category')) # add zProps from dmd.Devices to catch any that are undefined elsewhere for prop_id in dmd.Devices.zenPropertyIds(): prop_type = dmd.Devices.getPropertyType(prop_id) if (prop_id, prop_type) not in zprops: log.debug('Property {prop_id} is deprecated. It should be removed from the system.'.format(prop_id=prop_id)) zprops.add((prop_id, prop_type)) monkeypatchDescriptors(zprops, dmd.propertyTransformers)
def nameZenPackDaemons(self, zenPackId=None): """ Return a list of the names of the daemons provided by the given ZenPack. If no ZenPack is specified then list all daemons provided by all ZenPacks. """ dList = [] zpl = ZPLDaemons() # Get daemons from egg-based ZenPacks for entry in pkg_resources.iter_entry_points(ZENPACK_ENTRY_POINT): try: module = entry.load() dList += zpl.list(os.path.dirname(module.__file__), None) except Exception, ex: summary = "The ZenPack %s cannot be imported -- skipping." % entry.name self.log.exception(summary)
def _getZenPackSchemas(): schemas = [] for zpkg in pkg_resources.iter_entry_points('zenoss.zenpacks'): try: pkg_path = zpkg.load().__path__[0] # Load any queue schema files schemas.extend(_loadQjs(pkg_path)) except Exception, e: # This messes up logging a bit, but if we need to report # an error, this saves hours of trying to find out what's going on logging.basicConfig() log = logging.getLogger('zen.ZenMessaging') log.exception("Error encountered while processing %s", zpkg.module_name)
def DiscoverEggs(dmd, zenPackId): """ Find installed eggs that provide a zenoss.zenpacks entry point. Return a list of distributions whose ZenPacks need to be installed or upgraded. The list is sorted into the order in which this needs to happen. """ # Create a set of all available zenoss.zenpack entries that aren't # already installed in zenoss or need to be upgraded in zenoss. entries = set() parse_version = pkg_resources.parse_version for entry in pkg_resources.iter_entry_points(ZENPACK_ENTRY_POINT): packName = entry.name packVers = entry.dist.version existing = dmd.ZenPackManager.packs._getOb(packName, None) if existing and existing.isEggPack(): # We use >= to allow migrate to be run on currently installed # zenpacks whose version has been changed or for whom new # migrates have been added. if parse_version(packVers) >= parse_version(existing.version): entries.add(entry) else: entries.add(entry) # Starting with the entry representing zenPackId create a list of # all entrypoints # orderedEntries lists entries in the opposite order of that in which # they need to be installed. This is simply for convenience of using # .append() in code below. orderedEntries = [] entriesByName = dict((e.name, e) for e in entries) def AddEntryAndProcessDeps(e): orderedEntries.append(e) for name in [r.project_name for r in e.dist.requires()]: if name in [e.name for e in orderedEntries]: # This entry depends on something that we've already processed. # This might be a circular dependency, might not be. # We are just going to bail however. This should be # very unusual and the user can install deps first to work # around. raise ZenPackException( 'Unable to resolve ZenPack dependencies.' ' Try installing dependencies first.') if name in entriesByName: # The requirement is an entry that has not yet been processed # here. Add it to the list of entries to install/upgrade. AddEntryAndProcessDeps(entriesByName[name]) else: # The requirement is not in the entries generated above. # This either means that the dep is already installed (this # is likely) or that easy_install missed something and the dep # is not installed/available (this should be unlikely.) pass if zenPackId not in entriesByName: if zenPackId in dmd.ZenPackManager.packs.objectIds(): return [] else: raise ZenPackException('Unable to discover ZenPack named %s' % zenPackId) AddEntryAndProcessDeps(entriesByName[zenPackId]) orderedEntries.reverse() return [e.dist for e in orderedEntries]
def DiscoverEggs(dmd, zenPackId): """ Find installed eggs that provide a zenoss.zenpacks entry point. Return a list of distributions whose ZenPacks need to be installed or upgraded. The list is sorted into the order in which this needs to happen. """ # Create a set of all available zenoss.zenpack entries that aren't # already installed in zenoss or need to be upgraded in zenoss. entries = set() parse_version = pkg_resources.parse_version for entry in pkg_resources.iter_entry_points(ZENPACK_ENTRY_POINT): packName = entry.name packVers = entry.dist.version existing = dmd.ZenPackManager.packs._getOb(packName, None) if existing and existing.isEggPack(): # We use >= to allow migrate to be run on currently installed # zenpacks whose version has been changed or for whom new # migrates have been added. if parse_version(packVers) >= parse_version(existing.version): entries.add(entry) else: entries.add(entry) # Starting with the entry representing zenPackId create a list of # all entrypoints # orderedEntries lists entries in the opposite order of that in which # they need to be installed. This is simply for convenience of using # .append() in code below. orderedEntries = [] entriesByName = dict((e.name, e) for e in entries) def AddEntryAndProcessDeps(e): orderedEntries.append(e) for name in [r.project_name for r in e.dist.requires()]: if name in [e.name for e in orderedEntries]: # This entry depends on something that we've already processed. # This might be a circular dependency, might not be. # We are just going to bail however. This should be # very unusual and the user can install deps first to work # around. raise ZenPackException('Unable to resolve ZenPack dependencies.' ' Try installing dependencies first.') if name in entriesByName: # The requirement is an entry that has not yet been processed # here. Add it to the list of entries to install/upgrade. AddEntryAndProcessDeps(entriesByName[name]) else: # The requirement is not in the entries generated above. # This either means that the dep is already installed (this # is likely) or that easy_install missed something and the dep # is not installed/available (this should be unlikely.) pass if zenPackId not in entriesByName: if zenPackId in dmd.ZenPackManager.packs.objectIds(): return [] else: raise ZenPackException('Unable to discover ZenPack named %s' % zenPackId) AddEntryAndProcessDeps(entriesByName[zenPackId]) orderedEntries.reverse() return [e.dist for e in orderedEntries]
def setDescriptors(dmd): """ Set the property descriptors on the ZenPropertyManager class. The transformerFactories parameter is a dictionary that maps a property type to a callable factory that produces instances with transformForGet and transformForSet methods. """ zprops = {} # copy the core zProps # Z_PROPERTIES = id, defaultValue, type , label, description for item in Z_PROPERTIES: id = item[0] type = item[2] zprops[id] = (id, type) Z_PROPERTY_META_DATA[id] = dict() Z_PROPERTY_META_DATA[id]['type'] = type Z_PROPERTY_META_DATA[id]['defaultValue'] = item[1] if len(item) >= 4: Z_PROPERTY_META_DATA[id]['label'] = item[3] if len(item) >= 5: Z_PROPERTY_META_DATA[id]['description'] = item[4] # add zProps from zenpacks from Products.ZenUtils.PkgResources import pkg_resources for zpkg in pkg_resources.iter_entry_points('zenoss.zenpacks'): # fromlist is typically ZenPacks.zenoss fromlist = zpkg.module_name.split('.')[:-1] module = __import__(zpkg.module_name, globals(), locals(), fromlist) if hasattr(module, 'ZenPack'): # Merge ZenPack.packZProperties and ZenPack.packZProperties_data. # packZProperties wins if they disagree about type or defaultValue. for p_id, p_data in module.ZenPack.getZProperties().items(): if p_id in zprops: log.warning("%s tried to override existing %s property.", zpkg.module_name, p_id) continue zprops[p_id] = (p_id, p_data['type']) category = p_data.get('category') if category: setzPropertyCategory(p_id, category) Z_PROPERTY_META_DATA[p_id] = { 'type': p_data.get('type', 'string'), 'defaultValue': p_data.get('defaultValue'), 'label': p_data.get('label'), 'description': p_data.get('description'), 'category': category, } # add zProps from dmd.Devices to catch any that are undefined elsewhere for p_id in dmd.Devices.zenPropertyIds(): p_type = dmd.Devices.getPropertyType(p_id) if p_id not in zprops: zprops[p_id] = (p_id, p_type) log.debug( "Property %s is deprecated. It should be removed " "from the system.", p_id) monkeypatchDescriptors(zprops.values(), dmd.propertyTransformers)
import json import os.path import logging log = logging.getLogger("zen.ZenossStartup") from zope.dottedname.resolve import resolve from Products.CMFCore.utils import ProductsPath from Products.ZenUtils.PkgResources import pkg_resources # Iterate over all ZenPack eggs and load them for zpkg in pkg_resources.iter_entry_points('zenoss.zenpacks'): try: pkg_path = zpkg.load().__path__[0] if pkg_path not in ProductsPath: ProductsPath.insert(0, pkg_path) # Import the pack and tack it onto Products import Products module = resolve(zpkg.module_name) setattr(Products, zpkg.module_name, module) except Exception, e: # This messes up logging a bit, but if we need to report # an error, this saves hours of trying to find out what's going on logging.basicConfig()
def setDescriptors(dmd): """ Set the property descriptors on the ZenPropertyManager class. The transformerFactories parameter is a dictionary that maps a property type to a callable factory that produces instances with transformForGet and transformForSet methods. """ zprops = {} # copy the core zProps # Z_PROPERTIES = id, defaultValue, type , label, description for item in Z_PROPERTIES: id = item[0] type = item[2] zprops[id] = (id, type) Z_PROPERTY_META_DATA[id] = dict() Z_PROPERTY_META_DATA[id]['type'] = type Z_PROPERTY_META_DATA[id]['defaultValue'] = item[1] if len(item) >= 4: Z_PROPERTY_META_DATA[id]['label'] = item[3] if len(item) >= 5: Z_PROPERTY_META_DATA[id]['description'] = item[4] # add zProps from zenpacks from Products.ZenUtils.PkgResources import pkg_resources for zpkg in pkg_resources.iter_entry_points('zenoss.zenpacks'): # fromlist is typically ZenPacks.zenoss fromlist = zpkg.module_name.split('.')[:-1] module = __import__(zpkg.module_name, globals(), locals(), fromlist) if hasattr(module, 'ZenPack'): # Merge ZenPack.packZProperties and ZenPack.packZProperties_data. # packZProperties wins if they disagree about type or defaultValue. for p_id, p_data in module.ZenPack.getZProperties().items(): if p_id in zprops: log.warning( "%s tried to override existing %s property.", zpkg.module_name, p_id ) continue zprops[p_id] = (p_id, p_data['type']) category = p_data.get('category') if category: setzPropertyCategory(p_id, category) Z_PROPERTY_META_DATA[p_id] = { 'type': p_data.get('type', 'string'), 'defaultValue': p_data.get('defaultValue'), 'label': p_data.get('label'), 'description': p_data.get('description'), 'category': category, } # add zProps from dmd.Devices to catch any that are undefined elsewhere for p_id in dmd.Devices.zenPropertyIds(): p_type = dmd.Devices.getPropertyType(p_id) if p_id not in zprops: zprops[p_id] = (p_id, p_type) log.debug( "Property %s is deprecated. It should be removed " "from the system.", p_id ) monkeypatchDescriptors(zprops.values(), dmd.propertyTransformers)