summaryrefslogtreecommitdiff
path: root/cloudinit/util.py
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2011-01-19 16:11:55 -0500
committerScott Moser <smoser@ubuntu.com>2011-01-19 16:11:55 -0500
commit7a187863644c0a5baf2c72c3029621677cbb56c6 (patch)
tree9789fc61a6af27cb3d3d7c6da64193767fccb1d7 /cloudinit/util.py
parent738766778c88bcfe692f8df17f91c4d5c6c90cdd (diff)
parentf2cb6fa249c0f9a17aa8efd27749860622fd8ae1 (diff)
downloadvyos-cloud-init-7a187863644c0a5baf2c72c3029621677cbb56c6.tar.gz
vyos-cloud-init-7a187863644c0a5baf2c72c3029621677cbb56c6.zip
pull in the rework of /var/lib/cloud.
- /var/lib/cloud is redesigned, and its layout now described in doc/var-lib-cloud.txt. The big plus point of this was to get instance specific data into /var/lib/cloud/instances, so that data could easily be purged. A symlink /var/lib/cloud/instance -> /var/lib/cloud/instances/<current_id> is maintained. - Also, now run scripts in /var/lib/cloud/scripts/ per-once per-boot per-instance - bugs addressed: - LP: #704509
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r--cloudinit/util.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py
index d5ae2bec..a2291164 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -278,3 +278,31 @@ def read_cc_from_cmdline(cmdline=None):
begin = cmdline.find(tag_begin, end + end_l)
return('\n'.join(tokens))
+
+def ensure_dirs(dirlist, mode=0755):
+ fixmodes = []
+ for d in dirlist:
+ try:
+ if mode != None:
+ os.makedirs(d)
+ else:
+ os.makedirs(d, mode)
+ except OSError as e:
+ if e.errno != errno.EEXIST: raise
+ if mode != None: fixmodes.append(d)
+
+ for d in fixmodes:
+ os.chmod(d, mode)
+
+def chownbyname(fname,user=None,group=None):
+ uid = -1
+ gid = -1
+ if user == None and group == None: return
+ if user:
+ import pwd
+ uid = pwd.getpwnam(user).pw_uid
+ if group:
+ import grp
+ gid = grp.getgrnam(group).gr_gid
+
+ os.chown(fname,uid,gid)