From 79b59658dfdc0172818c54e3c7149e6ed914a93b Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Fri, 15 Apr 2016 12:16:14 -0400 Subject: only apply networking once per instance This attempts to only apply the networking once per instance by doing so only if the datasource was restored from disk. This will work by default for datasources with a functioning check_instance_id or if the user has set manual_cache_clean to true. --- bin/cloud-init | 4 +++- cloudinit/stages.py | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/bin/cloud-init b/bin/cloud-init index 715be4b5..b449ac95 100755 --- a/bin/cloud-init +++ b/bin/cloud-init @@ -265,7 +265,9 @@ def main_init(name, args): else: return (None, ["No instance datasource found."]) - if args.local: + if args.local and not init.ds_restored: + # if local mode and the datasource was not restored from cache + # (this is not first boot) then apply networking. init.apply_network_config() # Stage 6 diff --git a/cloudinit/stages.py b/cloudinit/stages.py index 3fbb4443..ffb15165 100644 --- a/cloudinit/stages.py +++ b/cloudinit/stages.py @@ -66,6 +66,7 @@ class Init(object): self._distro = None # Changed only when a fetch occurs self.datasource = NULL_DATA_SOURCE + self.ds_restored = False if reporter is None: reporter = events.ReportEventStack( @@ -80,6 +81,7 @@ class Init(object): self._distro = None if reset_ds: self.datasource = NULL_DATA_SOURCE + self.ds_restored = False @property def distro(self): @@ -231,6 +233,8 @@ class Init(object): ds = None else: myrep.description = "no cache found" + + self.ds_restored = bool(ds) LOG.debug(myrep.description) if not ds: -- cgit v1.2.3 From 53931ee132f0d236e3ed1b7fd6e0e0b519f40bda Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Fri, 15 Apr 2016 13:54:05 -0400 Subject: log that you're not applying config --- bin/cloud-init | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/bin/cloud-init b/bin/cloud-init index b449ac95..5857af32 100755 --- a/bin/cloud-init +++ b/bin/cloud-init @@ -265,10 +265,13 @@ def main_init(name, args): else: return (None, ["No instance datasource found."]) - if args.local and not init.ds_restored: - # if local mode and the datasource was not restored from cache - # (this is not first boot) then apply networking. - init.apply_network_config() + if args.local: + if not init.ds_restored: + # if local mode and the datasource was not restored from cache + # (this is not first boot) then apply networking. + init.apply_network_config() + else: + LOG.debug("skipping networking config from restored datasource.") # Stage 6 iid = init.instancify() -- cgit v1.2.3