summaryrefslogtreecommitdiff
path: root/cloudinit/helpers.py
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2012-06-19 16:13:29 -0700
committerJoshua Harlow <harlowja@yahoo-inc.com>2012-06-19 16:13:29 -0700
commitf71f1d0a80b79f99fbe3795d250c656efd2eace4 (patch)
tree8ac6acd3a3828c7a1240a4c977fe6ae305b7bca6 /cloudinit/helpers.py
parent51e28788a7f26c112587144b8c2165952d6f3ac7 (diff)
downloadvyos-cloud-init-f71f1d0a80b79f99fbe3795d250c656efd2eace4.tar.gz
vyos-cloud-init-f71f1d0a80b79f99fbe3795d250c656efd2eace4.zip
Initial add of read and write roots, this should cover a large set of cases that use the path object.
1. This basically allows configuration to specify 'read_root' which will be used for read operations, right now just templates and a 'write_root' via config that will be used for non read operations (ie 'var/lib/cloud' operations where most of the writing now happens)
Diffstat (limited to 'cloudinit/helpers.py')
-rw-r--r--cloudinit/helpers.py24
1 files changed, 22 insertions, 2 deletions
diff --git a/cloudinit/helpers.py b/cloudinit/helpers.py
index 3fd819b3..3938e7ee 100644
--- a/cloudinit/helpers.py
+++ b/cloudinit/helpers.py
@@ -206,11 +206,17 @@ class ContentHandlers(object):
class Paths(object):
def __init__(self, path_cfgs, ds=None):
- self.cloud_dir = path_cfgs.get('cloud_dir', '/var/lib/cloud')
+ self.cfgs = path_cfgs
+ # Populate all the initial paths
+ self.cloud_dir = self.join_paths(False,
+ path_cfgs.get('cloud_dir',
+ '/var/lib/cloud'))
self.instance_link = os.path.join(self.cloud_dir, 'instance')
self.boot_finished = os.path.join(self.instance_link, "boot-finished")
self.upstart_conf_d = path_cfgs.get('upstart_dir')
- template_dir = path_cfgs.get('templates_dir', '/etc/cloud/templates/')
+ template_dir = self.join_paths(True,
+ path_cfgs.get('templates_dir',
+ '/etc/cloud/templates/'))
self.template_tpl = os.path.join(template_dir, '%s.tmpl')
self.seed_dir = os.path.join(self.cloud_dir, 'seed')
self.lookups = {
@@ -227,6 +233,20 @@ class Paths(object):
# Set when a datasource becomes active
self.datasource = ds
+ # joins the paths but also appends a read
+ # or write root if available
+ def join_paths(self, read_only, *paths):
+ if read_only:
+ root = self.cfgs.get('read_root', '/')
+ else:
+ root = self.cfgs.get('write_root', '/')
+ if not paths:
+ return root
+ joined = os.path.join(*paths)
+ if root:
+ joined = os.path.join(root, joined.lstrip("/"))
+ return joined
+
# get_ipath_cur: get the current instance path for an item
def get_ipath_cur(self, name=None):
ipath = self.instance_link