[PATCH 06/13] Fix pylint warnings W0612 (unused variable)
From: Juerg Haefliger <juerg.haefliger@hp.com>
This commit is contained in:
@@ -31,7 +31,6 @@ def main():
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
cc = cloudinit.CloudConfig.CloudConfig(cloudinit.cloud_config)
|
cc = cloudinit.CloudConfig.CloudConfig(cloudinit.cloud_config)
|
||||||
cloud_config = cc.cfg
|
|
||||||
data = {
|
data = {
|
||||||
'user_data' : cc.cloud.get_userdata(),
|
'user_data' : cc.cloud.get_userdata(),
|
||||||
'user_data_raw' : cc.cloud.get_userdata_raw(),
|
'user_data_raw' : cc.cloud.get_userdata_raw(),
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ def rename_apt_lists(omirror,new_mirror,lists_d="/var/lib/apt/lists"):
|
|||||||
os.rename(file,"%s%s" % (nprefix, file[olen:]))
|
os.rename(file,"%s%s" % (nprefix, file[olen:]))
|
||||||
|
|
||||||
def get_release():
|
def get_release():
|
||||||
stdout, stderr = subprocess.Popen(['lsb_release', '-cs'], stdout=subprocess.PIPE).communicate()
|
stdout, _stderr = subprocess.Popen(['lsb_release', '-cs'], stdout=subprocess.PIPE).communicate()
|
||||||
return(stdout.strip())
|
return(stdout.strip())
|
||||||
|
|
||||||
def generate_sources_list(codename, mirror):
|
def generate_sources_list(codename, mirror):
|
||||||
@@ -202,7 +202,7 @@ def find_apt_mirror(cloud, cfg):
|
|||||||
|
|
||||||
if not mirror and cloud:
|
if not mirror and cloud:
|
||||||
# if we have a fqdn, then search its domain portion first
|
# if we have a fqdn, then search its domain portion first
|
||||||
( hostname, fqdn ) = util.get_hostname_fqdn(cfg, cloud)
|
( _hostname, fqdn ) = util.get_hostname_fqdn(cfg, cloud)
|
||||||
mydom = ".".join(fqdn.split(".")[1:])
|
mydom = ".".join(fqdn.split(".")[1:])
|
||||||
if mydom:
|
if mydom:
|
||||||
doms.append(".%s" % mydom)
|
doms.append(".%s" % mydom)
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ def handle(_name,cfg,cloud,log,_args):
|
|||||||
with open('/etc/chef/validation.pem', 'w') as validation_key_fh:
|
with open('/etc/chef/validation.pem', 'w') as validation_key_fh:
|
||||||
validation_key_fh.write(validation_key)
|
validation_key_fh.write(validation_key)
|
||||||
|
|
||||||
validation_name = chef_cfg.get('validation_name','chef-validator')
|
|
||||||
# create the chef config from template
|
# create the chef config from template
|
||||||
util.render_to_file('chef_client.rb', '/etc/chef/client.rb',
|
util.render_to_file('chef_client.rb', '/etc/chef/client.rb',
|
||||||
{'server_url': chef_cfg['server_url'],
|
{'server_url': chef_cfg['server_url'],
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ def handle(_name,cfg,_cloud,log,args):
|
|||||||
|
|
||||||
cmd = [ 'blkid', '-c', '/dev/null', '-sTYPE', '-ovalue', devpth ]
|
cmd = [ 'blkid', '-c', '/dev/null', '-sTYPE', '-ovalue', devpth ]
|
||||||
try:
|
try:
|
||||||
(fstype,err) = util.subp(cmd)
|
(fstype,_err) = util.subp(cmd)
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
log.warn("Failed to get filesystem type of maj=%s, min=%s via: %s" %
|
log.warn("Failed to get filesystem type of maj=%s, min=%s via: %s" %
|
||||||
(os.major(st_dev), os.minor(st_dev), cmd))
|
(os.major(st_dev), os.minor(st_dev), cmd))
|
||||||
@@ -74,7 +74,7 @@ def handle(_name,cfg,_cloud,log,args):
|
|||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
(out,err) = util.subp(resize_cmd)
|
util.subp(resize_cmd)
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
log.warn("Failed to resize filesystem (%s)" % resize_cmd)
|
log.warn("Failed to resize filesystem (%s)" % resize_cmd)
|
||||||
log.warn("output=%s\nerror=%s\n", e.output[0], e.output[1])
|
log.warn("output=%s\nerror=%s\n", e.output[0], e.output[1])
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ def handle(_name,_cfg,cloud,log,_args):
|
|||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
mdict = parse_qs(cloud.get_userdata_raw())
|
mdict = parse_qs(ud)
|
||||||
if not my_hookname in mdict: return
|
if not my_hookname in mdict: return
|
||||||
except:
|
except:
|
||||||
log.warn("failed to urlparse.parse_qa(userdata_raw())")
|
log.warn("failed to urlparse.parse_qa(userdata_raw())")
|
||||||
@@ -58,7 +58,6 @@ def handle(_name,_cfg,cloud,log,_args):
|
|||||||
|
|
||||||
scripts_d = get_ipath_cur('scripts')
|
scripts_d = get_ipath_cur('scripts')
|
||||||
i = 0
|
i = 0
|
||||||
errors = [ ]
|
|
||||||
first_e = None
|
first_e = None
|
||||||
for url in mdict[my_hookname]:
|
for url in mdict[my_hookname]:
|
||||||
fname = "%s/rightscale-%02i" % (scripts_d,i)
|
fname = "%s/rightscale-%02i" % (scripts_d,i)
|
||||||
|
|||||||
@@ -38,8 +38,6 @@ def handle(_name,cfg,_cloud,log,_args):
|
|||||||
def_dir = cfg.get('rsyslog_dir', DEF_DIR)
|
def_dir = cfg.get('rsyslog_dir', DEF_DIR)
|
||||||
def_fname = cfg.get('rsyslog_filename', DEF_FILENAME)
|
def_fname = cfg.get('rsyslog_filename', DEF_FILENAME)
|
||||||
|
|
||||||
entries = cfg['rsyslog']
|
|
||||||
|
|
||||||
files = [ ]
|
files = [ ]
|
||||||
elst = [ ]
|
elst = [ ]
|
||||||
for ent in cfg['rsyslog']:
|
for ent in cfg['rsyslog']:
|
||||||
@@ -80,7 +78,7 @@ def handle(_name,cfg,_cloud,log,_args):
|
|||||||
# it will also return failure on the attempt, so 'restarted'
|
# it will also return failure on the attempt, so 'restarted'
|
||||||
# won't get set
|
# won't get set
|
||||||
log.debug("restarting rsyslog")
|
log.debug("restarting rsyslog")
|
||||||
p = util.subp(['service', 'rsyslog', 'restart'])
|
util.subp(['service', 'rsyslog', 'restart'])
|
||||||
restarted = True
|
restarted = True
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -23,10 +23,10 @@ def handle(_name,cfg,cloud,log,_args):
|
|||||||
log.debug("preserve_hostname is set. not setting hostname")
|
log.debug("preserve_hostname is set. not setting hostname")
|
||||||
return(True)
|
return(True)
|
||||||
|
|
||||||
( hostname, fqdn ) = util.get_hostname_fqdn(cfg, cloud)
|
( hostname, _fqdn ) = util.get_hostname_fqdn(cfg, cloud)
|
||||||
try:
|
try:
|
||||||
set_hostname(hostname, log)
|
set_hostname(hostname, log)
|
||||||
except Exception as e:
|
except Exception:
|
||||||
util.logexc(log)
|
util.logexc(log)
|
||||||
log.warn("failed to set hostname to %s\n", hostname)
|
log.warn("failed to set hostname to %s\n", hostname)
|
||||||
|
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ def handle(_name,cfg,_cloud,log,args):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def rand_str(strlen=32, select_from=string.letters+string.digits):
|
def rand_str(strlen=32, select_from=string.letters+string.digits):
|
||||||
return("".join([random.choice(select_from) for x in range(0, strlen)]))
|
return("".join([random.choice(select_from) for _x in range(0, strlen)]))
|
||||||
|
|
||||||
def rand_user_password(pwlen=9):
|
def rand_user_password(pwlen=9):
|
||||||
selfrom=(string.letters.translate(None,'loLOI') +
|
selfrom=(string.letters.translate(None,'loLOI') +
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ def handle(_name,cfg,cloud,log,_args):
|
|||||||
|
|
||||||
util.render_to_file('hosts', '/etc/hosts', \
|
util.render_to_file('hosts', '/etc/hosts', \
|
||||||
{ 'hostname' : hostname, 'fqdn' : fqdn })
|
{ 'hostname' : hostname, 'fqdn' : fqdn })
|
||||||
except Exception as e:
|
except Exception:
|
||||||
log.warn("failed to update /etc/hosts")
|
log.warn("failed to update /etc/hosts")
|
||||||
raise
|
raise
|
||||||
elif manage_hosts == "localhost":
|
elif manage_hosts == "localhost":
|
||||||
|
|||||||
@@ -27,11 +27,11 @@ def handle(_name,cfg,cloud,log,_args):
|
|||||||
log.debug("preserve_hostname is set. not updating hostname")
|
log.debug("preserve_hostname is set. not updating hostname")
|
||||||
return
|
return
|
||||||
|
|
||||||
( hostname, fqdn ) = util.get_hostname_fqdn(cfg, cloud)
|
( hostname, _fqdn ) = util.get_hostname_fqdn(cfg, cloud)
|
||||||
try:
|
try:
|
||||||
prev ="%s/%s" % (cloud.get_cpath('data'),"previous-hostname")
|
prev ="%s/%s" % (cloud.get_cpath('data'),"previous-hostname")
|
||||||
update_hostname(hostname, prev, log)
|
update_hostname(hostname, prev, log)
|
||||||
except Exception as e:
|
except Exception:
|
||||||
log.warn("failed to set hostname\n")
|
log.warn("failed to set hostname\n")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ class DataSource:
|
|||||||
if isinstance(self.metadata['public-keys'], str):
|
if isinstance(self.metadata['public-keys'], str):
|
||||||
return([self.metadata['public-keys'],])
|
return([self.metadata['public-keys'],])
|
||||||
|
|
||||||
for keyname, klist in self.metadata['public-keys'].items():
|
for _keyname, klist in self.metadata['public-keys'].items():
|
||||||
# lp:506332 uec metadata service responds with
|
# lp:506332 uec metadata service responds with
|
||||||
# data that makes boto populate a string for 'klist' rather
|
# data that makes boto populate a string for 'klist' rather
|
||||||
# than a list.
|
# than a list.
|
||||||
@@ -197,7 +197,7 @@ def is_ipv4(instr):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
r = filter(lambda x: int(x) < 256 and x > 0, toks)
|
filter(lambda x: int(x) < 256 and x > 0, toks)
|
||||||
except:
|
except:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ class DataSourceEc2(DataSource.DataSource):
|
|||||||
max_wait = 120
|
max_wait = 120
|
||||||
try:
|
try:
|
||||||
max_wait = int(mcfg.get("max_wait",max_wait))
|
max_wait = int(mcfg.get("max_wait",max_wait))
|
||||||
except Exception as e:
|
except Exception:
|
||||||
util.logexc(log)
|
util.logexc(log)
|
||||||
log.warn("Failed to get max wait. using %s" % max_wait)
|
log.warn("Failed to get max wait. using %s" % max_wait)
|
||||||
|
|
||||||
@@ -99,7 +99,7 @@ class DataSourceEc2(DataSource.DataSource):
|
|||||||
timeout = 50
|
timeout = 50
|
||||||
try:
|
try:
|
||||||
timeout = int(mcfg.get("timeout",timeout))
|
timeout = int(mcfg.get("timeout",timeout))
|
||||||
except Exception as e:
|
except Exception:
|
||||||
util.logexc(log)
|
util.logexc(log)
|
||||||
log.warn("Failed to get timeout, using %s" % timeout)
|
log.warn("Failed to get timeout, using %s" % timeout)
|
||||||
|
|
||||||
@@ -226,7 +226,6 @@ def wait_for_metadata_service(urls, max_wait=None, timeout=None, status_cb=None)
|
|||||||
starttime = time.time()
|
starttime = time.time()
|
||||||
|
|
||||||
sleeptime = 1
|
sleeptime = 1
|
||||||
timeout_orig = timeout
|
|
||||||
|
|
||||||
if status_cb == None:
|
if status_cb == None:
|
||||||
def status_cb(msg): return
|
def status_cb(msg): return
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ class DataSourceOVF(DataSource.DataSource):
|
|||||||
np = { 'iso' : transport_iso9660,
|
np = { 'iso' : transport_iso9660,
|
||||||
'vmware-guestd' : transport_vmware_guestd, }
|
'vmware-guestd' : transport_vmware_guestd, }
|
||||||
for name, transfunc in np.iteritems():
|
for name, transfunc in np.iteritems():
|
||||||
(contents, dev, fname) = transfunc()
|
(contents, _dev, _fname) = transfunc()
|
||||||
if contents: break
|
if contents: break
|
||||||
|
|
||||||
if contents:
|
if contents:
|
||||||
@@ -171,7 +171,7 @@ def transport_iso9660(require_iso=False):
|
|||||||
|
|
||||||
mounted = { }
|
mounted = { }
|
||||||
for mpline in mounts:
|
for mpline in mounts:
|
||||||
(dev,mp,fstype,opts,freq,passno) = mpline.split()
|
(dev,mp,fstype,_opts,_freq,_passno) = mpline.split()
|
||||||
mounted[dev]=(dev,fstype,mp,False)
|
mounted[dev]=(dev,fstype,mp,False)
|
||||||
mp = mp.replace("\\040"," ")
|
mp = mp.replace("\\040"," ")
|
||||||
if fstype != "iso9660" and require_iso: continue
|
if fstype != "iso9660" and require_iso: continue
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ class AuthKeyEntry():
|
|||||||
elif curc == '"':
|
elif curc == '"':
|
||||||
quoted = not quoted
|
quoted = not quoted
|
||||||
i = i + 1
|
i = i + 1
|
||||||
except IndexError as e:
|
except IndexError:
|
||||||
self.is_comment = True
|
self.is_comment = True
|
||||||
return()
|
return()
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ class AuthKeyEntry():
|
|||||||
self.options = ent[0:i]
|
self.options = ent[0:i]
|
||||||
(self.keytype, self.base64, self.comment) = \
|
(self.keytype, self.base64, self.comment) = \
|
||||||
ent[i+1:].split(None,3)
|
ent[i+1:].split(None,3)
|
||||||
except ValueError as e:
|
except ValueError:
|
||||||
# we did not understand this line
|
# we did not understand this line
|
||||||
self.is_comment = True
|
self.is_comment = True
|
||||||
|
|
||||||
@@ -84,7 +84,7 @@ def update_authorized_keys(fname, keys):
|
|||||||
fp = open(fname, "r")
|
fp = open(fname, "r")
|
||||||
lines = fp.readlines() # lines have carriage return
|
lines = fp.readlines() # lines have carriage return
|
||||||
fp.close()
|
fp.close()
|
||||||
except IOError as e:
|
except IOError:
|
||||||
lines = [ ]
|
lines = [ ]
|
||||||
|
|
||||||
ka_stats = { } # keys_added status
|
ka_stats = { } # keys_added status
|
||||||
@@ -133,7 +133,7 @@ def setup_user_keys(keys, user, key_prefix, log=None):
|
|||||||
akeys = akeys.replace("%h", pwent.pw_dir)
|
akeys = akeys.replace("%h", pwent.pw_dir)
|
||||||
akeys = akeys.replace("%u", user)
|
akeys = akeys.replace("%u", user)
|
||||||
authorized_keys = akeys
|
authorized_keys = akeys
|
||||||
except Exception as e:
|
except Exception:
|
||||||
authorized_keys = '%s/.ssh/authorized_keys' % pwent.pw_dir
|
authorized_keys = '%s/.ssh/authorized_keys' % pwent.pw_dir
|
||||||
if log:
|
if log:
|
||||||
util.logexc(log)
|
util.logexc(log)
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ def do_include(content, appendmsg):
|
|||||||
content = urllib.urlopen(line).read()
|
content = urllib.urlopen(line).read()
|
||||||
if includeonce:
|
if includeonce:
|
||||||
util.write_file(includeonce_filename, content, mode=0600)
|
util.write_file(includeonce_filename, content, mode=0600)
|
||||||
except Exception as e:
|
except Exception:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
process_includes(message_from_string(decomp_str(content)), appendmsg)
|
process_includes(message_from_string(decomp_str(content)), appendmsg)
|
||||||
@@ -190,7 +190,6 @@ def process_includes(msg, appendmsg=None):
|
|||||||
|
|
||||||
def message_from_string(data, headers={}):
|
def message_from_string(data, headers={}):
|
||||||
if "mime-version:" in data[0:4096].lower():
|
if "mime-version:" in data[0:4096].lower():
|
||||||
was_mime = True
|
|
||||||
msg = email.message_from_string(data)
|
msg = email.message_from_string(data)
|
||||||
for (key,val) in headers.items():
|
for (key,val) in headers.items():
|
||||||
if key in msg:
|
if key in msg:
|
||||||
@@ -198,7 +197,6 @@ def message_from_string(data, headers={}):
|
|||||||
else:
|
else:
|
||||||
msg[key] = val
|
msg[key] = val
|
||||||
else:
|
else:
|
||||||
was_mime = False
|
|
||||||
mtype = headers.get("Content-Type","text/plain")
|
mtype = headers.get("Content-Type","text/plain")
|
||||||
maintype, subtype = mtype.split("/", 1)
|
maintype, subtype = mtype.split("/", 1)
|
||||||
msg = MIMEBase(maintype, subtype, *headers)
|
msg = MIMEBase(maintype, subtype, *headers)
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ class CloudInit:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
conf = util.get_base_cfg(self.sysconfig,cfg_builtin, parsed_cfgs)
|
conf = util.get_base_cfg(self.sysconfig,cfg_builtin, parsed_cfgs)
|
||||||
except Exception as e:
|
except Exception:
|
||||||
conf = get_builtin_cfg()
|
conf = get_builtin_cfg()
|
||||||
|
|
||||||
# support reading the old ConfigObj format file and merging
|
# support reading the old ConfigObj format file and merging
|
||||||
@@ -176,7 +176,7 @@ class CloudInit:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
f=open(cache, "wb")
|
f=open(cache, "wb")
|
||||||
data = cPickle.dump(self.datasource,f)
|
cPickle.dump(self.datasource,f)
|
||||||
f.close()
|
f.close()
|
||||||
os.chmod(cache,0400)
|
os.chmod(cache,0400)
|
||||||
except:
|
except:
|
||||||
@@ -360,7 +360,7 @@ class CloudInit:
|
|||||||
|
|
||||||
# give callbacks opportunity to finalize
|
# give callbacks opportunity to finalize
|
||||||
called = [ ]
|
called = [ ]
|
||||||
for (mtype, mod) in part_handlers.iteritems():
|
for (_mtype, mod) in part_handlers.iteritems():
|
||||||
if mod in called:
|
if mod in called:
|
||||||
continue
|
continue
|
||||||
handler_call_end(mod, data, frequency)
|
handler_call_end(mod, data, frequency)
|
||||||
@@ -425,7 +425,7 @@ class CloudInit:
|
|||||||
try:
|
try:
|
||||||
env=os.environ.copy()
|
env=os.environ.copy()
|
||||||
env['INSTANCE_ID']= self.datasource.get_instance_id()
|
env['INSTANCE_ID']= self.datasource.get_instance_id()
|
||||||
ret = subprocess.check_call([filepath], env=env)
|
subprocess.check_call([filepath], env=env)
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
log.error("boothooks script %s returned %i" %
|
log.error("boothooks script %s returned %i" %
|
||||||
(filepath,e.returncode))
|
(filepath,e.returncode))
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ def netdev_info():
|
|||||||
if toks[i] == "hwaddr":
|
if toks[i] == "hwaddr":
|
||||||
try:
|
try:
|
||||||
devs[curdev]["hwaddr"] = toks[i+1]
|
devs[curdev]["hwaddr"] = toks[i+1]
|
||||||
except IndexError as e:
|
except IndexError:
|
||||||
pass
|
pass
|
||||||
for field in ("addr", "bcast", "mask"):
|
for field in ("addr", "bcast", "mask"):
|
||||||
target = "%s%s" % (field, fieldpost)
|
target = "%s%s" % (field, fieldpost)
|
||||||
@@ -33,7 +33,7 @@ def netdev_info():
|
|||||||
if toks[i] == "%s:" % field:
|
if toks[i] == "%s:" % field:
|
||||||
try:
|
try:
|
||||||
devs[curdev][target] = toks[i+1]
|
devs[curdev][target] = toks[i+1]
|
||||||
except IndexError as e:
|
except IndexError:
|
||||||
pass
|
pass
|
||||||
elif toks[i].startswith("%s:" % field):
|
elif toks[i].startswith("%s:" % field):
|
||||||
devs[curdev][target] = toks[i][len(field)+1:]
|
devs[curdev][target] = toks[i][len(field)+1:]
|
||||||
@@ -61,7 +61,7 @@ def debug_info(pre="ci-info: "):
|
|||||||
lines = [ ]
|
lines = [ ]
|
||||||
try:
|
try:
|
||||||
netdev = netdev_info()
|
netdev = netdev_info()
|
||||||
except Exception as e:
|
except Exception:
|
||||||
lines.append("netdev_info failed!")
|
lines.append("netdev_info failed!")
|
||||||
netdev = {}
|
netdev = {}
|
||||||
for (dev, d) in netdev.iteritems():
|
for (dev, d) in netdev.iteritems():
|
||||||
@@ -69,7 +69,7 @@ def debug_info(pre="ci-info: "):
|
|||||||
(pre, dev, d["up"], d["addr"],d["mask"], d["hwaddr"]))
|
(pre, dev, d["up"], d["addr"],d["mask"], d["hwaddr"]))
|
||||||
try:
|
try:
|
||||||
routes = route_info()
|
routes = route_info()
|
||||||
except Exception as e:
|
except Exception:
|
||||||
lines.append("route_info failed")
|
lines.append("route_info failed")
|
||||||
routes = []
|
routes = []
|
||||||
n = 0
|
n = 0
|
||||||
|
|||||||
@@ -264,7 +264,6 @@ def read_file_with_includes(fname, rel = ".", stack=[], patt = None):
|
|||||||
stack.append(fname)
|
stack.append(fname)
|
||||||
|
|
||||||
cur = 0
|
cur = 0
|
||||||
clen = len(contents)
|
|
||||||
while True:
|
while True:
|
||||||
match = patt.search(contents[cur:])
|
match = patt.search(contents[cur:])
|
||||||
if not match: break
|
if not match: break
|
||||||
@@ -443,7 +442,7 @@ def islxc():
|
|||||||
# we're inside a container. otherwise, no
|
# we're inside a container. otherwise, no
|
||||||
sp = subprocess.Popen(['lxc-is-container'], stdout=subprocess.PIPE,
|
sp = subprocess.Popen(['lxc-is-container'], stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE)
|
stderr=subprocess.PIPE)
|
||||||
out,err = sp.communicate(None)
|
sp.communicate(None)
|
||||||
return(sp.returncode == 0)
|
return(sp.returncode == 0)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
if e.errno != errno.ENOENT:
|
if e.errno != errno.ENOENT:
|
||||||
@@ -507,7 +506,7 @@ def is_resolvable(name):
|
|||||||
try:
|
try:
|
||||||
socket.getaddrinfo(name, None)
|
socket.getaddrinfo(name, None)
|
||||||
return True
|
return True
|
||||||
except socket.gaierror as e:
|
except socket.gaierror:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def is_resolvable_url(url):
|
def is_resolvable_url(url):
|
||||||
@@ -520,7 +519,7 @@ def search_for_mirror(candidates):
|
|||||||
try:
|
try:
|
||||||
if is_resolvable_url(cand):
|
if is_resolvable_url(cand):
|
||||||
return cand
|
return cand
|
||||||
except Exception as e:
|
except Exception:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|||||||
Reference in New Issue
Block a user