def add_repo(self, repoid, baseurls=[], mirrorlist=None, **kwargs): '''like add_enable_repo, but doesn't do initial repo setup and doesn't make unnecessary changes''' r = yum.yumRepo.YumRepository(repoid) r.name = repoid r.base_persistdir = cachedir r.basecachedir = cachedir r.cache = self.cacheonly r.callback = kwargs.get('callback') or self._repoprogressbar r.failure_obj = self.failstate.callback r.baseurl = [varReplace(u, self.conf.yumvar) for u in baseurls if u] if mirrorlist: r.mirrorlist = varReplace(mirrorlist, self.conf.yumvar) self._repos.add(r) self._repos.enableRepo(repoid)
def _convert_vars(txmbr, command): """converts %options on the command to their values from the package it is running it for: takes $name, $arch, $ver, $rel, $epoch, $state, $repoid""" state_dict = { TS_INSTALL: 'install', TS_TRUEINSTALL: 'install', TS_OBSOLETING: 'obsoleting', TS_UPDATE: 'updating', TS_ERASE: 'remove', TS_OBSOLETED: 'obsoleted', TS_UPDATED: 'updated'} try: state = state_dict[txmbr.output_state] except KeyError: state = 'unknown - %s' % txmbr.output_state vardict = {'name': txmbr.name, 'arch': txmbr.arch, 'ver': txmbr.version, 'rel': txmbr.release, 'epoch': txmbr.epoch, 'repoid': txmbr.repoid, 'state': state } result = varReplace(command, vardict) return result
def _convert_vars(txmbr, command): """converts %options on the command to their values from the package it is running it for: takes $name, $arch, $ver, $rel, $epoch, $state, $repoid""" state_dict = { TS_INSTALL: 'install', TS_TRUEINSTALL: 'install', TS_OBSOLETING: 'obsoleting', TS_UPDATE: 'updating', TS_ERASE: 'remove', TS_OBSOLETED: 'obsoleted', TS_UPDATED: 'updated' } try: state = state_dict[txmbr.output_state] except KeyError: state = 'unknown - %s' % txmbr.output_state vardict = { 'name': txmbr.name, 'arch': txmbr.arch, 'ver': txmbr.version, 'rel': txmbr.release, 'epoch': txmbr.epoch, 'repoid': txmbr.repoid, 'state': state } result = varReplace(command, vardict) return result
def writeRawConfigFile(filename, section_id, yumvar, cfgoptions, items, optionobj, only=None): """ From writeRawRepoFile, but so we can alter [main] too. """ ini = INIConfig(open(filename)) osection_id = section_id # b/c repoids can have $values in them we need to map both ways to figure # out which one is which if section_id not in ini._sections: for sect in ini._sections.keys(): if varReplace(sect, yumvar) == section_id: section_id = sect # Updated the ConfigParser with the changed values cfgOptions = cfgoptions(osection_id) for name, value in items(): if value is None: # Proxy continue if only is not None and name not in only: continue option = optionobj(name) ovalue = option.tostring(value) # If the value is the same, but just interpreted ... when we don't want # to keep the interpreted values. if (name in ini[section_id] and ovalue == varReplace(ini[section_id][name], yumvar)): ovalue = ini[section_id][name] if name not in cfgOptions and option.default == value: continue ini[section_id][name] = ovalue fp = file(filename, "w") fp.write(str(ini)) fp.close()
def writeRawConfigFile(filename, section_id, yumvar, cfgoptions, items, optionobj, only=None): """ From writeRawRepoFile, but so we can alter [main] too. """ ini = INIConfig(open(filename)) osection_id = section_id # b/c repoids can have $values in them we need to map both ways to figure # out which one is which if section_id not in ini._sections: for sect in ini._sections.keys(): if varReplace(sect, yumvar) == section_id: section_id = sect # Updated the ConfigParser with the changed values cfgOptions = cfgoptions(osection_id) for name,value in items(): if value is None: # Proxy continue if only is not None and name not in only: continue option = optionobj(name) ovalue = option.tostring(value) # If the value is the same, but just interpreted ... when we don't want # to keep the interpreted values. if (name in ini[section_id] and ovalue == varReplace(ini[section_id][name], yumvar)): ovalue = ini[section_id][name] if name not in cfgOptions and option.default == value: continue ini[section_id][name] = ovalue fp =file(filename, "w") fp.write(str(ini)) fp.close()
def _generator_repos(self): # get and filter repos from yum, so we can compare it against what SM knows about yum_repos = dict( (rr[0], rr[1].enabled) for rr in yum.repos.repos.items()) # get repos from SM for x in self.invoker.get_repos(): enabled = True if x['enabled'] == '1' else False # if the SM reppo id is not in the yum repo list, or it's enabled flag doesn't match # then we mark the repo file as dirty if x.id not in yum_repos or yum_repos[x.id] != enabled: self.update = True # replace the $vars with the yumvar settings x['baseurl'] = varReplace(x['baseurl'], yum.conf.yumvar) x['enabled'] = enabled # generate the dictionary yield (x.id, x)
def setup_repos(self, callback=None, progressbar=None, repos=[]): '''Return a list of repos that had problems setting up.''' # These will set up progressbar and callback when we actually do setup self.prerepoconf.progressbar = progressbar self.prerepoconf.callback = callback self._repoprogressbar = progressbar # TODO invalidate cache if the version doesn't match previous version log.info("checking repos") # Add default instrepo (and its key) if needed if self.instrepoid is None: self.instrepoid = 'default-installrepo' # FIXME: hardcoded and Fedora-specific mirrorurl = mirrorlist('fedora-install-$releasever') repos.append(('add', '%s=@%s' % (self.instrepoid, mirrorurl))) repos.append(('gpgkey', '%s=%s' % (self.instrepoid, defaultkey))) # We need to read .repo files before we can enable/disable them, so: self.repos # implicit repo setup! ha ha! what fun! if self.version is None: # i.e. no --network arg self.repos.disableRepo('*') # user overrides to enable/disable repos. # NOTE: will raise YumBaseError if there are problems for action, repo in repos: if action == 'enable': self.repos.enableRepo(repo) elif action == 'disable': self.repos.disableRepo(repo) elif action == 'add': (repoid, url) = repo.split('=',1) if url[0] == '@': self.add_repo(repoid, mirrorlist=url[1:]) else: self.add_repo(repoid, baseurls=[url]) if self.conf.proxy: repo = self.repos.getRepo(repoid) repo.proxy = self.conf.proxy repo.proxy_username = self.conf.proxy_username repo.proxy_password = self.conf.proxy_password # add GPG keys *after* the repos are created for action, repo in repos: if action == 'gpgkey': (repoid, keyurl) = repo.split('=',1) repo = self.repos.getRepo(repoid) repo.gpgkey.append(varReplace(keyurl, self.conf.yumvar)) repo.gpgcheck = True # check enabled repos for repo in self.repos.listEnabled(): try: md_types = repo.repoXML.fileTypes() except yum.Errors.RepoError: log.info("can't find valid repo metadata for %s", repo.id) repo.disable() self.disabled_repos.append(repo.id) else: log.info("repo %s seems OK" % repo.id) # Disable gpg key checking for the repos, if requested if self._override_sigchecks: repo._override_sigchecks = True log.debug("repos.cache=%i", self.repos.cache) return self.disabled_repos
def fetch(self): global jws_method, osvendor if self.osversion == None: raise Exception('OS version not found.') if self.hostkey == None or self.hostkey == '00000000000000000000000000000000': raise Exception('system hostkey not found.') params = { 'method': jws_method, 'hostkey': self.hostkey, 'vendor': osvendor, 'osname': self.osname, 'osversion': self.osversion, 'arch': self.basearch, 'enablebeta': str(self.enable_beta), 'software_id': self.software_id } request = "%s?%s" % (self.request, urllib.urlencode(params)) hc = httplib.HTTPSConnection(self.url) hc.request("GET", request) hr = hc.getresponse() if hr.status != 200: raise Exception('unable to retrieve repository data.') buffer = hr.read() hc.close() response = self.byteify(json.loads(buffer)) if not response.has_key('code'): raise Exception('malformed response.') if response['code'] != 0: if not response.has_key('errmsg'): raise Exception('request failed, error code: %d' % (response['code'])) else: raise Exception('%s Code: %d' % (response['errmsg'], response['code'])) if response.has_key('community') and response['community'] == 1: if not os.path.exists('/var/clearos/registration/verified'): repos_to_enable = self.yum_repos.findRepos( 'clearos-centos,clearos-centos-updates,clearos-epel,clearos-updates', name_match=True, ignore_case=True) repo_status(repos_to_enable, enable=True) touch('/var/clearos/registration/verified') if not response.has_key('repos'): raise Exception('malformed response, missing repos.') repos = [] baseurl = False for r in response['repos']: repo = Repository(r['name']) baserepo = re.sub(r'^clearos-(.*?)(-testing)?$', r'\1', r['name']) repo.yumvar = self.conf.yumvar repo.name = varReplace(r['description'], repo.yumvar) repo.basecachedir = self.conf.cachedir repo.base_persistdir = self.conf._repos_persistdir if 'mirrorlist' in r: repo.setAttribute('mirrorlist', varReplace(r['mirrorlist'], repo.yumvar)) else: urls = [] for u in r['baseurl']: url = varReplace(u['url'], repo.yumvar) if len(u['username']) > 0: url = urlparse(u['url']) port = 80 if url.port != None: port = url.port url = "%s://%s:%s@%s:%s%s" % ( url.scheme, u['username'], u['password'], url.netloc, port, url.path) if u['url'].find('$basearch') < 0: urls.append(url + '/' + self.basearch) else: urls.append(url) repo.setAttribute('baseurl', urls) repo.setAttribute('enabled', r['enabled']) repo.setAttribute('gpgcheck', r['gpgcheck']) if 'gpgkey' in r: repo.setAttribute('gpgkey', varReplace(r['gpgkey'], repo.yumvar)) if 'sslverify' in r: repo.setAttribute('sslverify', r['sslverify']) else: repo.setAttribute('sslverify', 0) if not r['name'].startswith('private-'): headers = r.get('header', {}) headers.update(response.get('header', {})) if 'expire' in headers: headers['hostid'] = self.hostkey pkgkeys = True pkg_headers = {} for key, value in headers.iteritems(): if key in ['hostid', 'expire', 'key']: repo.http_headers['X-%s' % key.upper()] = value elif key in ['everyting', baserepo]: pkgkeys = False repo.http_headers['X-KEY-%s' % key.upper()] = value else: pkg_headers['X-KEY-%s' % key.upper()] = value if pkgkeys: repo.http_headers.update(pkg_headers) group = re.sub(r'^clearos-', r'', r['name']) request = '/pkgapi/%s/%s' % (self.osversion[:1], group) try: hc = httplib.HTTPSConnection('mirrorlist.clearos.com') hc.request("GET", request, None, repo.http_headers) hr = hc.getresponse() if hr.status != 200: raise Exception( 'unable to retrieve repository data.') incpkgs = hr.read() hc.close() repo.setAttribute('includepkgs', incpkgs.split()) except: pass if not repo.includepkgs: repo.setAttribute('includepkgs', ['None']) repos.append(repo) return repos