From f71f1d0a80b79f99fbe3795d250c656efd2eace4 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Tue, 19 Jun 2012 16:13:29 -0700 Subject: 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) --- cloudinit/helpers.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'cloudinit/helpers.py') 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 -- cgit v1.2.3