def getMirrors(source, defaultMirrorUrl=None): cfg = config.initUp2dateConfig() mirrorPath = "/etc/sysconfig/rhn/mirrors/" mirrorType = "" if cfg.has_key("mirrorLocation"): mirrorType = cfg['mirrorLocation'] if mirrorType != "": mirrorFile = "%s/%s.%s" % (mirrorPath, source['label'], mirrorType) else: mirrorFile = "%s/%s" % (mirrorPath, source['label']) # print "source: %s" % source mirrors = [] arch = up2dateUtils.getUnameArch() # print "mf1: %s" % mirrorFile if os.access(mirrorFile, os.R_OK): # print "mirrorFile: %s" % mirrorFile f = open(mirrorFile, "r") for line in f.readlines(): if line[0] == "#": continue line = string.strip(line) # just in case we want to add more info, like weight, etc tmp = [] tmp = string.split(line, ' ') # sub in arch so we can use one mirror list for all arches url = string.replace(tmp[0], "$ARCH", arch) mirrors.append(url) # if there were user defined mirrors, use them if mirrors: # print "mirrors from /etc: %s" % mirrors return mirrors # print "gh2" #otherwise look for the dymanic ones in /var/spool/up2date mirrorPath = cfg['storageDir'] mirrorFile = "%s/%s" % (mirrorPath, source['label']) mirrors = [] # we should cache these and do If-Modified fetches like we # do for the package list info ## if os.access(mirrorFile, os.R_OK): ### print "mirrorFile: %s" % mirrorFile ## f = open(mirrorFile, "r") ## for line in f.readlines(): ## line = string.strip(line) ## # just in case we want to add more info, like weight, etc ## tmp = [] ## tmp = string.split(line, ' ') ## mirrors.append(tmp[0]) # if there were user defined mirrors, use them if mirrors: return mirrors # print "gh3" # download and save the latest mirror list # use the hardcode url for the moment, till we can # expect mirror lists to be in the base of the repo, hopefully # soon if defaultMirrorUrl == None: return [] # we could try something heirarch here, aka, mirrors.us.es first, then mirrors.us, then mirrors if mirrorType != "": mirrorUrl = "%s.%s" % (defaultMirrorUrl, mirrorType) else: mirrorUrl = "%s" % (defaultMirrorUrl) print mirrorUrl try: readfd = urlUtils.open_resource(mirrorUrl, agent="Up2date/%s" % up2dateUtils.version()) except IOError: # print "gh5" return [] # print "DDDmirrorFile: %s" % mirrorFile fd = open(mirrorFile, "w") fd.write(readfd.read()) readfd.close() fd.close() arch = up2dateUtils.getUnameArch() if os.access(mirrorFile, os.R_OK): # print "mirrorFile2: %s" % mirrorFile f = open(mirrorFile, "r") for line in f.readlines(): line = string.strip(line) # blank line if len(line) == 0: continue if line[0] == "#": continue # just in case we want to add more info, like weight, etc tmp = [] tmp = string.split(line, ' ') url = string.replace(tmp[0], "$ARCH", arch) mirrors.append(url) # print "mirrors: %s" % mirrors return mirrors
def getServer(refreshCallback=None, serverOverride=None, timeout=None): log = up2dateLog.initLog() cfg = config.initUp2dateConfig() # Where do we keep the CA certificate for RHNS? # The servers we're talking to need to have their certs # signed by one of these CA. ca = cfg["sslCACert"] if isinstance(ca, basestring): ca = [ca] rhns_ca_certs = ca or ["/usr/share/rhn/RHNS-CA-CERT"] if cfg["enableProxy"]: proxyHost = config.getProxySetting() else: proxyHost = None if not serverOverride: serverUrls = config.getServerlURL() else: serverUrls = serverOverride serverList = ServerList(serverUrls) proxyUser = None proxyPassword = None if cfg["enableProxyAuth"]: proxyUser = cfg["proxyUser"] or None proxyPassword = cfg["proxyPassword"] or None lang = None for env in 'LANGUAGE', 'LC_ALL', 'LC_MESSAGES', 'LANG': if os.environ.has_key(env): if not os.environ[env]: # sometimes unset continue lang = os.environ[env].split(':')[0] lang = lang.split('.')[0] break s = RetryServer(serverList.server(), refreshCallback=refreshCallback, proxy=proxyHost, username=proxyUser, password=proxyPassword, timeout=timeout) s.addServerList(serverList) s.add_header("X-Up2date-Version", up2dateUtils.version()) if lang: s.setlang(lang) # require RHNS-CA-CERT file to be able to authenticate the SSL connections need_ca = [ True for i in s.serverList.serverList if urlparse.urlparse(i)[0] == 'https' ] if need_ca: for rhns_ca_cert in rhns_ca_certs: if not os.access(rhns_ca_cert, os.R_OK): msg = "%s: %s" % (_("ERROR: can not find RHNS CA file"), rhns_ca_cert) log.log_me("%s" % msg) raise up2dateErrors.SSLCertificateFileNotFound(msg) # force the validation of the SSL cert s.add_trusted_cert(rhns_ca_cert) clientCaps.loadLocalCaps() # send up the capabality info headerlist = clientCaps.caps.headerFormat() for (headerName, value) in headerlist: s.add_header(headerName, value) return s
def getMirrors(source, defaultMirrorUrl=None): cfg = config.initUp2dateConfig() mirrorPath = "/etc/sysconfig/rhn/mirrors/" mirrorType = "" if cfg.has_key("mirrorLocation"): mirrorType = cfg['mirrorLocation'] if mirrorType != "": mirrorFile = "%s/%s.%s" % (mirrorPath, source['label'], mirrorType) else: mirrorFile = "%s/%s" % (mirrorPath, source['label']) # print "source: %s" % source mirrors = [] arch = up2dateUtils.getUnameArch() # print "mf1: %s" % mirrorFile if os.access(mirrorFile, os.R_OK): # print "mirrorFile: %s" % mirrorFile f = open(mirrorFile, "r") for line in f.readlines(): if line[0] == "#": continue line = string.strip(line) # just in case we want to add more info, like weight, etc tmp = [] tmp = string.split(line, ' ') # sub in arch so we can use one mirror list for all arches url = string.replace(tmp[0], "$ARCH", arch) mirrors.append(url) # if there were user defined mirrors, use them if mirrors: # print "mirrors from /etc: %s" % mirrors return mirrors # print "gh2" #otherwise look for the dymanic ones in /var/spool/up2date mirrorPath = cfg['storageDir'] mirrorFile = "%s/%s" % (mirrorPath, source['label']) mirrors = [] # we should cache these and do If-Modified fetches like we # do for the package list info ## if os.access(mirrorFile, os.R_OK): ### print "mirrorFile: %s" % mirrorFile ## f = open(mirrorFile, "r") ## for line in f.readlines(): ## line = string.strip(line) ## # just in case we want to add more info, like weight, etc ## tmp = [] ## tmp = string.split(line, ' ') ## mirrors.append(tmp[0]) # if there were user defined mirrors, use them if mirrors: return mirrors # print "gh3" # download and save the latest mirror list # use the hardcode url for the moment, till we can # expect mirror lists to be in the base of the repo, hopefully # soon if defaultMirrorUrl == None: return [] # we could try something heirarch here, aka, mirrors.us.es first, then mirrors.us, then mirrors if mirrorType != "": mirrorUrl = "%s.%s" % (defaultMirrorUrl,mirrorType) else: mirrorUrl = "%s" % (defaultMirrorUrl) print mirrorUrl try: readfd = urlUtils.open_resource(mirrorUrl, agent="Up2date/%s" % up2dateUtils.version()) except IOError: # print "gh5" return [] # print "DDDmirrorFile: %s" % mirrorFile fd = open(mirrorFile, "w") fd.write(readfd.read()) readfd.close() fd.close() arch = up2dateUtils.getUnameArch() if os.access(mirrorFile, os.R_OK): # print "mirrorFile2: %s" % mirrorFile f = open(mirrorFile, "r") for line in f.readlines(): line = string.strip(line) # blank line if len(line) == 0: continue if line[0] == "#": continue # just in case we want to add more info, like weight, etc tmp = [] tmp = string.split(line, ' ') url = string.replace(tmp[0], "$ARCH", arch) mirrors.append(url) # print "mirrors: %s" % mirrors return mirrors
def getServer(refreshCallback=None): log = up2dateLog.initLog() cfg = config.initUp2dateConfig() # Where do we keep the CA certificate for RHNS? # The servers we're talking to need to have their certs # signed by one of these CA. ca = cfg["sslCACert"] if isinstance(ca, basestring): ca = [ca] rhns_ca_certs = ca or ["/usr/share/rhn/RHNS-CA-CERT"] if cfg["enableProxy"]: proxyHost = config.getProxySetting() else: proxyHost = None serverUrls = config.getServerlURL() serverList = ServerList(serverUrls) proxyUser = None proxyPassword = None if cfg["enableProxyAuth"]: proxyUser = cfg["proxyUser"] or None proxyPassword = cfg["proxyPassword"] or None lang = None for env in 'LANGUAGE', 'LC_ALL', 'LC_MESSAGES', 'LANG': if os.environ.has_key(env): if not os.environ[env]: # sometimes unset continue lang = os.environ[env].split(':')[0] lang = lang.split('.')[0] break s = RetryServer(serverList.server(), refreshCallback=refreshCallback, proxy=proxyHost, username=proxyUser, password=proxyPassword) s.addServerList(serverList) s.add_header("X-Up2date-Version", up2dateUtils.version()) if lang: s.setlang(lang) # require RHNS-CA-CERT file to be able to authenticate the SSL connections for rhns_ca_cert in rhns_ca_certs: if not os.access(rhns_ca_cert, os.R_OK): msg = "%s: %s" % (_("ERROR: can not find RHNS CA file"), rhns_ca_cert) log.log_me("%s" % msg) raise up2dateErrors.SSLCertificateFileNotFound(msg) # force the validation of the SSL cert s.add_trusted_cert(rhns_ca_cert) clientCaps.loadLocalCaps() # send up the capabality info headerlist = clientCaps.caps.headerFormat() for (headerName, value) in headerlist: s.add_header(headerName, value) return s
def getServer(refreshCallback=None): log = up2dateLog.initLog() cfg = config.initUp2dateConfig() # Where do we keep the CA certificate for RHNS? # The servers we're talking to need to have their certs # signed by one of these CA. ca = cfg["sslCACert"] if type(ca) == type(""): ca = [ca] rhns_ca_certs = ca or ["/usr/share/rhn/RHNS-CA-CERT"] if cfg["enableProxy"]: proxyHost = up2dateUtils.getProxySetting() else: proxyHost = None if hasSSL(): serverUrls = cfg["serverURL"] else: serverUrls = cfg["noSSLServerURL"] # the standard is to be a string, so list-a-fy in that case if type(serverUrls) == type(""): serverUrls = [serverUrls] serverList = initServerList(serverUrls) proxyUser = None proxyPassword = None if cfg["enableProxyAuth"]: proxyUser = cfg["proxyUser"] or None proxyPassword = cfg["proxyPassword"] or None lang = None for env in 'LANGUAGE', 'LC_ALL', 'LC_MESSAGES', 'LANG': if os.environ.has_key(env): if not os.environ[env]: # sometimes unset continue lang = string.split(os.environ[env], ':')[0] lang = string.split(lang, '.')[0] break s = RetryServer(serverList.server(), refreshCallback=refreshCallback, proxy=proxyHost, username=proxyUser, password=proxyPassword) s.addServerList(serverList) s.add_header("X-Up2date-Version", up2dateUtils.version()) if lang: s.setlang(lang) # require RHNS-CA-CERT file to be able to authenticate the SSL connections for rhns_ca_cert in rhns_ca_certs: if not os.access(rhns_ca_cert, os.R_OK): msg = "%s: %s" % ("ERROR: can not find RHNS CA file:", rhns_ca_cert) log.log_me("%s" % msg) print msg sys.exit(-1) # force the validation of the SSL cert s.add_trusted_cert(rhns_ca_cert) clientCaps.loadLocalCaps() # send up the capabality info headerlist = clientCaps.caps.headerFormat() for (headerName, value) in headerlist: s.add_header(headerName, value) return s