Ejemplo n.º 1
0
    def doManifestLogFile(action):
        """ do manifest log file """
        service = request.params.get('service', '')
        package = request.params.get('package', '')
        manifest = request.params.get('manifest', 'active')

        if (service == '' or package == ''):
            c.errorMsg = 'missing service or package parameter from request'
            c.errorCode = Errors.LOG_PARAM_REQUIRED
            return render('/derived/error.html')
        print 'service/package/manifest ', service, package, manifest
        packagePathStr = packagePath(service, package, manifest)
        print 'package path ', packagePathStr
        pkgInit = PkgInitConfig(service, package, manifest)
        pkgConfig = pkgInit.getConfigs()
        if not pkgConfig:
            c.errorMsg = 'cronus.ini does not exist, view log needs cronus.ini to know log location, please check your cronus package to make sure cronus.ini exist and have property logAppDir'
            c.errorCode = Errors.CRONUS_INI_EMPTY_NOT_FOUND
            return render('/derived/error.html')
        print '*** packageConfig ', pkgConfig
        manifestFileName = pkgConfig['logManifestFile']
        if (action == 'download'):
            return downloadFile(os.path.join(packagePathStr, manifestFileName))
        if (action == 'tail'):
            lines = request.params.get('size', '100')
            return tailFile(os.path.join(packagePathStr, manifestFileName),
                            lines)
        if (action == 'list'):
            return manifestFileName
Ejemplo n.º 2
0
    def doManifestLogFile(action):
        """ do manifest log file """
        service = request.params.get('service', '')
        package = request.params.get('package', '')
        manifest = request.params.get('manifest', 'active')

        if (service == '' or package == ''):
            c.errorMsg = 'missing service or package parameter from request'
            c.errorCode = Errors.LOG_PARAM_REQUIRED
            return render('/derived/error.html')
        print 'service/package/manifest ', service, package, manifest
        packagePathStr = packagePath(service, package, manifest)
        print 'package path ', packagePathStr
        pkgInit = PkgInitConfig(service, package, manifest)
        pkgConfig = pkgInit.getConfigs()
        if not pkgConfig:
            c.errorMsg = 'cronus.ini does not exist, view log needs cronus.ini to know log location, please check your cronus package to make sure cronus.ini exist and have property logAppDir'
            c.errorCode = Errors.CRONUS_INI_EMPTY_NOT_FOUND
            return render('/derived/error.html')
        print '*** packageConfig ', pkgConfig
        manifestFileName = pkgConfig['logManifestFile']
        if (action == 'download'):
            return downloadFile(os.path.join(packagePathStr, manifestFileName))
        if (action == 'tail'):
            lines = request.params.get('size', '100')
            return tailFile(os.path.join(packagePathStr, manifestFileName), lines)
        if (action == 'list'):
            return manifestFileName
Ejemplo n.º 3
0
    def _obtainCmdExecThreads(self, exeName, service, manifest, activateFlow):
        """start the threads to execute cmd in each package in the service/manifest"""

        execThreads = []
        packages = ManifestController.getPackages(service,
                                                  os.path.basename(manifest))
        # Executing the deactivate in reversed order where the last package is first deactivated.
        if (not activateFlow):
            packages.reverse()

        # make sure there's something to do, otherwise just return here
        if (len(packages) == 0):
            return execThreads

        for package in packages:

            pkgPath = manifestutil.packagePath(service, manifest, package)
            pkgInit = PkgInitConfig(pkgPath)
            pkgConfig = pkgInit.getConfigs()

            # check command type and package startup process
            if (exeName == 'reboot' or exeName == 'restart'):

                # default action for reboot is to startup, noop for restart agent
                action = 'startup' if 'reboot' == exeName else 'noop'

                if exeName == 'reboot' and pkgConfig and pkgConfig.has_key(
                        'lcm_on_system_reboot'):
                    action = pkgConfig['lcm_on_system_reboot']

                if (exeName == 'restart' and pkgConfig
                        and pkgConfig.has_key('lcm_on_agent_restart')):
                    action = pkgConfig['lcm_on_agent_restart']

                if action == 'reset':
                    execThread, dummy = self._getBuiltThread(
                        service, manifest, package, "shutdown")
                    execThreads.append([execThread, dummy])
                    execThread, dummy = self._getBuiltThread(
                        service, manifest, package, "deactivate")
                    execThreads.append([execThread, dummy])
                    execThread, dummy = self._getBuiltThread(
                        service, manifest, package, "activate")
                    execThreads.append([execThread, dummy])

                if (action == 'reset' or action == 'startup'):
                    execThread, dummy = self._getBuiltThread(
                        service, manifest, package, 'startup')
                    execThreads.append([execThread, dummy])

            else:
                execThread, dummy = self._getBuiltThread(
                    service, manifest, package, exeName)
                execThreads.append([execThread, dummy])

        return execThreads
Ejemplo n.º 4
0
    def doAppLogFile(action):
        """ listAppLog """
        service = request.params.get('service', '')
        package = request.params.get('package', '')
        manifest = request.params.get('manifest', 'active')

        if (service == '' or package == ''):
            c.errorMsg = 'missing service or package parameter from request'
            c.errorCode = Errors.LOG_PARAM_REQUIRED
            return render('/derived/error.html')
        packagePathStr = packagePath(service, manifest, package)
        if (not os.path.isdir(packagePathStr)):
            return ModulelogController.listManifests(service)
        LOG.info('In ModuleLogController doAppLogFile ' + packagePathStr)
        pkgInit = PkgInitConfig(service, manifest, package)
        pkgConfig = pkgInit.getConfigs()
        if not pkgConfig:
            c.errorMsg = 'cronus.ini does not exist, view log needs cronus.ini to know log location, please check your cronus package to make sure cronus.ini exist and have property logAppDir'
            c.errorCode = Errors.CRONUS_INI_EMPTY_NOT_FOUND
            return render('/derived/error.html')
        logAppDirList = pkgConfig['logAppDir']

        dirName = request.params.get('dirName', '')
        fileName = request.params.get('fileName', '')

        if (action == 'list'):
            if (fileName != '' and dirName != ''):
                dirName = os.path.join(dirName, fileName)
            if (dirName != ''):
                return ModulelogController.listAppLogDir(
                    service, manifest, package, dirName,
                    os.path.join(packagePathStr, dirName))
            else:
                return ModulelogController.listAllAppLogDir(
                    service, manifest, package, dirName, packagePathStr,
                    logAppDirList)

        if (dirName == '' or fileName == ''):
            c.errorMsg = 'tail/download App log requires dirName & FileName params missing'
            c.errorCode = Errors.NOT_ENOUGH_PARAMS
            return render('/derived/error.html')

        if (action == 'tail'):
            lines = request.params.get('size', '100')
            return tailFile(os.path.join(packagePathStr, dirName, fileName),
                            lines)

        if (action == 'download'):
            return downloadFile(os.path.join(packagePathStr, dirName,
                                             fileName))
Ejemplo n.º 5
0
    def _obtainCmdExecThreads(self, exeName, service, manifest, activateFlow):
        """start the threads to execute cmd in each package in the service/manifest"""

        execThreads = []
        packages = ManifestController.getPackages(service, os.path.basename(manifest))
        # Executing the deactivate in reversed order where the last package is first deactivated.
        if (not activateFlow):
            packages.reverse()

        # make sure there's something to do, otherwise just return here
        if (len(packages) == 0):
            return execThreads
        
        for package in packages:

            pkgPath = manifestutil.packagePath(service, manifest, package)
            pkgInit = PkgInitConfig(pkgPath)
            pkgConfig = pkgInit.getConfigs()
                
                
            # check command type and package startup process
            if (exeName == 'reboot' or exeName == 'restart'):
                
                # default action for reboot is to startup, noop for restart agent
                action = 'startup' if 'reboot' == exeName else 'noop'
                
                if exeName == 'reboot' and pkgConfig and pkgConfig.has_key('lcm_on_system_reboot'):
                    action = pkgConfig['lcm_on_system_reboot']
                            
                if (exeName == 'restart' and pkgConfig and pkgConfig.has_key('lcm_on_agent_restart')):
                    action = pkgConfig['lcm_on_agent_restart']
                        
                if action == 'reset':
                    execThread, dummy = self._getBuiltThread(service, manifest, package, "shutdown")
                    execThreads.append([execThread, dummy])
                    execThread, dummy = self._getBuiltThread(service, manifest, package, "deactivate")
                    execThreads.append([execThread, dummy])
                    execThread, dummy = self._getBuiltThread(service, manifest, package, "activate")
                    execThreads.append([execThread, dummy])
                    
                if (action == 'reset' or action == 'startup'):
                    execThread, dummy = self._getBuiltThread(service, manifest, package, 'startup')
                    execThreads.append([execThread, dummy])
            
            else:
                execThread, dummy = self._getBuiltThread(service, manifest, package, exeName)
                execThreads.append([execThread, dummy])
                
        return execThreads
Ejemplo n.º 6
0
    def doAppLogFile(action):
        """ listAppLog """
        service = request.params.get('service', '')
        package = request.params.get('package', '')
        manifest = request.params.get('manifest', 'active')

        if (service == '' or package == ''):
            c.errorMsg = 'missing service or package parameter from request'
            c.errorCode = Errors.LOG_PARAM_REQUIRED
            return render('/derived/error.html')
        packagePathStr = packagePath(service, manifest, package)
        if (not os.path.isdir(packagePathStr)):
            return ModulelogController.listManifests(service)
        LOG.info('In ModuleLogController doAppLogFile ' + packagePathStr)
        pkgInit = PkgInitConfig(service, manifest, package)
        pkgConfig = pkgInit.getConfigs()
        if not pkgConfig:
            c.errorMsg = 'cronus.ini does not exist, view log needs cronus.ini to know log location, please check your cronus package to make sure cronus.ini exist and have property logAppDir'
            c.errorCode = Errors.CRONUS_INI_EMPTY_NOT_FOUND
            return render('/derived/error.html')
        logAppDirList = pkgConfig['logAppDir']

        dirName = request.params.get('dirName', '')
        fileName = request.params.get('fileName', '')

        if (action == 'list'):
            if (fileName != '' and dirName != ''):
                dirName = os.path.join(dirName, fileName)
            if (dirName != ''):
                return ModulelogController.listAppLogDir(service, manifest, package, dirName, os.path.join(packagePathStr, dirName))
            else:
                return ModulelogController.listAllAppLogDir(service, manifest, package, dirName, packagePathStr, logAppDirList)

        if (dirName == '' or fileName == ''):
            c.errorMsg = 'tail/download App log requires dirName & FileName params missing'
            c.errorCode = Errors.NOT_ENOUGH_PARAMS
            return render('/derived/error.html')

        if (action == 'tail'):
            lines = request.params.get('size', '100')
            return tailFile(os.path.join(packagePathStr, dirName, fileName), lines)
            
        if (action == 'download'):
            return downloadFile(os.path.join(packagePathStr, dirName, fileName))