Beispiel #1
0
 def _get_repos(self, errcode):
     try:
         kimchiLock.acquire()
         repos = get_yum_repositories()
     except Exception, e:
         kimchiLock.release()
         raise OperationFailed(errcode, {'err': str(e)})
Beispiel #2
0
    def toggleRepo(self, repo_id, enable):
        repos = self._get_repos('KCHREPOS0011E')
        if repo_id not in repos.keys():
            raise NotFoundError("KCHREPOS0012E", {'repo_id': repo_id})

        entry = repos.get(repo_id)
        if enable and entry.enabled:
            raise InvalidOperation("KCHREPOS0015E", {'repo_id': repo_id})

        if not enable and not entry.enabled:
            raise InvalidOperation("KCHREPOS0016E", {'repo_id': repo_id})

        kimchiLock.acquire()
        try:
            if enable:
                entry.enable()
            else:
                entry.disable()

            write_repo_to_file(entry)
        except:
            if enable:
                raise OperationFailed("KCHREPOS0020E", {'repo_id': repo_id})

            raise OperationFailed("KCHREPOS0021E", {'repo_id': repo_id})
        finally:
            kimchiLock.release()

        return repo_id
Beispiel #3
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)
Beispiel #4
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)
Beispiel #5
0
    def toggleRepo(self, repo_id, enable):
        repos = self._get_repos('KCHREPOS0011E')
        if repo_id not in repos.keys():
            raise NotFoundError("KCHREPOS0012E", {'repo_id': repo_id})

        entry = repos.get(repo_id)
        if enable and entry.enabled:
            raise InvalidOperation("KCHREPOS0015E", {'repo_id': repo_id})

        if not enable and not entry.enabled:
            raise InvalidOperation("KCHREPOS0016E", {'repo_id': repo_id})

        kimchiLock.acquire()
        try:
            if enable:
                entry.enable()
            else:
                entry.disable()

            write_repo_to_file(entry)
        except:
            if enable:
                raise OperationFailed("KCHREPOS0020E", {'repo_id': repo_id})

            raise OperationFailed("KCHREPOS0021E", {'repo_id': repo_id})
        finally:
            kimchiLock.release()

        return repo_id
Beispiel #6
0
 def _get_repos(self, errcode):
     try:
         kimchiLock.acquire()
         repos = get_yum_repositories()
     except Exception, e:
         kimchiLock.release()
         raise OperationFailed(errcode, {'err': str(e)})
Beispiel #7
0
 def _get_repos(self):
     try:
         with self.pkg_lock():
             repos = self._sourceslist()
             repos.refresh()
     except Exception, e:
         kimchiLock.release()
         raise OperationFailed('KCHREPOS0025E', {'err': e.message})
Beispiel #8
0
 def _get_repos(self):
     try:
         with self.pkg_lock():
             repos = self._sourceslist()
             repos.refresh()
     except Exception, e:
         kimchiLock.release()
         raise OperationFailed('KCHREPOS0025E', {'err': e.message})
Beispiel #9
0
 def _refreshUpdateList(self):
     """
     Update the list of packages to be updated in the system.
     """
     apt_cache = getattr(__import__('apt'), 'Cache')()
     try:
         with self.pkg_lock():
             apt_cache.update()
             apt_cache.upgrade()
             self._pkgs = apt_cache.get_changes()
     except Exception, e:
         kimchiLock.release()
         raise OperationFailed('KCHPKGUPD0003E', {'err': e.message})
Beispiel #10
0
 def _refreshUpdateList(self):
     """
     Update the list of packages to be updated in the system.
     """
     apt_cache = getattr(__import__('apt'), 'Cache')()
     try:
         with self.pkg_lock():
             apt_cache.update()
             apt_cache.upgrade()
             self._pkgs = apt_cache.get_changes()
     except Exception, e:
         kimchiLock.release()
         raise OperationFailed('KCHPKGUPD0003E', {'err': e.message})
Beispiel #11
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
Beispiel #12
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
Beispiel #13
0
    def getPackagesList(self):
        """
        Return a list of package's dictionaries. Each dictionary contains the
        information about a package, in the format
        package = {'package_name': <string>, 'version': <string>,
                   'arch': <string>, 'repository': <string>}
        """
        if self.isRunning():
            raise OperationFailed('KCHPKGUPD0005E')

        kimchiLock.acquire()
        self._refreshUpdateList()
        kimchiLock.release()
        return self._pkgs
Beispiel #14
0
    def getPackagesList(self):
        """
        Return a list of package's dictionaries. Each dictionary contains the
        information about a package, in the format
        package = {'package_name': <string>, 'version': <string>,
                   'arch': <string>, 'repository': <string>}
        """
        if self.isRunning():
            raise OperationFailed('KCHPKGUPD0005E')

        kimchiLock.acquire()
        self._refreshUpdateList()
        kimchiLock.release()
        return self._pkgs
Beispiel #15
0
    def _get_source_entry(self, repo_id):
        kimchiLock.acquire()
        repos = self._get_repos()
        kimchiLock.release()

        for r in repos:
            # Ignore deb-src repositories
            if r.type != 'deb':
                continue

            if self._get_repo_id(r) != repo_id:
                continue

            return r

        return None
Beispiel #16
0
    def _get_source_entry(self, repo_id):
        kimchiLock.acquire()
        repos = self._get_repos()
        kimchiLock.release()

        for r in repos:
            # Ignore deb-src repositories
            if r.type != 'deb':
                continue

            if self._get_repo_id(r) != repo_id:
                continue

            return r

        return None
Beispiel #17
0
    def removeRepo(self, repo_id):
        """
        Remove a given repository
        """
        r = self._get_source_entry(repo_id)
        if r is None:
            raise NotFoundError("KCHREPOS0012E", {'repo_id': repo_id})

        kimchiLock.acquire()
        try:
            repos = self._get_repos()
            with self.pkg_lock():
                repos.remove(r)
                repos.save()
        except:
            kimchiLock.release()
            raise OperationFailed("KCHREPOS0017E", {'repo_id': repo_id})
        finally:
            kimchiLock.release()
Beispiel #18
0
    def removeRepo(self, repo_id):
        """
        Remove a given repository
        """
        r = self._get_source_entry(repo_id)
        if r is None:
            raise NotFoundError("KCHREPOS0012E", {'repo_id': repo_id})

        kimchiLock.acquire()
        try:
            repos = self._get_repos()
            with self.pkg_lock():
                repos.remove(r)
                repos.save()
        except:
            kimchiLock.release()
            raise OperationFailed("KCHREPOS0017E", {'repo_id': repo_id})
        finally:
            kimchiLock.release()
Beispiel #19
0
    def getRepositoriesList(self):
        """
        Return a list of repositories IDs

        APT repositories there aren't the concept about repository ID, so for
        internal control, the repository ID will be built as described in
        _get_repo_id()
        """
        kimchiLock.acquire()
        repos = self._get_repos()
        kimchiLock.release()

        res = []
        for r in repos:
            # Ignore deb-src repositories
            if r.type != 'deb':
                continue

            res.append(self._get_repo_id(r))

        return res
Beispiel #20
0
    def getRepositoriesList(self):
        """
        Return a list of repositories IDs

        APT repositories there aren't the concept about repository ID, so for
        internal control, the repository ID will be built as described in
        _get_repo_id()
        """
        kimchiLock.acquire()
        repos = self._get_repos()
        kimchiLock.release()

        res = []
        for r in repos:
            # Ignore deb-src repositories
            if r.type != 'deb':
                continue

            res.append(self._get_repo_id(r))

        return res
Beispiel #21
0
    def getPackagesList(self):
        """
        Return a list of package's dictionaries. Each dictionary contains the
        information about a package, in the format
        package = {'package_name': <string>, 'version': <string>,
                   'arch': <string>, 'repository': <string>}
        """
        if self.isRunning():
            raise OperationFailed('KCHPKGUPD0005E')

        kimchiLock.acquire()
        self._refreshUpdateList()
        kimchiLock.release()
        pkg_list = []
        for pkg in self._pkgs:
            package = {'package_name': pkg.shortname,
                       'version': pkg.candidate.version,
                       'arch': pkg._pkg.architecture,
                       'repository': pkg.candidate.origins[0].label}
            pkg_list.append(package)

        return pkg_list
Beispiel #22
0
    def getPackagesList(self):
        """
        Return a list of package's dictionaries. Each dictionary contains the
        information about a package, in the format
        package = {'package_name': <string>, 'version': <string>,
                   'arch': <string>, 'repository': <string>}
        """
        if self.isRunning():
            raise OperationFailed('KCHPKGUPD0005E')

        kimchiLock.acquire()
        self._refreshUpdateList()
        kimchiLock.release()
        pkg_list = []
        for pkg in self._pkgs:
            package = {
                'package_name': pkg.shortname,
                'version': pkg.candidate.version,
                'arch': pkg._pkg.architecture,
                'repository': pkg.candidate.origins[0].label
            }
            pkg_list.append(package)

        return pkg_list
Beispiel #23
0
    def toggleRepo(self, repo_id, enable):
        """
        Enable a given repository
        """
        r = self._get_source_entry(repo_id)
        if r is None:
            raise NotFoundError("KCHREPOS0012E", {'repo_id': repo_id})

        if enable and not r.disabled:
            raise InvalidOperation("KCHREPOS0015E", {'repo_id': repo_id})

        if not enable and r.disabled:
            raise InvalidOperation("KCHREPOS0016E", {'repo_id': repo_id})

        if enable:
            line = 'deb'
        else:
            line = '#deb'

        kimchiLock.acquire()
        try:
            repos = self._get_repos()
            with self.pkg_lock():
                repos.remove(r)
                repos.add(line, r.uri, r.dist, r.comps, file=self.filename)
                repos.save()
        except:
            kimchiLock.release()
            if enable:
                raise OperationFailed("KCHREPOS0020E", {'repo_id': repo_id})

            raise OperationFailed("KCHREPOS0021E", {'repo_id': repo_id})
        finally:
            kimchiLock.release()

        return repo_id
Beispiel #24
0
    def toggleRepo(self, repo_id, enable):
        """
        Enable a given repository
        """
        r = self._get_source_entry(repo_id)
        if r is None:
            raise NotFoundError("KCHREPOS0012E", {'repo_id': repo_id})

        if enable and not r.disabled:
            raise InvalidOperation("KCHREPOS0015E", {'repo_id': repo_id})

        if not enable and r.disabled:
            raise InvalidOperation("KCHREPOS0016E", {'repo_id': repo_id})

        if enable:
            line = 'deb'
        else:
            line = '#deb'

        kimchiLock.acquire()
        try:
            repos = self._get_repos()
            with self.pkg_lock():
                repos.remove(r)
                repos.add(line, r.uri, r.dist, r.comps, file=self.filename)
                repos.save()
        except:
            kimchiLock.release()
            if enable:
                raise OperationFailed("KCHREPOS0020E", {'repo_id': repo_id})

            raise OperationFailed("KCHREPOS0021E", {'repo_id': repo_id})
        finally:
            kimchiLock.release()

        return repo_id
Beispiel #25
0
        if 'main' in yumcfg and 'logfile' in yumcfg['main']:
            return yumcfg['main']['logfile']

        return None

    def _refreshUpdateList(self):
        """
        Update the list of packages to be updated in the system.
        """
        try:
            kimchiLock.acquire()
            self._pkgs = get_yum_packages_list_update()
        except Exception, e:
            raise OperationFailed('KCHPKGUPD0003E', {'err': str(e)})
        finally:
            kimchiLock.release()

    def getPackagesList(self):
        """
        Return a list of package's dictionaries. Each dictionary contains the
        information about a package, in the format:
        package = {'package_name': <string>, 'version': <string>,
                   'arch': <string>, 'repository': <string>}
        """
        if self.isRunning():
            raise OperationFailed('KCHPKGUPD0005E')

        self._refreshUpdateList()
        pkg_list = []
        for pkg in self._pkgs:
            package = {
Beispiel #26
0
    TYPE = 'yum'
    DEFAULT_CONF_DIR = "/etc/yum.repos.d"
    CONFIG_ENTRY = ('repo_name', 'mirrorlist', 'metalink')

    def __init__(self):
        self._confdir = self.DEFAULT_CONF_DIR

    def _get_repos(self, errcode):
        try:
            kimchiLock.acquire()
            repos = get_yum_repositories()
        except Exception, e:
            kimchiLock.release()
            raise OperationFailed(errcode, {'err': str(e)})
        finally:
            kimchiLock.release()

        return repos

    def getRepositoriesList(self):
        """
        Return a list of repositories IDs
        """
        repos = self._get_repos('KCHREPOS0024E')
        return repos.keys()

    def getRepo(self, repo_id):
        """
        Return a dictionary in the repositories.Repositories() of the given
        repository ID format with the information of a YumRepository object.
        """