[Yum-devel] [PATCH] Add "timedhosts" info from the fastestmirror plugin. BZ 904622

Zdenek Pavlas zpavlas at redhat.com
Fri Feb 1 14:57:59 UTC 2013


Host profiling in urlgrabber is more accurate, but these timings
are indeed useful and can help in some cases.  E.g. fastestmirror
very efficiently (in parallel) detects dead mirrors.
---
 yum/yumRepo.py | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/yum/yumRepo.py b/yum/yumRepo.py
index 392102d..1d601e7 100644
--- a/yum/yumRepo.py
+++ b/yum/yumRepo.py
@@ -574,23 +574,24 @@ class YumRepository(Repository, config.RepoConf):
                                     copy_local=self.copy_local,
                                     reget='simple',
                                     **ugopts)
+        # use fastestmirror data if available
+        try: from fastestmirror import timedhosts
+        except: timedhosts = {}
         def add_mc(url):
             host = urlparse.urlsplit(url).netloc.split('@')[-1]
-            mc = self.metalink_data._host2mc.get(host)
-            if mc:
-                url = {
-                    'mirror': misc.to_utf8(url),
-                    'kwargs': {
-                        'max_connections': mc.max_connections,
-                        'preference': mc.preference,
-                        'private': mc.private,
-                    },
-                }
+            mc = self.metalink and self.metalink_data._host2mc.get(host)
+            th = timedhosts.get(host)
+            if mc or th:
+                kw = {}
+                url = { 'mirror': misc.to_utf8(url), 'kwargs': kw }
+                if mc:
+                    kw['max_connections'] = mc.max_connections
+                    kw['preference'] = mc.preference
+                    kw['private'] = mc.private
+                if th:
+                    kw['timedhosts'] = th
             return url
-        urls = self.urls
-        if self.metalink:
-            urls = map(add_mc, urls)
-
+        urls = map(add_mc, self.urls)
         self._grab = mgclass(self._grabfunc, urls,
                              failure_callback=self.mirror_failure_obj)
 
-- 
1.7.11.7



More information about the Yum-devel mailing list