summaryrefslogtreecommitdiff
path: root/cloudinit/util.py
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2011-01-19 18:35:07 +0000
committerScott Moser <smoser@ubuntu.com>2011-01-19 18:35:07 +0000
commitee03480e670c10d48a4825a458fac18aaf4fbec0 (patch)
treeeebc82706725efaa70eb9267791bb03f30c47678 /cloudinit/util.py
parent32eab86a04f4f6056b200e1cfac99ec0495cd5c0 (diff)
downloadvyos-cloud-init-ee03480e670c10d48a4825a458fac18aaf4fbec0.tar.gz
vyos-cloud-init-ee03480e670c10d48a4825a458fac18aaf4fbec0.zip
initial /var/lib rework still lots to do. includes a fix for LP: #704509
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)