diff options
author | Joshua Harlow <harlowja@yahoo-inc.com> | 2012-06-11 17:11:46 -0700 |
---|---|---|
committer | Joshua Harlow <harlowja@yahoo-inc.com> | 2012-06-11 17:11:46 -0700 |
commit | 830c54fec367f852b2f4b0caa71849aa621b5377 (patch) | |
tree | ed6b3ddb7680fbc66f949e68048faee4e4601ae9 /cloudinit/helpers.py | |
parent | 6b37d05a4848e00d34c34b4b23a74d9187f29bba (diff) | |
download | vyos-cloud-init-830c54fec367f852b2f4b0caa71849aa621b5377.tar.gz vyos-cloud-init-830c54fec367f852b2f4b0caa71849aa621b5377.zip |
Move paths to here, since it also qualifies.
Diffstat (limited to 'cloudinit/helpers.py')
-rw-r--r-- | cloudinit/helpers.py | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/cloudinit/helpers.py b/cloudinit/helpers.py index cdb8a07e..0bd13c78 100644 --- a/cloudinit/helpers.py +++ b/cloudinit/helpers.py @@ -202,3 +202,66 @@ class ContentHandlers(object): self.registered[t] = mod registered.add(t) return registered + + +class Paths(object): + def __init__(self, sys_info): + self.cloud_dir = sys_info.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 = sys_info.get('upstart_dir') + template_dir = sys_info.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 = { + "handlers": "handlers", + "scripts": "scripts", + "sem": "sem", + "boothooks": "boothooks", + "userdata_raw": "user-data.txt", + "userdata": "user-data.txt.i", + "obj_pkl": "obj.pkl", + "cloud_config": "cloud-config.txt", + "data": "data", + } + # Set when a datasource becomes active + self.datasource = None + + # get_ipath_cur: get the current instance path for an item + def get_ipath_cur(self, name=None): + ipath = self.instance_link + add_on = self.lookups.get(name) + if add_on: + ipath = os.path.join(ipath, add_on) + return ipath + + # get_cpath : get the "clouddir" (/var/lib/cloud/<name>) + # for a name in dirmap + def get_cpath(self, name=None): + cpath = self.cloud_dir + add_on = self.lookups.get(name) + if add_on: + cpath = os.path.join(cpath, add_on) + return cpath + + def _get_ipath(self, name=None): + if not self.datasource: + return None + iid = self.datasource.get_instance_id() + if iid is None: + return None + ipath = os.path.join(self.cloud_dir, 'instances', iid) + add_on = self.lookups.get(name) + if add_on: + ipath = os.path.join(ipath, add_on) + return ipath + + # (/var/lib/cloud/instances/<instance>/<name>) + def get_ipath(self, name=None): + ipath = self._get_ipath(name) + if not ipath: + LOG.warn(("No per instance semaphores available, " + "is there an datasource/iid set?")) + return None + else: + return ipath |