summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2019-12-26 11:23:47 +0200
committerLars Wirzenius <liw@liw.fi>2019-12-26 18:15:36 +0200
commit456b265412be956761c623f248bc86040be0ddf5 (patch)
tree1751ef319bcd37ba52820f8981f52c5c971950b6
parentf4d4c72b0357ebba48cbe54e46063a1ea51b7680 (diff)
downloadvmdb2-456b265412be956761c623f248bc86040be0ddf5.tar.gz
Fix: handle mode/owner/group as integers in files plugin
Also, refactor how defaults are handled, for clarity and terseness.
-rw-r--r--vmdb/plugins/files_plugin.py57
1 files changed, 9 insertions, 48 deletions
diff --git a/vmdb/plugins/files_plugin.py b/vmdb/plugins/files_plugin.py
index 40dc86c..772443c 100644
--- a/vmdb/plugins/files_plugin.py
+++ b/vmdb/plugins/files_plugin.py
@@ -37,25 +37,12 @@ class CreateFileStepRunner(vmdb.StepRunnerInterface):
root = state.tags.get_mount_point('/')
newfile = step['create-file']
contents = step['contents']
- perm = step.get('perm')
- uid = step.get('uid')
- gid = step.get('gid')
+ perm = step.get('perm', 0o644)
+ uid = step.get('uid', 0)
+ gid = step.get('gid', 0)
filename = '/'.join([root,newfile])
- if perm:
- perm = int(perm, 8)
- else:
- perm = 0o0644
- if uid:
- uid = int(uid)
- else:
- uid = 0
- if gid:
- gid = int(gid)
- else:
- gid = 0
-
logging.info('Creating file %s, uid %d, gid %d, perms %o' % (filename, uid, gid, perm))
fd = open(filename, 'w')
fd.write(contents)
@@ -74,25 +61,12 @@ class CopyFileStepRunner(vmdb.StepRunnerInterface):
root = state.tags.get_mount_point('/')
newfile = step['copy-file']
src = step['src']
- perm = step.get('perm')
- uid = step.get('uid')
- gid = step.get('gid')
+ perm = step.get('perm', 0o644)
+ uid = step.get('uid', 0)
+ gid = step.get('gid', 0)
filename = '/'.join([root,newfile])
- if perm:
- perm = int(perm, 8)
- else:
- perm = 0o0644
- if uid:
- uid = int(uid)
- else:
- uid = 0
- if gid:
- gid = int(gid)
- else:
- gid = 0
-
logging.info(
'Copying file %s to %s, uid %d, gid %d, perms %o' % (
src, filename, uid, gid, perm))
@@ -117,22 +91,9 @@ class CreateDirStepRunner(vmdb.StepRunnerInterface):
root = state.tags.get_mount_point('/')
newdir = step['create-dir']
path = '/'.join([root, newdir])
- perm = step.get('perm')
- uid = step.get('uid')
- gid = step.get('gid')
-
- if perm:
- perm = int(perm, 8)
- else:
- perm = 0o0755
- if uid:
- uid = int(uid)
- else:
- uid = 0
- if gid:
- gid = int(gid)
- else:
- gid = 0
+ perm = step.get('perm', 0o755)
+ uid = step.get('uid', 0)
+ gid = step.get('gid', 0)
logging.info('Creating directory %s, uid %d, gid %d, perms %o' % (path, uid, gid, perm))