summaryrefslogtreecommitdiff
path: root/cloudinit
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2012-06-21 20:14:50 -0700
committerJoshua Harlow <harlowja@yahoo-inc.com>2012-06-21 20:14:50 -0700
commita588b9b966e51c9b9778b0082c8c5b6ab10f2677 (patch)
tree39313f1b07f3f2f01b925f50ed7b5fa35d799655 /cloudinit
parent94bf83b7a66c95eb56d2c286723d7f37c8c3de04 (diff)
downloadvyos-cloud-init-a588b9b966e51c9b9778b0082c8c5b6ab10f2677.tar.gz
vyos-cloud-init-a588b9b966e51c9b9778b0082c8c5b6ab10f2677.zip
1. Go through a single protected get ipath method that will throw if there
is not an active datasource (ie the user has done an out of order call to a function that needs the datasource to exist) 2. Add in a '_get_instance_subdirs' method that can be over-ridden in the future if more subdirs are needed.
Diffstat (limited to 'cloudinit')
-rw-r--r--cloudinit/stages.py26
1 files changed, 20 insertions, 6 deletions
diff --git a/cloudinit/stages.py b/cloudinit/stages.py
index 9f28c2e8..25f13fd4 100644
--- a/cloudinit/stages.py
+++ b/cloudinit/stages.py
@@ -234,15 +234,29 @@ class Init(object):
self.paths.datasource = ds
return ds
+ def _get_instance_subdirs(self):
+ return ['handlers', 'scripts', 'sems']
+
+ def _get_ipath(self, subname=None):
+ # Force a check to see if anything
+ # actually comes back, if not
+ # then a datasource has not been assigned...
+ instance_dir = self.paths.get_ipath(subname)
+ if not instance_dir:
+ raise RuntimeError(("No instance directory is available."
+ " Has a datasource been fetched??"))
+ return instance_dir
+
def _reflect_cur_instance(self):
- # Ensure we are hooked into the right symlink for the current instance
- idir = self.paths.get_ipath()
+ # Remove the old symlink and attach a new one so
+ # that further reads/writes connect into the right location
+ idir = self._get_ipath()
util.del_file(self.paths.instance_link)
util.sym_link(idir, self.paths.instance_link)
# Ensures these dirs exist
dir_list = []
- for d in ["handlers", "scripts", "sem"]:
+ for d in self._get_instance_subdirs():
dir_list.append(os.path.join(idir, d))
util.ensure_dirs(dir_list)
@@ -297,9 +311,9 @@ class Init(object):
def _store_userdata(self):
raw_ud = "%s" % (self.datasource.get_userdata_raw())
- util.write_file(self.paths.get_ipath('userdata_raw'), raw_ud, 0600)
+ util.write_file(self._get_ipath('userdata_raw'), raw_ud, 0600)
processed_ud = "%s" % (self.datasource.get_userdata())
- util.write_file(self.paths.get_ipath('userdata'), processed_ud, 0600)
+ util.write_file(self._get_ipath('userdata'), processed_ud, 0600)
def _default_userdata_handlers(self):
opts = {
@@ -317,7 +331,7 @@ class Init(object):
def consume(self, frequency=PER_INSTANCE):
cdir = self.paths.get_cpath("handlers")
- idir = self.paths.get_ipath("handlers")
+ idir = self._get_ipath("handlers")
# Add the path to the plugins dir to the top of our list for import
# instance dir should be read before cloud-dir