diff options
author | Scott Moser <smoser@ubuntu.com> | 2011-12-16 11:43:35 -0500 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2011-12-16 11:43:35 -0500 |
commit | e25e758be42c482a0273df6c9e80069bf6ef147c (patch) | |
tree | 91f3f6b523022da4154db05b79db791c3dd9b2b3 /cloudinit/util.py | |
parent | 0c6228a36eebb3bc84924afa99f984c37c3245ca (diff) | |
download | vyos-cloud-init-e25e758be42c482a0273df6c9e80069bf6ef147c.tar.gz vyos-cloud-init-e25e758be42c482a0273df6c9e80069bf6ef147c.zip |
initial mirror configuration/discovery
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r-- | cloudinit/util.py | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py index 0c457128..dc461f6c 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -24,9 +24,11 @@ from Cheetah.Template import Template import urllib2 import urllib import logging +import re +import socket import time import traceback -import re +import urlparse try: import selinux @@ -97,7 +99,7 @@ def get_cfg_by_path(yobj,keyp,default=None): cur = cur[tok] return(cur) -# merge values from src into cand. +# merge values from cand into source # if src has a key, cand will not override def mergedict(src,cand): if isinstance(src,dict) and isinstance(cand,dict): @@ -498,3 +500,26 @@ def get_fqdn_from_hosts(hostname, filename="/etc/hosts"): pass return fqdn + +def is_resolvable(name): + """ determine if a url is resolvable, return a boolean """ + try: + socket.getaddrinfo(name, None) + return True + except socket.gaierror as e: + return False + +def is_resolvable_url(url): + """ determine if this url is resolvable (existing or ip) """ + return(is_resolvable(urlparse.urlparse(url).hostname)) + +def search_for_mirror(candidates): + """ Search through a list of mirror urls for one that works """ + for cand in candidates: + try: + if is_resolvable_url(cand): + return cand + except Exception as e: + raise + + return None |