Esempio n. 1
0
 def __init__(self):
     super().__init__()
     
     self._kit_manager = KitManager(
         eula_validator=CommandLineEulaValidator()
     )
     self._logger = logging.getLogger(KIT_NAMESPACE)
Esempio n. 2
0
    def action_post_install(self, *args, **kwargs):
        super().action_post_install(*args, **kwargs)

        #
        # Cache Munin packages and dependencies from EPEL
        #
        os.system(os.path.join(self.install_path, 'bin', "dl.sh"))

        k = KitManager().getKit('munin')

        kit_repo_dir = os.path.join(
            self.config_manager.getReposDir(),
            k.getKitRepoDir()
        )

        #
        # If cache directory exists, copy to 'kitRepoDir' (the default
        # location for kit packages)
        #
        if os.path.isdir('/var/cache/tortuga/pkgs/munin'):
            tortugaSubprocess.executeCommandAndIgnoreFailure(
                'rsync -a {}/ {}'.format(
                    '/var/cache/tortuga/pkgs/munin', kit_repo_dir)
            )
            tortugaSubprocess.executeCommandAndIgnoreFailure(
                'createrepo {}'.format(kit_repo_dir))
Esempio n. 3
0
    def action_post_install(self, *args, **kwargs):
        super().action_post_install(*args, **kwargs)
        #
        # Cache Ganglia packages from EPEL
        #
        os.system(os.path.join(self.install_path, 'bin', "dl.sh"))

        kit = KitManager().getKit('ganglia')
        kit_repo_dir = os.path.join(
            self.config_manager.getReposDir(),
            kit.getKitRepoDir()
        )

        cmd = 'rsync -a {}/ {}'.format('/var/cache/tortuga/pkgs/ganglia',
                                       kit_repo_dir)
        tortugaSubprocess.executeCommandAndIgnoreFailure(cmd)

        cmd = 'cd %s; createrepo .'.format(kit_repo_dir)
        tortugaSubprocess.executeCommandAndIgnoreFailure(cmd)

        #
        # Copy default configuration file into place
        #
        dst_path = os.path.join(self.config_manager.getKitConfigBase(),
                                'ganglia')
        if not os.path.exists(dst_path):
            os.makedirs(dst_path)
        shutil.copyfile(
            os.path.join(self.files_path, 'gmond-component.conf'),
            os.path.join(dst_path, 'gmond-component.conf')
        )
Esempio n. 4
0
    def getKitEula(self, name, version, iteration=None):
        """ Get kit Eula. """

        try:
            eula = KitManager().get_kit_eula(name, version, iteration)

            response = eula.getCleanDict()
        except Exception as ex:
            self.getLogger().error('%s' % ex)
            self.handleException(ex)
            response = self.errorResponse(str(ex))

        return self.formatResponse(response)
Esempio n. 5
0
    def getKitList(self):
        """ Return list of all available kits. """

        try:
            kitList = KitManager().getKitList()

            response = {'kits': kitList.getCleanDict()}
        except Exception as ex:
            self.getLogger().error('%s' % ex)
            self.handleException(ex)
            response = self.errorResponse(str(ex))

        return self.formatResponse(response)
Esempio n. 6
0
    def getKitById(self, kit_id):
        """ Return info for the specified kit by id. """

        try:
            kit = KitManager().getKitById(cherrypy.request.db, kit_id)

            response = {
                'kit': kit.getCleanDict(),
            }
        except Exception as ex:
            self._logger.error(str(ex))
            self.handleException(ex)
            response = self.errorResponse(str(ex))

        return self.formatResponse(response)
Esempio n. 7
0
    def getKit(self, name, version, iteration=None):
        """ Return info for the specified kit. """

        self.getLogger().debug(
            '[%s] getKit(): name=[%s], version=[%s], iteration=[%s]' %
            (self.__module__, name, version, iteration))

        try:
            kit = KitManager().getKit(name, version, iteration)

            response = {'kit': kit.getCleanDict()}
        except Exception as ex:
            self.getLogger().error('%s' % ex)
            self.handleException(ex)
            response = self.errorResponse(str(ex))

        return self.formatResponse(response)
Esempio n. 8
0
    def kitsAction(self, **kwargs):
        """
        Return list of all available kits.
        """

        response = None

        try:
            name = kwargs.get('name')
            version = kwargs.get('version')
            iteration = kwargs.get('iteration')

            if cherrypy.request.method == 'DELETE':
                KitManager().deleteKit(
                    cherrypy.request.db, name, version, iteration)
            else:
                # GET method
                if name:
                    # get kit by name
                    kitList = TortugaObjectList(
                        [self.getKit(name,
                                     version=version,
                                     iteration=iteration)]
                    )
                else:
                    # get all kits
                    kitList = KitManager().getKitList(cherrypy.request.db)

                response = {'kits': kitList.getCleanDict()}
        except KitNotFound as ex:
            self.handleException(ex)
            code = self.getTortugaStatusCode(ex)
            response = self.notFoundErrorResponse(str(ex), code)
        except Exception as ex:
            self.getLogger().error('%s' % ex)
            self.handleException(ex)
            response = self.errorResponse(str(ex))

        return self.formatResponse(response)
Esempio n. 9
0
    def deleteKit(self, name, version, iteration=None):
        """ Remove kit by name, version and iteration. """

        response = None

        try:
            KitManager().deleteKit(name, version, iteration)
        except Exception as ex:
            self.getLogger().error('%s' % ex)
            self.handleException(ex)
            response = self.errorResponse(str(ex))

        return self.formatResponse(response)
Esempio n. 10
0
    def installKit(self, name, version, iteration=None, key=None):
        """ Install kit by name, version and iteration. """

        response = None

        try:
            KitManager().installKit(name, version, iteration, key)
        except Exception as ex:
            self.getLogger().error('%s' % ex)
            self.handleException(ex)
            response = self.errorResponse(str(ex))

        return self.formatResponse(response)
Esempio n. 11
0
    def installKit(self, name, version, iteration=None):
        """ Install kit by name, version and iteration. """

        response = None

        try:
            KitManager().installKit(cherrypy.request.db, name, version,
                                    iteration, key)
        except Exception as ex:
            self._logger.error(str(ex))
            self.handleException(ex)
            response = self.errorResponse(str(ex))

        return self.formatResponse(response)
Esempio n. 12
0
    def getKit(self, name: str, version: Optional[str], iteration: Optional[str]):
        """
        Return info for the specified kit.

        Raises:
            KitNotFound
        """

        self.getLogger().debug(
            'getKit(): name=[%s], version=[%s], iteration=[%s]' % (
                name, version, iteration))

        return KitManager().getKit(
            cherrypy.request.db, name, version=version, iteration=iteration)
Esempio n. 13
0
    def addProxy(self, url):
        self._logger.info('Proxy OS kit detected, no RPMs will be copied')

        # Determine the "real" repo dir and the directory as apache
        # sees it

        realRepoDir = self._getRepoDir()

        repoDir = realRepoDir[realRepoDir.index('/repos'):]

        # Set proxy information in the apache component configuration file
        self._logger.info(
            'Enabling proxy for OS kit in web server configuration file')

        # Configure proxy
        KitManager().configureProxy(url, repoDir)
Esempio n. 14
0
 def __init__(self):
     super().__init__()
     self._kit_manager = KitManager(
         eula_validator=CommandLineEulaValidator()
     )
Esempio n. 15
0
class KitApi(TortugaApi):
    """
    Kit API class.
    """
    def __init__(self):
        super().__init__()
        self._kit_manager = KitManager(
            eula_validator=CommandLineEulaValidator()
        )

    def getKit(self, name, version, iteration=None):
        """
        Get kit info.

            Returns:
                kit
            Throws:
                KitNotFound
                TortugaException
        """
        try:
            kit = self._kit_manager.getKit(name, version, iteration)
            return kit
        except TortugaException as ex:
            raise
        except Exception as ex:
            self.getLogger().exception('%s' % ex)
            raise TortugaException(exception=ex)

    def getKitById(self, id_):
        """
        Get kit info by kitId.

            Returns:
                kit
            Throws:
                KitNotFound
                TortugaException
        """
        try:
            return self._kit_manager.getKitById(id_)
        except TortugaException as ex:
            raise
        except Exception as ex:
            self.getLogger().exception('%s' % ex)

    def getKitList(self):
        """
        Get kit list.

            Returns:
                [kits]
            Throws:
                TortugaException
        """
        try:
            kitList = self._kit_manager.getKitList()
            return kitList
        except TortugaException as ex:
            raise
        except Exception as ex:
            self.getLogger().exception('%s' % ex)
            raise TortugaException(exception=ex)

    def installKit(self, name, version, iteration=None, key=None):
        """
        Install kit using kit name/version/iteration.

            Returns:
                kitId
            Throws:
                UserNotAuthorized
                FileNotFound
                KitAlreadyExists
                TortugaException
        """
        try:
            kit = self._kit_manager.installKit(
                name, version, iteration, key)

            return kit
        except TortugaException as ex:
            raise
        except Exception as ex:
            self.getLogger().exception('%s' % ex)
            raise TortugaException(exception=ex)

    def installKitPackage(self, packageUrl, key=None):
        """
            Install kit package.

            Returns:
                kitId
            Throws:
                UserNotAuthorized
                FileNotFound
                KitAlreadyExists
                TortugaException
        """
        try:
            kit = self._kit_manager.installKitPackage(
                packageUrl, key)

            return kit
        except TortugaException as ex:
            raise
        except Exception as ex:
            self.getLogger().exception('%s' % ex)
            raise TortugaException(exception=ex)

    def getKitEula(self, name, version, iteration=None):
        """
            Fetch eula information for kit.

            Returns:
                eula tortuga object
            Throws:
                UserNotAuthorized
                FileNotFound
                NoKitEula
                TortugaException
        """
        try:
            return self._kit_manager.get_kit_eula(
                name, version, iteration)
        except TortugaException as ex:
            raise
        except Exception as ex:
            self.getLogger().exception('%s' % ex)
            raise TortugaException(exception=ex)

    def getKitPackageEula(self, packageUrl):
        """
            Fetch eula information for kit package.

            Returns:
                eula tortuga object
            Throws:
                UserNotAuthorized
                FileNotFound
                NoKitEula
                TortugaException
        """
        try:
            eula = self._kit_manager.get_kit_package_eula(packageUrl)
            return eula
        except TortugaException as ex:
            raise
        except Exception as ex:
            self.getLogger().exception('%s' % ex)
            raise TortugaException(exception=ex)

    def installOsKit(self, os_media_urls: List[str], **kwargs) -> None:
        """
            Install OS kit

            Returns:
                kitId
            Throws:
                UserNotAuthorized
                FileNotFound
                KitAlreadyExists
                TortugaException
        """
        try:
            return self._kit_manager.installOsKit(os_media_urls, **kwargs)
        except TortugaException:
            raise
        except Exception as ex:
            self.getLogger().exception(ex)
            raise TortugaException(exception=ex)

    def deleteKit(self, name, version=None, iteration=None, force=False) -> None:
        """
        Delete kit.

            Returns:
                None
            Throws:
                UserNotAuthorized
                KitNotFound
                KitInUse
                TortugaException
        """
        try:
            self._kit_manager.deleteKit(
                name, version, iteration, force=force)
        except TortugaException:
            raise
        except Exception as ex:
            self.getLogger().exception('%s' % ex)
            raise TortugaException(exception=ex)