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)
def _get_repos(self, errcode): try: kimchiLock.acquire() repos = get_yum_repositories() except Exception, e: kimchiLock.release() raise OperationFailed(errcode, {'err': str(e)})
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
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)})
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
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
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
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()
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
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
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
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