Beispiel #1
0
    def get(self, service):
        """ Get a new service object """
        try:
            from agent.lib.agent_thread.manifest_create import ManifestCreate

            # make sure the service path exists
            path = ServiceController.servicePath(service)
            if (not os.path.exists(path)):
                return errorResult(request,
                                   response,
                                   error=Errors.SERVICE_NOT_FOUND,
                                   errorMsg='Unable to find service (%s)' %
                                   service,
                                   controller=self)

            path = ServiceController.manifestPath(service)

            activeManifest = None
            manifestList = []
            for manifest in os.listdir(path):
                if (ManifestCreate.isInProgress(manifest)):
                    continue

                manifestPath = os.path.join(path, manifest)
                if (manifest == 'active'):
                    activeLink = readlink(manifestPath)

                    if (activeLink == None):
                        manifestList.append(manifest)
                    else:
                        activeManifest = os.path.basename(activeLink)
                else:
                    manifestList.append(manifest)

            result = {}
            manifestList.sort()
            result['manifest'] = manifestList
            result['activemanifest'] = activeManifest

            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 service (%s) %s - %s' %
                (service, str(excep), traceback.format_exc(2)),
                controller=self)
Beispiel #2
0
    def get(self, service):
        """ Get a new service object """
        try:
            from agent.lib.agent_thread.manifest_create import ManifestCreate

            # make sure the service path exists
            path = ServiceController.servicePath(service)
            if not os.path.exists(path):
                return errorResult(
                    request,
                    response,
                    error=Errors.SERVICE_NOT_FOUND,
                    errorMsg="Unable to find service (%s)" % service,
                    controller=self,
                )

            path = ServiceController.manifestPath(service)

            activeManifest = None
            manifestList = []
            for manifest in os.listdir(path):
                if ManifestCreate.isInProgress(manifest):
                    continue

                manifestPath = os.path.join(path, manifest)
                if manifest == "active":
                    activeLink = readlink(manifestPath)

                    if activeLink == None:
                        manifestList.append(manifest)
                    else:
                        activeManifest = os.path.basename(activeLink)
                else:
                    manifestList.append(manifest)

            result = {}
            manifestList.sort()
            result["manifest"] = manifestList
            result["activemanifest"] = activeManifest

            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 service (%s) %s - %s"
                % (service, str(excep), traceback.format_exc(2)),
                controller=self,
            )
Beispiel #3
0
    def getManifests(service):
        """ return the list of manifests under a specific service """
        from agent.lib.agent_thread.manifest_create import ManifestCreate

        manifests = []

        dirContent = os.listdir(ServiceController.manifestPath(service))

        for item in dirContent:
            path = os.path.join(ServiceController.manifestPath(service), item)
            if (os.path.isdir(path) and not ManifestCreate.isInProgress(path)):
                if (not islink(path)):
                    manifests.append(item)

        return sorted(manifests)
Beispiel #4
0
    def getManifests(service):
        """ return the list of manifests under a specific service """
        from agent.lib.agent_thread.manifest_create import ManifestCreate

        manifests = []

        dirContent = os.listdir(ServiceController.manifestPath(service))

        for item in dirContent:
            path = os.path.join(ServiceController.manifestPath(service), item)
            if (os.path.isdir(path) and not ManifestCreate.isInProgress(path)):
                if (not islink(path)):
                    manifests.append(item)

        return sorted(manifests)
Beispiel #5
0
    def cleanupServices():
        """
        for all services clean up partially completed manifests
        This should only be called during startup.
        """
        from agent.lib.agent_thread.manifest_create import ManifestCreate

        try:
            services = ServiceController.getServices()
            for service in services:
                manPath = ServiceController.manifestPath(service)
                manifestPaths = [os.path.join(manPath, path) for path in os.listdir(manPath)]

                [shutil.rmtree(manifestPath) for manifestPath in manifestPaths
                 if ManifestCreate.isInProgress(os.path.basename(manifestPath))]

        except OSError:
            pass
Beispiel #6
0
    def cleanupServices():
        """
        for all services clean up partially completed manifests
        This should only be called during startup.
        """
        from agent.lib.agent_thread.manifest_create import ManifestCreate

        try:
            services = ServiceController.getServices()
            for service in services:
                manPath = ServiceController.manifestPath(service)
                manifestPaths = [
                    os.path.join(manPath, path) for path in os.listdir(manPath)
                ]

                [
                    shutil.rmtree(manifestPath)
                    for manifestPath in manifestPaths
                    if ManifestCreate.isInProgress(
                        os.path.basename(manifestPath))
                ]

        except OSError:
            pass