summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimeon Simeonov2017-09-12 22:00:48 +0200
committerSimeon Simeonov2017-09-12 22:00:48 +0200
commit7a754f722de1e44865573335b990658b3ff004cc (patch)
tree03cece268261b4636e95a2854c5dac65484b184f
parent822d319d892c5a22cbae3babb5ab5f2edcf3f2d8 (diff)
LVM support added
-rwxr-xr-xcmount.py52
-rwxr-xr-xcumount.py46
2 files changed, 69 insertions, 29 deletions
diff --git a/cmount.py b/cmount.py
index 587c02f..f980dc9 100755
--- a/cmount.py
+++ b/cmount.py
@@ -20,21 +20,43 @@ def main():
20 config_dict = json.load(fp) 20 config_dict = json.load(fp)
21 cstm_error = 'Invalid / nonexistent mapping: {0}'.format(sys.argv[1]) 21 cstm_error = 'Invalid / nonexistent mapping: {0}'.format(sys.argv[1])
22 data = config_dict[sys.argv[1]] 22 data = config_dict[sys.argv[1]]
23 if data.get('type') == 'efile': 23 if data.get('type') == 'lvm':
24 cstm_error = 'Unable to create loop device' 24 if not isinstance(data.get('pv_sources'), dict):
25 data['device'] = subprocess.check_output(['/usr/sbin/losetup', 25 cstm_error = 'Invalid config for lvm-type'
26 '--find', 26 raise Exception()
27 '--show', 27 cstm_error = 'pv_sources error'
28 data['device']]).strip() 28 for device, mapper_name in data['pv_sources'].items():
29 cstm_error = 'system() error' 29 subprocess.check_call(['/sbin/cryptsetup',
30 subprocess.check_call(['/sbin/cryptsetup', 30 'luksOpen',
31 'luksOpen', 31 device,
32 data['device'], 32 mapper_name])
33 data['mapper_name']]) 33 cstm_error = 'lvchange error'
34 arguments = ['/bin/mount', '/dev/mapper/' + data['mapper_name']] 34 subprocess.check_call(['/sbin/lvchange',
35 if data.get('target'): 35 '-a',
36 arguments.append(data['target']) 36 'y',
37 subprocess.check_call(arguments) 37 data['device']])
38 cstm_error = 'mount error'
39 arguments = ['/bin/mount', data['device']]
40 if data.get('target'):
41 arguments.append(data['target'])
42 subprocess.check_call(arguments)
43 else:
44 if data.get('type') == 'efile':
45 cstm_error = 'Unable to create loop device'
46 data['device'] = subprocess.check_output(
47 ['/usr/sbin/losetup',
48 '--find',
49 '--show',
50 data['device']]).strip()
51 cstm_error = 'system() error'
52 subprocess.check_call(['/sbin/cryptsetup',
53 'luksOpen',
54 data['device'],
55 data['mapper_name']])
56 arguments = ['/bin/mount', '/dev/mapper/' + data['mapper_name']]
57 if data.get('target'):
58 arguments.append(data['target'])
59 subprocess.check_call(arguments)
38 except subprocess.CalledProcessError as e: 60 except subprocess.CalledProcessError as e:
39 sys.stderr.write('Execution error: {0}\n'.format(e)) 61 sys.stderr.write('Execution error: {0}\n'.format(e))
40 sys.stderr.flush() 62 sys.stderr.flush()
diff --git a/cumount.py b/cumount.py
index 16aa2f3..e2fb32f 100755
--- a/cumount.py
+++ b/cumount.py
@@ -20,20 +20,38 @@ def main():
20 config_dict = json.load(fp) 20 config_dict = json.load(fp)
21 cstm_error = 'Invalid / nonexistent mapping: {0}'.format(sys.argv[1]) 21 cstm_error = 'Invalid / nonexistent mapping: {0}'.format(sys.argv[1])
22 data = config_dict[sys.argv[1]] 22 data = config_dict[sys.argv[1]]
23 subprocess.check_call(['/bin/umount', 23 if data.get('type') == 'lvm':
24 '/dev/mapper/' + data['mapper_name']]) 24 if not isinstance(data.get('pv_sources'), dict):
25 subprocess.check_call(['/sbin/cryptsetup', 25 cstm_error = 'Invalid config for lvm-type'
26 'luksClose', 26 raise Exception()
27 data['mapper_name']]) 27 cstm_error = 'umount error'
28 if data.get('type') == 'efile': 28 subprocess.check_call(['/bin/umount',
29 cstm_error = 'Unable to destroy loop device' 29 data['device']])
30 loop_device = subprocess.check_output(['/usr/sbin/losetup', 30 cstm_error = 'lvchange error'
31 '--associated', 31 subprocess.check_call(['/sbin/lvchange',
32 data['device']]) 32 '-a',
33 loop_device = loop_device.split(':')[0] 33 'n',
34 subprocess.check_call(['/usr/sbin/losetup', 34 data['device']])
35 '-d', 35 cstm_error = 'pv_sources error'
36 loop_device]) 36 for mapper_name in data['pv_sources'].values():
37 subprocess.check_call(['/sbin/cryptsetup',
38 'luksClose',
39 mapper_name])
40 else:
41 subprocess.check_call(['/bin/umount',
42 '/dev/mapper/' + data['mapper_name']])
43 subprocess.check_call(['/sbin/cryptsetup',
44 'luksClose',
45 data['mapper_name']])
46 if data.get('type') == 'efile':
47 cstm_error = 'Unable to destroy loop device'
48 loop_device = subprocess.check_output(['/usr/sbin/losetup',
49 '--associated',
50 data['device']])
51 loop_device = loop_device.split(':')[0]
52 subprocess.check_call(['/usr/sbin/losetup',
53 '-d',
54 loop_device])
37 except subprocess.CalledProcessError as e: 55 except subprocess.CalledProcessError as e:
38 sys.stderr.write('Execution error: {0}\n'.format(e)) 56 sys.stderr.write('Execution error: {0}\n'.format(e))
39 sys.stderr.flush() 57 sys.stderr.flush()