diff options
author | Daniel Watkins <oddbloke@ubuntu.com> | 2020-03-23 15:39:51 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-23 13:39:51 -0600 |
commit | a18338e99d0ab91f1f08b969bce8181938a284cc (patch) | |
tree | be6fa5446bce267654ee2c2f07bf13e03b640a82 /cloudinit | |
parent | df7a7857566c98df03cd7914643433b15faab5bc (diff) | |
download | vyos-cloud-init-a18338e99d0ab91f1f08b969bce8181938a284cc.tar.gz vyos-cloud-init-a18338e99d0ab91f1f08b969bce8181938a284cc.zip |
cc_apt_configure/util: combine search_for_mirror implementations (#271)
These two implementations had drifted away from one another very
slightly. Reconcile them and then remove the one in cc_apt_configure.
Diffstat (limited to 'cloudinit')
-rw-r--r-- | cloudinit/config/cc_apt_configure.py | 23 | ||||
-rw-r--r-- | cloudinit/util.py | 5 |
2 files changed, 7 insertions, 21 deletions
diff --git a/cloudinit/config/cc_apt_configure.py b/cloudinit/config/cc_apt_configure.py index c44dec45..ff58c062 100644 --- a/cloudinit/config/cc_apt_configure.py +++ b/cloudinit/config/cc_apt_configure.py @@ -763,25 +763,6 @@ def convert_to_v3_apt_format(cfg): return cfg -def search_for_mirror(candidates): - """ - Search through a list of mirror urls for one that works - This needs to return quickly. - """ - if candidates is None: - return None - - LOG.debug("search for mirror in candidates: '%s'", candidates) - for cand in candidates: - try: - if util.is_resolvable_url(cand): - LOG.debug("found working mirror: '%s'", cand) - return cand - except Exception: - pass - return None - - def search_for_mirror_dns(configured, mirrortype, cfg, cloud): """ Try to resolve a list of predefines DNS names to pick mirrors @@ -813,7 +794,7 @@ def search_for_mirror_dns(configured, mirrortype, cfg, cloud): for post in doms: mirror_list.append(mirrorfmt % (post)) - mirror = search_for_mirror(mirror_list) + mirror = util.search_for_mirror(mirror_list) return mirror @@ -876,7 +857,7 @@ def get_mirror(cfg, mirrortype, arch, cloud): # fallback to search if specified if mirror is None: # list of mirrors to try to resolve - mirror = search_for_mirror(mcfg.get("search", None)) + mirror = util.search_for_mirror(mcfg.get("search", None)) # fallback to search_dns if specified if mirror is None: diff --git a/cloudinit/util.py b/cloudinit/util.py index 6a641550..9cc87d7d 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -1230,9 +1230,14 @@ def search_for_mirror(candidates): Search through a list of mirror urls for one that works This needs to return quickly. """ + if candidates is None: + return None + + LOG.debug("search for mirror in candidates: '%s'", candidates) for cand in candidates: try: if is_resolvable_url(cand): + LOG.debug("found working mirror: '%s'", cand) return cand except Exception: pass |