summaryrefslogtreecommitdiff
path: root/cloud-init.py
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2011-02-18 15:12:04 -0500
committerScott Moser <smoser@ubuntu.com>2011-02-18 15:12:04 -0500
commitb36409906bb374ea17e5fd3f7e0a9eda93fed4fa (patch)
tree578dcd8e44853da480fc98c9ee55cc70117c00ad /cloud-init.py
parent260ef3428a6c4a4bd148a4d5f1a7488e895f83ee (diff)
downloadvyos-cloud-init-b36409906bb374ea17e5fd3f7e0a9eda93fed4fa.tar.gz
vyos-cloud-init-b36409906bb374ea17e5fd3f7e0a9eda93fed4fa.zip
improve startup if no eth0 is available (LP: #714807)
LP: #714807
Diffstat (limited to 'cloud-init.py')
-rwxr-xr-xcloud-init.py42
1 files changed, 32 insertions, 10 deletions
diff --git a/cloud-init.py b/cloud-init.py
index e8454eaa..3c9df13e 100755
--- a/cloud-init.py
+++ b/cloud-init.py
@@ -27,6 +27,7 @@ import cloudinit.DataSource as ds
import time
import logging
import errno
+import os
def warn(wstr):
sys.stderr.write("WARN:%s" % wstr)
@@ -75,29 +76,50 @@ def main():
except Exception as e:
warn("Failed to get and set output config: %s\n" % e)
- msg = "cloud-init %s running: %s. up %s seconds" % (cmd, now, uptime)
- sys.stderr.write(msg + "\n")
- sys.stderr.flush()
-
cloudinit.logging_set_from_cfg(cfg)
log = logging.getLogger()
- log.info(msg)
try:
cloudinit.initfs()
except Exception as e:
warn("failed to initfs, likely bad things to come: %s\n" % str(e))
-
- # 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
- if cmd == "start-local":
+ nonet_path = "%s/%s" % (cloudinit.get_cpath("data"), "no-net")
+
+ if cmd == "start":
+ stop_files = ( cloudinit.get_ipath_cur("obj_pkl"), nonet_path )
+ # if starting as the network start, there are cases
+ # where everything is already done for us, and it makes
+ # most sense to exit early and silently
+ for f in stop_files:
+ try:
+ fp = open("/var/lib/cloud/instance/obj.pkl","r")
+ fp.close()
+ except:
+ continue
+
+ log.debug("no need for cloud-init start to run (%s)\n", f)
+ sys.exit(0)
+ elif cmd == "start-local":
+ # 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
manclean = util.get_cfg_option_bool(cfg, 'manual_cache_clean',False)
if manclean:
log.debug("not purging cache, manual_cache_clean = True")
cloudinit.purge_cache(not manclean)
+ try:
+ os.unlink(nonet_path)
+ except OSError as e:
+ if e.errno != errno.ENOENT: raise
+
+ msg = "cloud-init %s running: %s. up %s seconds" % (cmd, now, uptime)
+ sys.stderr.write(msg + "\n")
+ sys.stderr.flush()
+
+ log.info(msg)
+
cloud = cloudinit.CloudInit(ds_deps=deps[cmd])
try: