示例#1
0
    def addRepo(self, params):
        """
        Add a given repository to YumBase
        """
        # At least one base url, or one mirror, must be given.
        baseurl = params.get('baseurl', '')

        config = params.get('config', {})
        mirrorlist = config.get('mirrorlist', '')
        metalink = config.get('metalink', '')
        if not baseurl and not mirrorlist and not metalink:
            raise MissingParameter("KCHREPOS0013E")

        if baseurl:
            validate_repo_url(get_expanded_url(baseurl))

        if mirrorlist:
            validate_repo_url(get_expanded_url(mirrorlist))

        if metalink:
            validate_repo_url(get_expanded_url(metalink))

        if mirrorlist and metalink:
            raise InvalidOperation('KCHREPOS0030E')

        repo_id = params.get('repo_id', None)
        if repo_id is None:
            repo_id = "kimchi_repo_%s" % str(int(time.time() * 1000))

        repos = self._get_repos('KCHREPOS0026E')
        if repo_id in repos.keys():
            raise InvalidOperation("KCHREPOS0022E", {'repo_id': repo_id})

        repo_name = config.get('repo_name', repo_id)
        repo = {
            'baseurl': baseurl,
            'mirrorlist': mirrorlist,
            'name': repo_name,
            'gpgcheck': 1,
            'gpgkey': [],
            'enabled': 1,
            'metalink': metalink
        }

        # write a repo file in the system with repo{} information.
        parser = ConfigParser()
        parser.add_section(repo_id)

        for key, value in repo.iteritems():
            if value:
                parser.set(repo_id, key, value)

        repofile = os.path.join(self._confdir, repo_id + '.repo')
        try:
            with open(repofile, 'w') as fd:
                parser.write(fd)
        except:
            raise OperationFailed("KCHREPOS0018E", {'repo_file': repofile})

        return repo_id
示例#2
0
    def addRepo(self, params):
        """
        Add a given repository to YumBase
        """
        # At least one base url, or one mirror, must be given.
        baseurl = params.get('baseurl', '')

        config = params.get('config', {})
        mirrorlist = config.get('mirrorlist', '')
        metalink = config.get('metalink', '')
        if not baseurl and not mirrorlist and not metalink:
            raise MissingParameter("KCHREPOS0013E")

        if baseurl:
            validate_repo_url(get_expanded_url(baseurl))

        if mirrorlist:
            validate_repo_url(get_expanded_url(mirrorlist))

        if metalink:
            validate_repo_url(get_expanded_url(metalink))

        if mirrorlist and metalink:
            raise InvalidOperation('KCHREPOS0030E')

        repo_id = params.get('repo_id', None)
        if repo_id is None:
            repo_id = "kimchi_repo_%s" % str(int(time.time() * 1000))

        repos = self._get_repos('KCHREPOS0026E')
        if repo_id in repos.keys():
            raise InvalidOperation("KCHREPOS0022E", {'repo_id': repo_id})

        repo_name = config.get('repo_name', repo_id)
        repo = {'baseurl': baseurl, 'mirrorlist': mirrorlist,
                'name': repo_name, 'gpgcheck': 1,
                'gpgkey': [], 'enabled': 1, 'metalink': metalink}

        # write a repo file in the system with repo{} information.
        parser = ConfigParser()
        parser.add_section(repo_id)

        for key, value in repo.iteritems():
            if value:
                parser.set(repo_id, key, value)

        repofile = os.path.join(self._confdir, repo_id + '.repo')
        try:
            with open(repofile, 'w') as fd:
                parser.write(fd)
        except:
            raise OperationFailed("KCHREPOS0018E",
                                  {'repo_file': repofile})

        return repo_id
示例#3
0
    def updateRepo(self, repo_id, params):
        """
        Update a given repository in repositories.Repositories() format
        """
        repos = self._get_repos('KCHREPOS0011E')
        if repo_id not in repos.keys():
            raise NotFoundError("KCHREPOS0012E", {'repo_id': repo_id})

        entry = repos.get(repo_id)

        baseurl = params.get('baseurl', None)
        config = params.get('config', {})
        mirrorlist = config.get('mirrorlist', None)
        metalink = config.get('metalink', None)

        if baseurl is not None and len(baseurl.strip()) == 0:
            baseurl = None

        if mirrorlist is not None and len(mirrorlist.strip()) == 0:
            mirrorlist = None

        if metalink is not None and len(metalink.strip()) == 0:
            metalink = None

        if baseurl is None and mirrorlist is None and metalink is None:
            raise MissingParameter("KCHREPOS0013E")

        if baseurl is not None:
            validate_repo_url(get_expanded_url(baseurl))
            entry.baseurl = baseurl

        if mirrorlist is not None:
            validate_repo_url(get_expanded_url(mirrorlist))
            entry.mirrorlist = mirrorlist

        if metalink is not None:
            validate_repo_url(get_expanded_url(metalink))
            entry.metalink = metalink

        if mirrorlist and metalink:
            raise InvalidOperation('KCHREPOS0030E')

        entry.id = params.get('repo_id', repo_id)
        entry.name = config.get('repo_name', entry.name)
        entry.gpgcheck = config.get('gpgcheck', entry.gpgcheck)
        entry.gpgkey = config.get('gpgkey', entry.gpgkey)
        kimchiLock.acquire()
        write_repo_to_file(entry)
        kimchiLock.release()
        return repo_id
示例#4
0
    def updateRepo(self, repo_id, params):
        """
        Update a given repository in repositories.Repositories() format
        """
        repos = self._get_repos('KCHREPOS0011E')
        if repo_id not in repos.keys():
            raise NotFoundError("KCHREPOS0012E", {'repo_id': repo_id})

        entry = repos.get(repo_id)

        baseurl = params.get('baseurl', None)
        config = params.get('config', {})
        mirrorlist = config.get('mirrorlist', None)
        metalink = config.get('metalink', None)

        if baseurl is not None and len(baseurl.strip()) == 0:
            baseurl = None

        if mirrorlist is not None and len(mirrorlist.strip()) == 0:
            mirrorlist = None

        if metalink is not None and len(metalink.strip()) == 0:
            metalink = None

        if baseurl is None and mirrorlist is None and metalink is None:
            raise MissingParameter("KCHREPOS0013E")

        if baseurl is not None:
            validate_repo_url(get_expanded_url(baseurl))
            entry.baseurl = baseurl

        if mirrorlist is not None:
            validate_repo_url(get_expanded_url(mirrorlist))
            entry.mirrorlist = mirrorlist

        if metalink is not None:
            validate_repo_url(get_expanded_url(metalink))
            entry.metalink = metalink

        if mirrorlist and metalink:
            raise InvalidOperation('KCHREPOS0030E')

        entry.id = params.get('repo_id', repo_id)
        entry.name = config.get('repo_name', entry.name)
        entry.gpgcheck = config.get('gpgcheck', entry.gpgcheck)
        entry.gpgkey = config.get('gpgkey', entry.gpgkey)
        kimchiLock.acquire()
        write_repo_to_file(entry)
        kimchiLock.release()
        return repo_id
示例#5
0
    def addRepo(self, params):
        """
        Add a new APT repository based on <params>
        """
        # To create a APT repository the dist is a required parameter
        # (in addition to baseurl, verified on controller through API.json)
        config = params.get('config', None)
        if config is None:
            raise MissingParameter("KCHREPOS0019E")

        if 'dist' not in config.keys():
            raise MissingParameter("KCHREPOS0019E")

        uri = params['baseurl']
        dist = config['dist']
        comps = config.get('comps', [])

        validate_repo_url(get_expanded_url(uri))

        kimchiLock.acquire()
        try:
            repos = self._get_repos()
            source_entry = repos.add('deb', uri, dist, comps,
                                     file=self.filename)
            with self.pkg_lock():
                repos.save()
        except Exception as e:
            kimchiLock.release()
            raise OperationFailed("KCHREPOS0026E", {'err': e.message})
        kimchiLock.release()
        return self._get_repo_id(source_entry)
示例#6
0
    def addRepo(self, params):
        """
        Add a new APT repository based on <params>
        """
        # To create a APT repository the dist is a required parameter
        # (in addition to baseurl, verified on controller through API.json)
        config = params.get('config', None)
        if config is None:
            raise MissingParameter("KCHREPOS0019E")

        if 'dist' not in config.keys():
            raise MissingParameter("KCHREPOS0019E")

        uri = params['baseurl']
        dist = config['dist']
        comps = config.get('comps', [])

        validate_repo_url(get_expanded_url(uri))

        kimchiLock.acquire()
        try:
            repos = self._get_repos()
            source_entry = repos.add('deb',
                                     uri,
                                     dist,
                                     comps,
                                     file=self.filename)
            with self.pkg_lock():
                repos.save()
        except Exception as e:
            kimchiLock.release()
            raise OperationFailed("KCHREPOS0026E", {'err': e.message})
        kimchiLock.release()
        return self._get_repo_id(source_entry)