summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorScott Moser <smoser@brickies.net>2016-08-23 16:48:40 -0400
committerScott Moser <smoser@brickies.net>2016-08-23 16:48:40 -0400
commit24365490c58df8f0ef2246838c81ec604f0311ac (patch)
tree3a6e44277256d15bb215cef3c61799397a673e6e /bin
parentf16b906c987c7a7948c9adad8f32c1f786ca6569 (diff)
parent18bf614ca1d9fbabdf83495e7675a2cacaf6c2f4 (diff)
downloadvyos-cloud-init-24365490c58df8f0ef2246838c81ec604f0311ac.tar.gz
vyos-cloud-init-24365490c58df8f0ef2246838c81ec604f0311ac.zip
merge trunk at 0.7.7~bzr1189
Diffstat (limited to 'bin')
-rwxr-xr-xbin/cloud-init39
1 files changed, 22 insertions, 17 deletions
diff --git a/bin/cloud-init b/bin/cloud-init
index 7f665e7e..341359e3 100755
--- a/bin/cloud-init
+++ b/bin/cloud-init
@@ -212,6 +212,7 @@ def main_init(name, args):
# Stage 4
path_helper = init.paths
if not args.local:
+ existing = "trust"
sys.stderr.write("%s\n" % (netinfo.debug_info()))
LOG.debug(("Checking to see if files that we need already"
" exist from a previous run that would allow us"
@@ -236,21 +237,17 @@ def main_init(name, args):
LOG.debug("Execution continuing, no previous run detected that"
" would allow us to stop early.")
else:
- # The cache is not instance specific, so it has to be purged
- # but we want 'start' to benefit from a cache if
- # a previous start-local populated one...
- manual_clean = util.get_cfg_option_bool(init.cfg,
- 'manual_cache_clean', False)
- if manual_clean:
- LOG.debug("Not purging instance link, manual cleaning enabled")
- init.purge_cache(False)
- else:
- init.purge_cache()
+ existing = "check"
+ if util.get_cfg_option_bool(init.cfg, 'manual_cache_clean', False):
+ existing = "trust"
+
+ init.purge_cache()
# Delete the non-net file as well
util.del_file(os.path.join(path_helper.get_cpath("data"), "no-net"))
+
# Stage 5
try:
- init.fetch()
+ init.fetch(existing=existing)
except sources.DataSourceNotFoundException:
# In the case of 'cloud-init init' without '--local' it is a bit
# more likely that the user would consider it failure if nothing was
@@ -266,6 +263,10 @@ def main_init(name, args):
return (None, [])
else:
return (None, ["No instance datasource found."])
+
+ if args.local:
+ init.apply_network_config()
+
# Stage 6
iid = init.instancify()
LOG.debug("%s will now be targeting instance id: %s", name, iid)
@@ -328,7 +329,7 @@ def main_modules(action_name, args):
init.read_cfg(extract_fns(args))
# Stage 2
try:
- init.fetch()
+ init.fetch(existing="trust")
except sources.DataSourceNotFoundException:
# There was no datasource found, theres nothing to do
msg = ('Can not apply stage %s, no datasource found! Likely bad '
@@ -382,7 +383,7 @@ def main_single(name, args):
init.read_cfg(extract_fns(args))
# Stage 2
try:
- init.fetch()
+ init.fetch(existing="trust")
except sources.DataSourceNotFoundException:
# There was no datasource found,
# that might be bad (or ok) depending on
@@ -435,20 +436,24 @@ def main_single(name, args):
return 0
-def atomic_write_json(path, data):
+def atomic_write_file(path, content, mode='w'):
tf = None
try:
tf = tempfile.NamedTemporaryFile(dir=os.path.dirname(path),
- delete=False)
- tf.write(util.encode_text(json.dumps(data, indent=1) + "\n"))
+ delete=False, mode=mode)
+ tf.write(content)
tf.close()
os.rename(tf.name, path)
except Exception as e:
if tf is not None:
- util.del_file(tf.name)
+ os.unlink(tf.name)
raise e
+def atomic_write_json(path, data):
+ return atomic_write_file(path, json.dumps(data, indent=1) + "\n")
+
+
def status_wrapper(name, args, data_d=None, link_d=None):
if data_d is None:
data_d = os.path.normpath("/var/lib/cloud/data")