Пример #1
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('GGBPKGUPD0005E')

        gingerBaseLock.acquire()
        try:
            self._refreshUpdateList()
        except Exception:
            raise
        finally:
            gingerBaseLock.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
Пример #2
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('GGBREPOS0019E')

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

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

        validate_repo_url(get_expanded_url(uri))

        gingerBaseLock.acquire()
        try:
            repos = self._get_repos()
            source_entry = repos.add('deb',
                                     uri,
                                     dist,
                                     comps,
                                     file=self.filename)
            repos.save()
        except Exception as e:
            raise OperationFailed('GGBREPOS0026E', {'err': e.message})
        finally:
            gingerBaseLock.release()
        return self._get_repo_id(source_entry)
Пример #3
0
    def toggleRepo(self, repo_id, enable):
        """
        Enable a given repository
        """
        r = self._get_source_entry(repo_id)
        if r is None:
            raise NotFoundError('GGBREPOS0012E', {'repo_id': repo_id})

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

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

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

        gingerBaseLock.acquire()
        try:
            repos = self._get_repos()
            repos.remove(r)
            repos.add(line, r.uri, r.dist, r.comps, file=self.filename)
            repos.save()
        except Exception:
            if enable:
                raise OperationFailed('GGBREPOS0020E', {'repo_id': repo_id})

            raise OperationFailed('GGBREPOS0021E', {'repo_id': repo_id})
        finally:
            gingerBaseLock.release()

        return repo_id
Пример #4
0
    def toggleRepo(self, repo_id, enable):
        repos = self._get_repos('GGBREPOS0011E')
        if repo_id not in repos.keys():
            raise NotFoundError('GGBREPOS0012E', {'repo_id': repo_id})

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

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

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

            write_repo_to_file(entry)
        except Exception:
            if enable:
                raise OperationFailed('GGBREPOS0020E', {'repo_id': repo_id})

            raise OperationFailed('GGBREPOS0021E', {'repo_id': repo_id})
        finally:
            gingerBaseLock.release()

        return repo_id
Пример #5
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()
        """
        gingerBaseLock.acquire()
        try:
            repos = self._get_repos()
        except OperationFailed:
            raise
        finally:
            gingerBaseLock.release()

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

            res.append(self._get_repo_id(r))

        return res
Пример #6
0
    def toggleRepo(self, repo_id, enable):
        """
        Enable a given repository
        """
        r = self._get_source_entry(repo_id)
        if r is None:
            raise NotFoundError("GGBREPOS0012E", {'repo_id': repo_id})

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

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

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

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

            raise OperationFailed("GGBREPOS0021E", {'repo_id': repo_id})
        finally:
            gingerBaseLock.release()

        return repo_id
Пример #7
0
 def _get_repos(self, errcode):
     try:
         gingerBaseLock.acquire()
         repos = get_yum_repositories()
     except Exception, e:
         gingerBaseLock.release()
         raise OperationFailed(errcode, {'err': str(e)})
Пример #8
0
 def _get_repos(self, errcode):
     try:
         gingerBaseLock.acquire()
         repos = get_yum_repositories()
     except Exception, e:
         gingerBaseLock.release()
         raise OperationFailed(errcode, {'err': str(e)})
Пример #9
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('GGBPKGUPD0005E')

        gingerBaseLock.acquire()
        try:
            self._refreshUpdateList()
        except Exception:
            raise
        finally:
            gingerBaseLock.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
Пример #10
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()
        """
        gingerBaseLock.acquire()
        try:
            repos = self._get_repos()
        except OperationFailed:
            raise
        finally:
            gingerBaseLock.release()

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

            res.append(self._get_repo_id(r))

        return res
Пример #11
0
    def toggleRepo(self, repo_id, enable):
        repos = self._get_repos('GGBREPOS0011E')
        if repo_id not in repos.keys():
            raise NotFoundError("GGBREPOS0012E", {'repo_id': repo_id})

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

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

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

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

            raise OperationFailed("GGBREPOS0021E", {'repo_id': repo_id})
        finally:
            gingerBaseLock.release()

        return repo_id
Пример #12
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("GGBREPOS0019E")

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

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

        validate_repo_url(get_expanded_url(uri))

        gingerBaseLock.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:
            gingerBaseLock.release()
            raise OperationFailed("GGBREPOS0026E", {'err': e.message})
        gingerBaseLock.release()
        return self._get_repo_id(source_entry)
Пример #13
0
 def _refreshUpdateList(self):
     """
     Update the list of packages to be updated in the system.
     """
     try:
         gingerBaseLock.acquire()
         self._pkgs = get_yum_packages_list_update()
     except Exception, e:
         raise OperationFailed('GGBPKGUPD0003E', {'err': str(e)})
Пример #14
0
    def getPackageInfo(self, pkg_name):
        """
        Get package information. The return is a dictionary containg the
        information about a package, in the format:

        package = {'package_name': <string>,
                   'version': <string>,
                   'arch': <string>,
                   'repository': <string>,
                   'depends': <list>
                  }
        """
        if self.isRunning():
            raise OperationFailed('GGBPKGUPD0005E')

        gingerBaseLock.acquire()
        cmd = ["zypper", "info", "--requires", pkg_name]
        (stdout, stderr, returncode) = run_command(cmd)

        if len(stderr) > 0:
            raise OperationFailed('GGBPKGUPD0006E', {'err': stderr})

        # Zypper returns returncode == 0 and stderr <= 0, even if package is
        # not found in it's base. Need check the output of the command to parse
        # correctly.
        stdout = stdout.split('\n')
        message = 'package \'%s\' not found.' % pkg_name
        if message in stdout:
            raise NotFoundError('GGBPKGUPD0006E', {'err': message})

        package = {}
        for (key, token) in (('repository', 'Repository:'),
                             ('version', 'Version:'),
                             ('arch', 'Arch:'),
                             ('package_name', 'Name:')):
            for line in stdout:
                if line.startswith(token):
                    package[key] = line.split(': ')[1].strip()
                    break

        # get the list of dependencies
        pkg_dep = []
        for line in stdout[stdout.index('Requires:')+1:len(stdout)-1]:
            # scan for valid lines with package names
            line = line.strip()
            if '.so' in line:
                continue
            if line.startswith('/'):
                continue
            if "python(abi)" in line:
                line = "python-base"
            pkg_dep.append(line.split()[0])
        pkg_dep = list(set(pkg_dep))
        package['depends'] = pkg_dep
        gingerBaseLock.release()
        return package
Пример #15
0
    def getPackagesList(self):
        """
        Return a list of packages eligible to be updated by Yum.
        """
        if self.isRunning():
            raise OperationFailed('GGBPKGUPD0005E')

        pkgs = []
        try:
            gingerBaseLock.acquire()
            pkgs = get_yum_packages_list_update()
        except Exception, e:
            raise OperationFailed('GGBPKGUPD0003E', {'err': str(e)})
Пример #16
0
    def updateRepo(self, repo_id, params):
        """
        Update a given repository in repositories.Repositories() format
        """
        repos = self._get_repos('GGBREPOS0011E')
        if repo_id not in repos.keys():
            raise NotFoundError('GGBREPOS0012E', {'repo_id': repo_id})

        entry = repos.get(repo_id)

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

        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('GGBREPOS0013E')

        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('GGBREPOS0030E')

        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)
        gingerBaseLock.acquire()
        write_repo_to_file(entry)
        gingerBaseLock.release()
        return repo_id
Пример #17
0
    def getPackagesList(self):
        """
        Return a list of packages eligible to be updated by apt-get.
        """
        if self.isRunning():
            raise OperationFailed('GGBPKGUPD0005E')

        gingerBaseLock.acquire()
        try:
            self._apt_cache.update()
            self._apt_cache.upgrade()
            pkgs = self._apt_cache.get_changes()
        except Exception, e:
            raise OperationFailed('GGBPKGUPD0003E', {'err': e.message})
Пример #18
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('GGBPKGUPD0005E')

        gingerBaseLock.acquire()
        self._refreshUpdateList()
        gingerBaseLock.release()
        return self._pkgs
Пример #19
0
    def updateRepo(self, repo_id, params):
        """
        Update a given repository in repositories.Repositories() format
        """
        repos = self._get_repos('GGBREPOS0011E')
        if repo_id not in repos.keys():
            raise NotFoundError("GGBREPOS0012E", {'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("GGBREPOS0013E")

        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('GGBREPOS0030E')

        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)
        gingerBaseLock.acquire()
        write_repo_to_file(entry)
        gingerBaseLock.release()
        return repo_id
Пример #20
0
    def _get_source_entry(self, repo_id):
        gingerBaseLock.acquire()
        repos = self._get_repos()
        gingerBaseLock.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
Пример #21
0
    def _get_source_entry(self, repo_id):
        gingerBaseLock.acquire()
        repos = self._get_repos()
        gingerBaseLock.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
Пример #22
0
    def removeRepo(self, repo_id):
        """
        Remove a given repository
        """
        r = self._get_source_entry(repo_id)
        if r is None:
            raise NotFoundError('GGBREPOS0012E', {'repo_id': repo_id})

        gingerBaseLock.acquire()
        try:
            repos = self._get_repos()
            repos.remove(r)
            repos.save()
        except Exception:
            raise OperationFailed('GGBREPOS0017E', {'repo_id': repo_id})
        finally:
            gingerBaseLock.release()
Пример #23
0
    def removeRepo(self, repo_id):
        """
        Remove a given repository
        """
        r = self._get_source_entry(repo_id)
        if r is None:
            raise NotFoundError("GGBREPOS0012E", {'repo_id': repo_id})

        gingerBaseLock.acquire()
        try:
            repos = self._get_repos()
            repos.remove(r)
            repos.save()
        except:
            raise OperationFailed("GGBREPOS0017E", {'repo_id': repo_id})
        finally:
            gingerBaseLock.release()
Пример #24
0
    def getPackagesList(self):
        """
        Return a list of packages eligible to be updated by Zypper.
        """
        if self.isRunning():
            raise OperationFailed('GGBPKGUPD0005E')

        gingerBaseLock.acquire()
        packages = []
        cmd = ["zypper", "list-updates"]
        (stdout, stderr, returncode) = run_command(cmd)

        if len(stderr) > 0:
            raise OperationFailed('GGBPKGUPD0003E', {'err': stderr})

        for line in stdout.split('\n'):
            if line.startswith('v |'):
                packages.append(line.split(' | ')[2].strip())
        gingerBaseLock.release()
        return packages
Пример #25
0
    def _get_source_entry(self, repo_id):
        gingerBaseLock.acquire()
        try:
            repos = self._get_repos()
        except OperationFailed:
            raise
        finally:
            gingerBaseLock.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
Пример #26
0
    def _get_source_entry(self, repo_id):
        gingerBaseLock.acquire()
        try:
            repos = self._get_repos()
        except OperationFailed:
            raise
        finally:
            gingerBaseLock.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
Пример #27
0
    def getPackageInfo(self, pkg_name):
        """
        Get package information. The return is a dictionary containg the
        information about a package, in the format:

        package = {'package_name': <string>,
                   'version': <string>,
                   'arch': <string>,
                   'repository': <string>,
                   'depends': <list>
                  }
        """
        if self.isRunning():
            raise OperationFailed('GGBPKGUPD0005E')

        package = {}
        try:
            gingerBaseLock.acquire()
            package = get_dnf_package_info(pkg_name)
        except Exception, e:
            raise NotFoundError('GGBPKGUPD0003E', {'err': str(e)})
Пример #28
0
    def getPackageInfo(self, pkg_name):
        """
        Get package information. The return is a dictionary containg the
        information about a package, in the format:

        package = {'package_name': <string>,
                   'version': <string>,
                   'arch': <string>,
                   'repository': <string>,
                   'depends': <list>
                  }
        """
        if self.isRunning():
            raise OperationFailed('GGBPKGUPD0005E')

        package = {}
        gingerBaseLock.acquire()
        try:
            self._apt_cache.upgrade()
            pkgs = self._apt_cache.get_changes()
        except Exception, e:
            raise OperationFailed('GGBPKGUPD0006E', {'err': e.message})