class AddDPToIISDataSource(ZenPackMigration): # Main class that contains the migrate() method. # Note version setting. version = Version(2, 8, 0) def add_status_dp(self, datasource): if not datasource: return if 'status' not in [dp.id for dp in datasource.datapoints()]: datasource.manage_addRRDDataPoint('status') def migrate(self, dmd): # Add state datasource/datapoint to subclasses # This will catch any device specific templates and make this migration quicker log.info('Searching for IISSiteDataSources.') results = ICatalogTool( dmd.Devices.Server.Microsoft).search(IISSiteDataSource) if results.total == 0: return progress = progresslog.ProgressLogger(log, prefix="IISSiteSiteDataSource", total=results.total, interval=PROGRESS_LOG_INTERVAL) for result in results: try: datasource = result.getObject() except Exception: continue progress.increment() self.add_status_dp(datasource)
class renameEnterprisePlugins(ZenPackMigration): """ """ version = Version(2, 0, 0) def migrate(self, pack): try: z = pack.dmd.ZenPackManager.packs._getOb( 'ZenPacks.zenoss.EnterpriseLinux') except AttributeError: return log.info('Deprecating EnterpriseLinux plugins and parsers.') zpath = os.path.join(z.path(), 'modeler/plugins/zenoss/cmd/linux') for filename in ('alt_kernel_name', 'rpm', 'sudo_dmidecode'): self.renameFile(zpath, filename) zpath = os.path.join(z.path(), 'parsers/linux') for filename in ('diskstats', 'ifconfig'): self.renameFile(zpath, filename) def renameFile(self, zpath, filename): if not zpath or not filename: return if os.path.exists(os.path.join(zpath, filename + '.py')): os.rename(os.path.join(zpath, filename + '.py'), os.path.join(zpath, filename + '_deprecated.py'))
class makeoltab: version = Version(1, 0, 1) olMapTab = { 'id': 'olgeomaptab', 'name': 'OpenLayers Map', 'action': 'OLGeoMapTab', 'permissions': (permissions.view, ) } def _registerOLMapTab(self, dmd): # actions = list(dmd.Locations.factory_type_information[0]['actions']) # for i in range(len(actions)): # if(self.olMapTab['id'] in actions[i].values()): # return # actions.append(self.olMapTab) # dmd.Locations.factory_type_information[0]['actions'] = tuple(actions) # transaction.commit() # print "Reg: ",dmd.Locations.factory_type_information pass def migrate(self, pack): # dmd = pack.__primary_parent__.__primary_parent__ # self._registerOLMapTab(dmd) pass def recover(self, pack): pass
class DefaultZProps(ZenPackMigration): version = Version(2, 4, 0) def migrate(self, pack): dmd = pack.dmd set_default_if_none = { 'zOpenStackNeutronConfigDir': '/etc/neutron', 'zOpenStackAMQPUsername': '******' } remove_local_copy_if_default = { 'Server/SSH/Linux/NovaHost': [ 'zOpenStackRunNovaManageInContainer', 'zOpenStackRunVirshQemuInContainer', 'zOpenStackRunNeutronCommonInContainer' ] } for zprop, newval in set_default_if_none.iteritems(): if dmd.Devices.hasProperty(zprop): if dmd.Devices.getZ(zprop) == '': log.info("Setting default of %s to %s", zprop, newval) dmd.Devices.setZenProperty(zprop, newval) for deviceclass, zprops in remove_local_copy_if_default.iteritems(): try: dc = dmd.Devices.getObjByPath(deviceclass) except KeyError: continue for zprop in zprops: if dc.hasProperty(zprop) and dc.getZ(zprop) == dmd.Devices.getZ(zprop): log.info("Removing redundant default value for %s", zprop) dc._delProperty(zprop)
class AddHardDiskPlugin(ZenPackMigration): version = Version(2, 7, 0) def migrate(self, pack): new_plugin = 'zenoss.winrm.HardDisks' ref_plugin = 'zenoss.winrm.FileSystems' dcObject = pack.dmd.Devices.getOrganizer('/Server/Microsoft/Windows') zCollectorPlugins = dcObject.zCollectorPlugins if new_plugin not in zCollectorPlugins: log.debug('Adding HardDisks modeler plugin to zCollectorPlugins for' ' /Server/Microsoft/Windows') zCollectorPlugins.append(new_plugin) dcObject.setZenProperty('zCollectorPlugins', zCollectorPlugins) # apply also to any sub-device classes or devices with locally defined plugins for ob in dcObject.getOverriddenObjects("zCollectorPlugins", showDevices=True): collector_plugins = ob.zCollectorPlugins # skip if object doesn't use the FileSystems plugin if ref_plugin not in collector_plugins: continue if new_plugin not in collector_plugins: log.debug('Adding HardDisks modeler plugin to zCollectorPlugins for {}'.format(ob.getDmdKey())) collector_plugins.append(new_plugin) ob.setZenProperty('zCollectorPlugins', collector_plugins)
class RemoveEventInst(ZenPackMigration): # Main class that contains the migrate() method. # Note version setting. version = Version(2, 8, 0) def migrate(self, dmd): # Remove unnecessary mappings def remove_mapping(path, instances): try: org = dmd.Events.getOrganizer(path) results = ICatalogTool(org).search(EventClassInst, query=In('id', instances)) if results.total: log.info( 'Removing deprecated Event Class Instances from {}'. format(path)) for instance in instances: if safe_hasattr(org, instance): org.removeInstances([instance]) except Exception: pass for path, instances in PATH_INSTANCES.iteritems(): remove_mapping(path, instances) # Remove unnecessary sub classes log.info( 'Searching for deprecated Event Class subclasses and mappings to remove.' ) for path in BAD_PATHS: try: org = dmd.Events.getOrganizer(path) except Exception: continue dmd.Events.manage_deleteOrganizer(org.getDmdKey())
class MigrateMSExchangeIS(ZenPackMigration): # Main class that contains the migrate() method. # Note version setting. version = Version(2, 4, 1) def migrate(self, dmd): # This is the main method. It removes the 'MSExchangeIS' monitoring template. # MSExchangeIS is also the name of a winrmservice so do not remove if a user # has created it. Also change msexchangeversion so we know how to find # the correct monitoring template organizer = dmd.Devices.getOrganizer('/Server/Microsoft') if organizer: ok_to_remove = True for template in organizer.getRRDTemplates(): if 'MSExchangeIS' in template.id: if 'DefaultService' in [ ds.id for ds in template.getRRDDataSources() ]: ok_to_remove = False break if ok_to_remove: organizer.manage_deleteRRDTemplates(['MSExchangeIS']) try: for device in organizer.devices(): if device.msexchangeversion == 'MSExchangeIS': device.msexchangeversion = 'MSExchangeInformationStore' except: pass
class AddOSRelations(ZenPackMigration): version = Version(2, 6, 3) def migrate(self, pack): results = ICatalogTool(pack.dmd.Devices).search(Device) LOG.info("starting: %s total devices", results.total) progress = progresslog.ProgressLogger(LOG, prefix="progress", total=results.total, interval=PROGRESS_LOG_INTERVAL) objects_migrated = 0 for result in results: try: if self.updateRelations(result.getObject()): objects_migrated += 1 except Exception: LOG.exception("error updating relationships for %s", result.id) progress.increment() LOG.info("finished: %s of %s devices required migration", objects_migrated, results.total) def updateRelations(self, device): for relname in (x[0] for x in OperatingSystem._relations): if not device.os.aqBaseHasAttr(relname): device.os.buildRelations() return True return False
class AddZenmapperService(ZenPackMigration): version = Version(1, 2, 1) def migrate(self, pack): # Apply only on ZP upgrade. if pack.prevZenPackVersion is None: return try: import servicemigration as sm except ImportError: # No servicemigrations, which means we are on Zenoss 4.2.x or 5.0.x # No need to install service on Zenoss 5.0.x as service install # performed on each upgrade. return sm.require("1.0.0") try: ctx = sm.ServiceContext() except: log.warn("Couldn't generate service context, skipping.") return # Check whether zenmapper service is already installed. services = filter(lambda s: s.name == "zenmapper", ctx.services) if not services: log.info('Deploying zenmapper service') pack.installServices()
class ChangeMonitoredTemplateToDeviceWMI(ZenPackMigration): """ Change Monitoring template for MSSQLServer from Device (SNMP-oriented) to Device_WMI """ version = Version(2, 0, 3) def migrate(self, pack): try: devices = pack.dmd.getDmdRoot("Devices") mssql_dc = devices.Server.Windows.WMI.MSSQLServer templates = mssql_dc.zDeviceTemplates changed = False if 'Device' in templates: templates.remove('Device') changed = True if 'Device_WMI' not in templates: templates.insert(0, 'Device_WMI') changed = True if changed: mssql_dc.setZenProperty('zDeviceTemplates', templates) except Exception as e: log.warn( "Failed to modify zDeviceTemplates on MSSQLServer device class, %s", e)
class MigrateThreadCountDataPoints(ZenPackMigration): version = Version(3, 1, 5) def migrate(self, pack): log.info("MigrateThreadCountDataPoints migrate") #find devices with either the java or zenjmx templat #and delete the rrd file for the threadcount datapoint for d in pack.dmd.Devices.getSubDevices(): log.debug("MigrateThreadCountDataPoints device %s" % d.id) for template in d.getRRDTemplates(): templateId = template.getPrimaryDmdId() log.debug("MigrateThreadCountDataPoints template %s" % templateId) dpName = None if templateId == '/Devices/rrdTemplates/Java': dpName = 'Thread Count_ThreadCount' elif templateId == '/Devices/rrdTemplates/ZenJMX': dpName = 'ZenJMX Thread Count_ThreadCount' if dpName: log.debug("MigrateThreadCountDataPoints dpName %s" % dpName) perfConf = d.getPerformanceServer() log.debug("MigrateThreadCountDataPoints perfConf %s" % perfConf.id) perfConf.deleteRRDFiles(device=d.id, datapoint=dpName)
def afterSetUp(self): super(TestMigrate, self).afterSetUp() self.version = Version(9, 9, 9) self.migration = Migration() self.oldCurrentVersion = self.migration._currentVersion self.migration._currentVersion = self.getTestVersion
class FixCpuAlias( ZenPackMigration ): """ The former cpu alias formula was incorrect. It was '__EVAL:str(len(here.hw.cpus())) + ',/,1,EXC,-' but should have been '__EVAL:str(len(here.hw.cpus())) + ',/,100,EXC,-' """ version = Version(1, 0, 0) def migrate(self, pack): try: log.info( 'Fixing cpu__pct alias if necessary') sshLinux = getSshLinux( pack.dmd ) if sshLinux: deviceTemplate = sshLinux.rrdTemplates.Device cpuIdleDp = deviceTemplate.datasources.cpu.datapoints.ssCpuIdle if cpuIdleDp.hasAlias( 'cpu__pct' ): cpuAlias = cpuIdleDp.aliases.cpu__pct # If it has been changed already, leave it alone if cpuAlias.formula == "__EVAL:str(len(here.hw.cpus())) + ',/,1,EXC,-'": log.debug( 'Modifying cpu__pct alias on cpuIdle datapoint' ) cpuAlias.formula == "__EVAL:str(len(here.hw.cpus())) + ',/,100,EXC,-'" except Exception, e: log.debug( 'Exception trying to modify cpu__pct alias' )
class UpdateZenJMXTemplates(ZenPackMigration): version = Version(3, 1, 2) def migrate(self, pack): log.debug("UpdateZenJMXTemplates migrate") zenJMXTemplate = pack.dmd.Devices.rrdTemplates.ZenJMX #delete old datasources def deleteDataSource(dsId): log.debug("deleteDataSource for %s", dsId) ds = None try: log.debug("looking up datasource") ds = zenJMXTemplate.datasources._getOb(dsId) log.debug("found datasource") except AttributeError: log.debug("error looking up datasource") log.debug("%s datasource does not exist", dsId) return pack.manage_deletePackable([ds.getPrimaryUrlPath()]) zenJMXTemplate.manage_deleteRRDDataSources([dsId]) deleteDataSource('Non-Heap Memory') deleteDataSource('Heap Memory') deleteDataSource('Open File Descriptors') deleteDataSource('Thread Count') #remote graph datapoints that were in the deleted datasources def deleteGraphPoint(graphId, dpId): log.debug("deleteGraphPoint for %s", dpId) graph = None try: graph = zenJMXTemplate.graphDefs._getOb(graphId) except AttributeError: log.debug("%s graph def does not exist", graphId) return gp = None try: gp = graph.graphPoints._getOb(dpId) except AttributeError: log.debug("%s graph point does not exist on graph %s", dpId, graphId) return pack.manage_deletePackable([gp.getPrimaryUrlPath()]) graph.manage_deleteGraphPoints([dpId]) deleteGraphPoint('ZenJMX Non-Heap Memory','Non-Heap Memory_committed') deleteGraphPoint('ZenJMX Non-Heap Memory','Non-Heap Memory_used') deleteGraphPoint('ZenJMX Heap Memory','Heap Memory_used') deleteGraphPoint('ZenJMX Heap Memory','Heap Memory_committed') deleteGraphPoint('ZenJMX Open File Descriptors', 'Open File Descriptors_OpenFileDescriptorCount') deleteGraphPoint('ZenJMX Thread Count','Thread Count_ThreadCount')
class RemoveExtraClusterPlugins(ZenPackMigration): # Main class that contains the migrate() method. # Note version setting. version = Version(2, 9, 1) def get_objects(self, dmd): for ob in dmd.Devices.Server.Microsoft.Cluster.getSubOrganizers() +\ dmd.Devices.Server.Microsoft.Cluster.getSubDevices(): yield ob def migrate(self, dmd): for ob in self.get_objects(dmd): self.remove_extra(ob) def remove_extra(self, thing): """Removes extra occurrences of WinCluster in zCollectorPlugins""" if not hasattr(thing, 'zCollectorPlugins'): return if not thing.isLocal('zCollectorPlugins'): return zCollectorPlugins = thing.zCollectorPlugins if zCollectorPlugins.count('zenoss.winrm.WinCluster') > 1: thing.setZenProperty('zCollectorPlugins', list(set(zCollectorPlugins)))
class RemoveConnectionsCatalog(ZenPackMigration): version = Version(1, 2, 1) def migrate(self, pack): log.info('Removing ConnectionsCatalog') if hasattr(pack.dmd.zport, 'connections_catalog'): pack.dmd.zport._delObject('connections_catalog')
def testStepDeterminationInPlace(self): self.migration.allSteps = realVersionSteps self.version = Version(4, 2, 0) steps = self.migration.determineSteps() self.assertEqual(len(steps), 1) self.assertIncludesVersions(steps, [step420.version])
class RemoveMSExchangeTemplates(ZenPackMigration): version = Version(2, 8, 2) def migrate(self, dmd): for org in dmd.Devices.Server.Microsoft.getSubOrganizers(): if set(('MSExchange2010IS', 'MSExchange2013IS')).issubset(org.zDeviceTemplates): org.zDeviceTemplates.remove('MSExchange2013IS') org.setZenProperty('zDeviceTemplates', org.zDeviceTemplates)
def testGetEarliestAppropriateStepVersion(self): m = Migration(noopts=True) self.assertEquals( Version(1, 0, 70), m.getEarliestAppropriateStepVersion(codeVers=Version(1, 1, 50))) self.assertEquals( Version(1, 1, 70), m.getEarliestAppropriateStepVersion(codeVers=Version(1, 1, 70))) self.assertEquals( Version(1, 1, 70), m.getEarliestAppropriateStepVersion(codeVers=Version(1, 1, 99))) self.assertEquals( Version(1, 1, 70), m.getEarliestAppropriateStepVersion(codeVers=Version(1, 2, 0))) m.allSteps.append(MyTestStep(98, 3, 71)) self.assertEquals( Version(98, 3, 70), m.getEarliestAppropriateStepVersion(codeVers=Version(99, 0, 1)))
class removeOldHPEVAReports(ZenPackMigration): version = Version(1, 8) def migrate(self, pack): if hasattr(pack.dmd.Reports, 'Device Reports'): devReports = pack.dmd.Reports['Device Reports'] if hasattr(devReports, 'HPEVA'): devReports._delObject('HPEVA')
class MyTestStep(Step): def __init__(self, major, minor, micro): self.version = Version(major, minor, micro) def __cutover__(self): pass def __cleanup__(self): pass def name(self): return 'MyTestStep_%s' % self.version.short()
class fixRelations(ZenPackMigration): version = Version(1, 8) def migrate(self, pack): for d in pack.dmd.Devices.getSubDevices(lambda dev:isinstance(dev, dt)): d.hw.buildRelations() d.os.buildRelations() for comp in d.getDeviceComponents(): comp.buildRelations()
class InstallTopLevel: version = Version(1, 1, 0) def migrate(self, pack): if not getattr(pack.dmd, 'TopLevel', None): log.info("Installing TopLevel object.") manage_addTopLevel(pack.dmd) else: log.info("TopLevel object already exists.")
class ConvertJMXDataSources(ZenPackDataSourceMigrateBase): version = Version(3, 1, 2) # These provide for conversion of datasource instances to the new class dsClass = JMXDataSource oldDsModuleName = 'Products.ZenJMX.datasources.JMXDataSource' oldDsClassName = 'JMXDataSource' # Reindex all applicable datasource instances reIndex = True
class ConvertMailTxDataSources(ZenPackDataSourceMigrateBase): version = Version(2, 0, 1) # These provide for conversion of datasource instances to the new class dsClass = MailTxDataSource oldDsModuleName = 'Products.ZenMailTx.datasources.MailTxDataSource' oldDsClassName = 'MailTxDataSource' # Reindex all applicable datasource instances reIndex = True
class MigrateConnectionString(ZenPackMigration): ''' Main class that contains the migrate() method. Note version setting. ''' version = Version(3, 0, 0) def migrate(self, dmd): ''' This is the main method. Its searches for overridden objects (templates) and then migrates the data to the new format or properties. In this case bound objects get assigned the new modeler pluging. ''' overridden_on = dmd.Devices.getOverriddenObjects('zDeviceTemplates', showDevices=True) for thing in overridden_on: if TEMPLATE_NAME in thing.zDeviceTemplates: self.enable_plugin(thing) self.populate_connection_strings(thing) def enable_plugin(self, thing): ''' Associate a collector plugin with the thing we have found. zCollectorPlugins is used by ModelerService.createDeviceProxy() to add associated (modeler) plugins to the list for self-discovery. ModelerService.remote_getDeviceConfig() actually calls the modelers. ''' current_plugins = list(thing.zCollectorPlugins) if MODELER_PLUGIN_NAME in current_plugins: return log.info("Adding %s modeler plugin to %s", MODELER_PLUGIN_NAME, name_for_thing(thing)) current_plugins.append(MODELER_PLUGIN_NAME) thing.setZenProperty('zCollectorPlugins', current_plugins) def populate_connection_strings(self, thing): ''' Just a helper method to collect data for this ZP ''' if thing.zMySQLConnectionString: return if thing.zMySqlUsername: connection_string = '{"user":"******","passwd":"%s","port":"%s"}' % \ (thing.zMySqlUsername, thing.zMySqlPassword, thing.zMySqlPort) log.info("Setting zMySQLConnectionString for %s", name_for_thing(thing)) thing.setZenProperty('zMySQLConnectionString', [connection_string]) thing.setZenProperty('zMySqlUsername', '') thing.setZenProperty('zMySqlPassword', '') thing.setZenProperty('zMySqlPort', '')
class ConvertApacheMonitorDataSources(ZenPackDataSourceMigrateBase): version = Version(2, 0, 2) # These provide for conversion of datasource instances to the new class dsClass = ApacheMonitorDataSource oldDsModuleName = 'Products.ApacheMonitor.datasources' \ '.ApacheMonitorDataSource' oldDsClassName = 'ApacheMonitorDataSource' # Reindex all applicable datasource instances reIndex = True
class RemoveUnusedPort(ZenPackMigration): version = Version(1, 2, 0) def migrate(self, dmd): port_to_remove = 9090 zopeConfig = ZopeConfig() # Return if 9090 is a real port in use by the Zope configuration if port_to_remove in zopeConfig.zope_ports: return nginxConfig = NginxConfig() nginxConfig.remove_zope_server_by_port(port_to_remove)
class MigrateThresholds(ZenPackMigration): # Main class that contains the migrate() method. # Note version setting. version = Version(2, 4, 5) def migrate(self, dmd): # Remove unnecessary objects that were inadvertently added. organizer = dmd.Devices.getOrganizer('/Server/Microsoft') if organizer: for t in organizer.getRRDTemplates(): if t.id == 'Device': t.manage_deleteRRDThresholds(THRESHOLDS)
class removeOldHPReports(ZenPackMigration): version = Version(2, 1) def migrate(self, pack): if hasattr(pack.dmd.Reports, 'Device Reports'): devReports = pack.dmd.Reports['Device Reports'] if hasattr(devReports, 'HP iLO Boards'): devReports._delObject('HP iLO Boards') if hasattr(devReports, 'HP Storage Controllers'): devReports._delObject('HP Storage Controllers')
def __init__(self, major, minor, micro): self.version = Version(major, minor, micro)