コード例 #1
0
 def cutover(self, dmd):
     if os.path.exists(self.cfname) and "genconf: command not found" in open(self.cfname).read():
         log.info("creating new zenrrdcached.conf via genconf")
         try:
             atomicWrite(self.cfname, subprocess.check_output([zenPath("bin/zenrrdcached"), "genconf"]),)
         except subprocess.CalledProcessError as e:
             log.error("zenrrdcached.conf migration failed ({0}): {1}".format(e.errno, e.strerror))
             raise e
コード例 #2
0
 def saveHystState(self):
     log.debug("saving hysteresis state")
     atomicWrite(
         zenPath('var/%s_%s_hystCount.pickle' %
                 (self.context().deviceName, self.name())),
         pickle.dumps(self.hystCount),
         raiseException=False,
     )
     atomicWrite(
         zenPath('var/%s_%s_hystFlag.pickle' %
                 (self.context().deviceName, self.name())),
         pickle.dumps(self.hystFlag),
         raiseException=False,
     )
コード例 #3
0
ファイル: PBDaemon.py プロジェクト: zenoss/zenoss-prodbin
 def _signalZenHubAnswering(self, answering):
     """
     Write or remove file that the ZenHub_answering health check uses to report status.
     @param answering: true if ZenHub is answering, False, otherwise.
     """
     self.log.debug('_signalZenHubAnswering(%s)' % answering)
     filename = 'zenhub_connected'
     signalFilePath = zenPath('var', filename)
     if answering:
         self.log.debug('writing file at %s' % signalFilePath)
         atomicWrite(signalFilePath, '')
     else:
         try:
             self.log.debug('removing file at %s' % signalFilePath)
             os.remove(signalFilePath)
         except Exception as e:
             self.log.debug('ignoring %s exception (%s) removing file %s' % (e.__class__, e.message, signalFilePath))
コード例 #4
0
ファイル: PBDaemon.py プロジェクト: njervis/zenoss-prodbin
 def _signalZenHubAnswering(self, answering):
     """
     Write or remove file that the ZenHub_answering health check uses to report status.
     @param answering: true if ZenHub is answering, False, otherwise.
     """
     self.log.debug('_signalZenHubAnswering(%s)' % answering)
     filename = 'zenhub_connected'
     signalFilePath = zenPath('var', filename)
     if answering:
         self.log.debug('writing file at %s' % signalFilePath)
         atomicWrite(signalFilePath, '')
     else:
         try:
             self.log.debug('removing file at %s' % signalFilePath)
             os.remove(signalFilePath)
         except Exception as e:
             self.log.debug('ignoring %s exception (%s) removing file %s' %
                            (e.__class__, e.message, signalFilePath))
コード例 #5
0
    def handleUploadedFile(self, REQUEST):
        """
        Assumes the file to be a mib so we need to create a mib module with
        its contents
        File will be available with REQUEST.upload
        """
        filename = REQUEST.upload.filename
        mibs = REQUEST.upload.read()
        savedMIBPath = zenPath('/var/ext/uploadedMIBs/%s' % filename)
        atomicWrite(savedMIBPath, mibs, raiseException=True, createDir=True)

        # create the job
        mypath = self.absolute_url_path().replace('/zport/dmd/Mibs', '')
        if not mypath:
            mypath = '/'
        commandArgs = [binPath('zenmib'), 'run', savedMIBPath,
                '--path=%s' % mypath]
        return self.dmd.JobManager.addJob(SubprocessJob,
                   description="Load MIB at %s" % mypath,
                   kwargs=dict(cmd=commandArgs))
コード例 #6
0
ファイル: ZenPackCmd.py プロジェクト: zenoss/zenoss-prodbin
def InstallDistAsZenPack(dmd, dist, eggPath, link=False, filesOnly=False,
                         previousVersion=None, forceRunExternal=False,
                         fromUI=False, serviceId=None, ignoreServiceInstall=False):
    """
    Given an installed dist, install it into Zenoss as a ZenPack.
    Return the ZenPack instance.
    """

    @transact
    def transactional_actions():
        # Instantiate ZenPack
        entryMap = pkg_resources.get_entry_map(dist, ZENPACK_ENTRY_POINT)
        if not entryMap or len(entryMap) > 1:
            raise ZenPackException('A ZenPack egg must contain exactly one'
                    ' zenoss.zenpacks entry point.  This egg appears to contain'
                    ' %s such entry points.' % len(entryMap))
        packName, packEntry = entryMap.items()[0]
        runExternalZenpack = True
        #if zenpack with same name exists we can't load both modules
        #installing new egg zenpack will be done in a sub process
        def doesExist():
            existing = dmd.ZenPackManager.packs._getOb(packName, None)
            if existing:
                log.info("Previous ZenPack exists with same name %s" % packName)
            return existing
        if filesOnly or not doesExist():
            if filesOnly:
                log.info("ZenPack files only install: %s" % packName)
            #running files only or zenpack by same name doesn't already exists
            # so no need to install the zenpack in an external process
            runExternalZenpack = False
            module = packEntry.resolve()
            if hasattr(module, 'ZenPack'):
                zenPack = module.ZenPack(packName)
            else:
                zenPack = ZenPack(packName)
            zenPack.eggPack = True
            CopyMetaDataToZenPackObject(dist, zenPack)
            if filesOnly:
                for loader in (ZPL.ZPLDaemons(), ZPL.ZPLBin(), ZPL.ZPLLibExec()):
                    loader.load(zenPack, None)
            if fromUI and not zenPack.installableFromUI:
                raise ZenPackException("This ZenPack cannot be installed through the UI.")

        if not filesOnly:
            # Look for an installed ZenPack to be upgraded.  In this case
            # upgraded means that it is removed before the new one is installed
            # but that its objects are not removed and the packables are
            # copied to the new instance.
            existing = dmd.ZenPackManager.packs._getOb(packName, None)
            if not existing and zenPack.prevZenPackName:
                existing = dmd.ZenPackManager.packs._getOb(
                                    zenPack.prevZenPackName, None)

            deferFileDeletion = False
            packables = []
            upgradingFrom = None
            if existing:
                upgradingFrom = existing.version
                for p in existing.packables():
                    packables.append(p)
                    existing.packables.removeRelation(p)
                if existing.isEggPack():
                    forceNoFileDeletion = existing.eggPath() == dist.location
                    RemoveZenPack(dmd, existing.id,
                                    skipDepsCheck=True, leaveObjects=True,
                                    forceNoFileDeletion=forceNoFileDeletion,
                                    uninstallEgg=False)
                else:
                    # Don't delete files, might still be needed for
                    # migrate scripts to be run below.
                    deferFileDeletion = True
                    oldzenpack.RemoveZenPack(dmd, existing.id,
                                    skipDepsCheck=True, leaveObjects=True,
                                    deleteFiles=False)

            if runExternalZenpack or forceRunExternal:
                log.info("installing zenpack %s; launching process" % packName)
                cmd = [binPath('zenpack')]
                if link:
                    cmd += ["--link"]
                cmd += ["--install", eggPath]
                if upgradingFrom:
                    cmd += ['--previousversion', upgradingFrom]
                if fromUI:
                    cmd += ["--fromui"]
                if serviceId:
                    cmd += ['--service-id', serviceId]
                if ignoreServiceInstall:
                    cmd += ['--ignore-service-install']

                cmdStr = " ".join(cmd)
                log.debug("launching sub process command: %s" % cmdStr)
                p = subprocess.Popen(cmdStr,
                                shell=True)
                out, err = p.communicate()
                p.wait()
                if p.returncode:
                    raise ZenPackException('Error installing the egg (%s): %s' %
                                           (p.returncode, err))
                dmd._p_jar.sync()
            else:
                dmd.ZenPackManager.packs._setObject(packName, zenPack)
                zenPack = dmd.ZenPackManager.packs._getOb(packName)
                #hack because ZenPack.install is overridden by a lot of zenpacks
                #so we can't change the signature of install to take the
                #previousVerison
                zenPack.prevZenPackVersion = previousVersion
                if ignoreServiceInstall:
                    ZenPack.ignoreServiceInstall = True
                zenPack.install(dmd)
                zenPack.prevZenPackVersion = None

            try:
                zenPack = dmd.ZenPackManager.packs._getOb(packName)
                for p in packables:
                    pId = p.getPrimaryId()
                    try:
                        # make sure packable still exists; could be deleted by a
                        # migrate
                        getObjByPath(dmd, pId)
                        log.debug("adding packable relation for id %s", pId)
                        zenPack.packables.addRelation(p)
                    except (KeyError, zExceptions.NotFound):
                        log.debug('did not find packable %s',pId)
            except AttributeError as e:
                # If this happens in the child process or during the non-upgrade
                # flow, reraise the exception
                if not runExternalZenpack:
                    raise

                # This specific error will occur when the version of the ZenPack
                # being installed subclasses Products.ZenModel.ZenPack, but the
                # previous version of the ZenPack did not.
                if str(e) == "'ZenPack' object has no attribute '__of__'":
                    zenPack = ZenPack(packName)
                else:
                    # This is the signature error of class-loading issues
                    # during zenpack upgrade.  The final state should be okay,
                    # except that modified packables may be lost.
                    message = "There has been an error during the post-" + \
                              "installation steps for the zenpack %s.  In " + \
                              "most cases, no further action is required.  If " + \
                              "issues persist, please reinstall this zenpack."
                    message = message % packName
                    log.warning( message )
                    raise NonCriticalInstallError( message )

            cleanupSkins(dmd)
            return zenPack, deferFileDeletion, existing
        else:
            return zenPack, False, True

    info = ReadZenPackInfo(dist)
    if ('compatZenossVers' in info):
        vers = info['compatZenossVers']
        if vers[0] in string.digits:
            vers = '==' + vers
        try:
            req = pkg_resources.Requirement.parse('zenoss%s' % vers)
        except ValueError:
            raise ZenPackException("Couldn't parse requirement zenoss%s" % vers)
        if not req.__contains__(ZENOSS_VERSION):
            raise ZenPackException("Incompatible Zenoss Version %s, need %s" % (ZENOSS_VERSION, vers))

    ZenPack.currentServiceId = serviceId
    zenPack, deferFileDeletion, existing = transactional_actions()
    packInfos = {}
    oldPacksDump = getPacksDump()
    for pack in dmd.ZenPackManager.packs():
        try:
            eggPath = ""
            eggPath = pack.eggPath()
        except Exception:
            if pack.id in oldPacksDump:
                eggPath = oldPacksDump[pack.id]
        packInfos[pack.id] = {
            "id": pack.id,
            "version": pack.version,
            "dependencies": pack.dependencies,
            "eggPack": pack.eggPack,
            "eggPath": eggPath,
            "compatZenossVers": pack.compatZenossVers,
            "createdTime": pack.createdTime.ISO8601(),
        }
    atomicWrite(PACKS_DUMP, json.dumps(packInfos))

    if not filesOnly and deferFileDeletion:
        # We skipped deleting the existing files from filesystem
        # because maybe they'd be needed in migrate scripts.
        # Delete them now
        oldZpDir = zenPath('Products', existing.id)
        if os.path.islink(oldZpDir):
            os.remove(oldZpDir)
        else:
            shutil.rmtree(oldZpDir)

    return zenPack
コード例 #7
0
 def saveCounters(self):
     atomicWrite(
         self._getCountersFile(),
         pickle.dumps(self.counters),
         raiseException=False,
     )
コード例 #8
0
ファイル: zenmodeler.py プロジェクト: bbc/zenoss-prodbin
 def saveCounters(self):
     atomicWrite(
         self._getCountersFile(),
         pickle.dumps(self.counters),
         raiseException=False,
     )
コード例 #9
0
ファイル: ZenPackCmd.py プロジェクト: bbc/zenoss-prodbin
        try:
            eggPath = ""
            eggPath = pack.eggPath()
        except Exception:
            if pack.id in oldPacksDump:
                eggPath = oldPacksDump[pack.id]
        packInfos[pack.id] = {
            "id": pack.id,
            "version": pack.version,
            "dependencies": pack.dependencies,
            "eggPack": pack.eggPack,
            "eggPath": eggPath,
            "compatZenossVers": pack.compatZenossVers,
            "createdTime": pack.createdTime.ISO8601(),
        }
    atomicWrite(PACKS_DUMP, json.dumps(packInfos))

    if not filesOnly and deferFileDeletion:
        # We skipped deleting the existing files from filesystem
        # because maybe they'd be needed in migrate scripts.
        # Delete them now
        oldZpDir = zenPath('Products', existing.id)
        if os.path.islink(oldZpDir):
            os.remove(oldZpDir)
        else:
            shutil.rmtree(oldZpDir)

    return zenPack

def getPacksDump():
    packs = {}
コード例 #10
0
ファイル: PBDaemon.py プロジェクト: c0ns0le/zenoss-4
 def saveCounters(self):
     atomicWrite(
         zenPath('var/%s_counters.pickle' % self.name),
         pickle.dumps(self.counters),
         raiseException=False,
     )
コード例 #11
0
ファイル: PBDaemon.py プロジェクト: bbc/zenoss-prodbin
 def saveCounters(self):
     atomicWrite(
         zenPath('var/%s_counters.pickle' % self.name),
         pickle.dumps(self.counters),
         raiseException=False,
     )
コード例 #12
0
ファイル: __init__.py プロジェクト: vencis/docker-misc
 def _rewriteEasyInstallPthFile(self, data):
     if isinstance(data, list):
         data = '\n'.join(data)
     atomicWrite(self.easyInstallPthFileName, data)
コード例 #13
0
 def touch(self):
     """Create the file."""
     atomicWrite(self.__signalFilePath, '')
     self.__log.debug("Created file '%s'", self.__signalFilePath)
コード例 #14
0
ファイル: zenhubworker.py プロジェクト: zenoss/zenoss-prodbin
 def touch(self):
     """Create the file."""
     atomicWrite(self.__signalFilePath, '')
     self.__log.debug("Created file '%s'", self.__signalFilePath)
コード例 #15
0
        try:
            eggPath = ""
            eggPath = pack.eggPath()
        except Exception:
            if pack.id in oldPacksDump:
                eggPath = oldPacksDump[pack.id]
        packInfos[pack.id] = {
            "id": pack.id,
            "version": pack.version,
            "dependencies": pack.dependencies,
            "eggPack": pack.eggPack,
            "eggPath": eggPath,
            "compatZenossVers": pack.compatZenossVers,
            "createdTime": pack.createdTime.ISO8601(),
        }
    atomicWrite(PACKS_DUMP, json.dumps(packInfos))

    if not filesOnly and deferFileDeletion:
        # We skipped deleting the existing files from filesystem
        # because maybe they'd be needed in migrate scripts.
        # Delete them now
        oldZpDir = zenPath('Products', existing.id)
        if os.path.islink(oldZpDir):
            os.remove(oldZpDir)
        else:
            shutil.rmtree(oldZpDir)

    return zenPack


def getPacksDump():
コード例 #16
0
 def _rewriteEasyInstallPthFile(self, data):
     if isinstance(data, list):
         data = '\n'.join(data)
     atomicWrite(self.easyInstallPthFileName, data)