Exemplo n.º 1
0
    def delete(self, module):
        """ Delete a new service object """
        try:
            LOG.info('Got a delete request for module ' + module)

            path = manifestutil.modulePath('agent', module)

            if (not os.path.exists(path) and not os.path.isdir(path)):
                return doneResult(request, response, controller=self)

            # start the delete thread
            appGlobal = config['pylons.app_globals']
            deleteThread = ModuleDelete(appGlobal.threadMgr, module)
            self.injectJobCtx(deleteThread)
            deleteThread.start()
            deleteThread.threadMgrEvent.wait()

            return statusResult(request,
                                response,
                                deleteThread,
                                controller=self)

        except Exception as excep:
            return errorResult(
                request,
                response,
                error=Errors.UNKNOWN_ERROR,
                errorMsg='Unknown error when deleting module(%s) %s - %s' %
                (module, str(excep), traceback.format_exc(2)),
                controller=self)
Exemplo n.º 2
0
    def get(self, module):
        """ Get a new service object """
        try:
            # make sure the service path exists
            path = manifestutil.modulePath('agent', module)
            if (not os.path.exists(path)):
                return errorResult(request,
                                   response,
                                   error=Errors.SERVICE_NOT_FOUND,
                                   errorMsg='Unable to find module (%s)' %
                                   module,
                                   controller=self)

            result = {}
            modulePackage = readlink(path)
            result['package'] = modulePackage

            return doneResult(request,
                              response,
                              result=result,
                              controller=self)

        except Exception as excep:
            return errorResult(
                request,
                response,
                error=Errors.UNKNOWN_ERROR,
                errorMsg='Unknown error when getting module (%s) %s - %s' %
                (module, str(excep), traceback.format_exc(2)),
                controller=self)
Exemplo n.º 3
0
    def get(self, module):
        """ Get a new service object """
        try:
            # make sure the service path exists
            path = manifestutil.modulePath("agent", module)
            if not os.path.exists(path):
                return errorResult(
                    request,
                    response,
                    error=Errors.SERVICE_NOT_FOUND,
                    errorMsg="Unable to find module (%s)" % module,
                    controller=self,
                )

            result = {}
            modulePackage = readlink(path)
            result["package"] = modulePackage

            return doneResult(request, response, result=result, controller=self)

        except Exception as excep:
            return errorResult(
                request,
                response,
                error=Errors.UNKNOWN_ERROR,
                errorMsg="Unknown error when getting module (%s) %s - %s"
                % (module, str(excep), traceback.format_exc(2)),
                controller=self,
            )
Exemplo n.º 4
0
    def delete(self, module):
        """ Delete a new service object """
        try:
            LOG.info("Got a delete request for module " + module)

            path = manifestutil.modulePath("agent", module)

            if not os.path.exists(path) and not os.path.isdir(path):
                return doneResult(request, response, controller=self)

            # start the delete thread
            appGlobal = config["pylons.app_globals"]
            deleteThread = ModuleDelete(appGlobal.threadMgr, module)
            self.injectJobCtx(deleteThread)
            deleteThread.start()
            deleteThread.threadMgrEvent.wait()

            return statusResult(request, response, deleteThread, controller=self)

        except Exception as excep:
            return errorResult(
                request,
                response,
                error=Errors.UNKNOWN_ERROR,
                errorMsg="Unknown error when deleting module(%s) %s - %s"
                % (module, str(excep), traceback.format_exc(2)),
                controller=self,
            )
Exemplo n.º 5
0
    def doRun(self):
        """ Main body of the thread """
        try:
            deleted = True
            path = manifestutil.modulePath(self.__service, self.__module)

            try:
                manifestutil.processModule(self.__service, self.__module, False)
                utils.rmlink(path)

            except AgentException as excep:
                LOG.warning('Delete Module Exception - %s', excep.getMsg())
                self._updateStatus(httpStatus = 500, error = excep.getCode(),
                                   errorMsg = excep.getMsg())
            except OSError as excep:
                LOG.warning('Delete Module Exception - %s', excep.getMsg())
                self._updateStatus(httpStatus = 500, error = Errors.SERVICE_DELETE_FAILED,
                                   errorMsg = 'Path (%s) failed to be deleted' % path)
                deleted = False

            # verify that the path does not exist
            if (os.path.exists(path) and deleted):
                self._updateStatus(httpStatus = 500, error = 1,
                                    errorMsg = 'Path (%s) still exists even after delete attempt' % path)

            self._updateStatus(progress = 100)
            
        except Exception as exc:
            msg = 'Unknown error when deleting module %s - %s' % (self.__service, str(exc))
            errCode = Errors.UNKNOWN_ERROR
            self._updateStatus(httpStatus = 500, error = errCode, errorMsg = msg)
Exemplo n.º 6
0
    def _getBuiltThread(self, scriptName):
        """ build lcm script exec thread """
        # figure out the path to the cronus scripts
        uname = pylons.config['app_user_account']
        execPath = os.path.join(manifestutil.modulePath(self.__service, self.__module), self.__package, 'cronus', 'scripts', scriptName)
        if (isHigherPrivilegeService(self.__service)):
            cmd = execPath
        else:
            cmd = utils.sudoCmd([execPath], uname)

        dummy = not os.path.exists(execPath)
        execThread = ExecThread(self._threadMgr, cmd)
        copycontexts(self, execThread, ['service', 'guid'])
        return execThread, dummy
Exemplo n.º 7
0
    def _getBuiltThread(self, scriptName):
        """ build lcm script exec thread """
        # figure out the path to the cronus scripts
        uname = pylons.config['app_user_account']
        execPath = os.path.join(
            manifestutil.modulePath(self.__service, self.__module),
            self.__package, 'cronus', 'scripts', scriptName)
        if (isHigherPrivilegeService(self.__service)):
            cmd = execPath
        else:
            cmd = utils.sudoCmd([execPath], uname)

        dummy = not os.path.exists(execPath)
        execThread = ExecThread(self._threadMgr, cmd)
        copycontexts(self, execThread, ['service', 'guid'])
        return execThread, dummy
Exemplo n.º 8
0
    def doRun(self):
        """ Main body of the thread """
        try:
            deleted = True
            path = manifestutil.modulePath(self.__service, self.__module)

            try:
                manifestutil.processModule(self.__service, self.__module,
                                           False)
                utils.rmlink(path)

            except AgentException as excep:
                LOG.warning('Delete Module Exception - %s', excep.getMsg())
                self._updateStatus(httpStatus=500,
                                   error=excep.getCode(),
                                   errorMsg=excep.getMsg())
            except OSError as excep:
                LOG.warning('Delete Module Exception - %s', excep.getMsg())
                self._updateStatus(httpStatus=500,
                                   error=Errors.SERVICE_DELETE_FAILED,
                                   errorMsg='Path (%s) failed to be deleted' %
                                   path)
                deleted = False

            # verify that the path does not exist
            if (os.path.exists(path) and deleted):
                self._updateStatus(
                    httpStatus=500,
                    error=1,
                    errorMsg='Path (%s) still exists even after delete attempt'
                    % path)

            self._updateStatus(progress=100)

        except Exception as exc:
            msg = 'Unknown error when deleting module %s - %s' % (
                self.__service, str(exc))
            errCode = Errors.UNKNOWN_ERROR
            self._updateStatus(httpStatus=500, error=errCode, errorMsg=msg)