summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2017-03-28 22:19:03 +0300
committerLars Wirzenius <liw@liw.fi>2017-03-28 22:19:03 +0300
commit5f4aad6e401cde45863feef71e2d79bed501ca70 (patch)
tree068b10347cec30ec9940e86013e0320aecd71f9e
parentffd5543a833201d704753afebf8a9ce0a51cd916 (diff)
downloadvmdb2-5f4aad6e401cde45863feef71e2d79bed501ca70.tar.gz
Create loopback partitions with kpartx, keep in State
-rw-r--r--vmdb/plugins/partition_plugin.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/vmdb/plugins/partition_plugin.py b/vmdb/plugins/partition_plugin.py
index cb0833e..b2412f9 100644
--- a/vmdb/plugins/partition_plugin.py
+++ b/vmdb/plugins/partition_plugin.py
@@ -18,6 +18,7 @@
import logging
+import os
import sys
import cliapp
@@ -43,7 +44,7 @@ class MklabelStepRunner(vmdb.StepRunnerInterface):
sys.stdout.write(
'Creating partition table ({}) on {}\n'.format(label_type, device))
cliapp.runcmd(['parted', device, 'mklabel', label_type], stderr=None)
- state.parts = []
+ state.parts = {}
class MkpartStepRunner(vmdb.StepRunnerInterface):
@@ -56,8 +57,28 @@ class MkpartStepRunner(vmdb.StepRunnerInterface):
device = step_spec['device']
start = step_spec['start']
end = step_spec['end']
+ part_tag = step_spec['part-tag']
sys.stdout.write(
'Creating partition ({}) on {} ({} to {})\n'.format(
part_type, device, start, end))
cliapp.runcmd(['parted', '-s', device, 'mkpart', part_type, start, end])
+
+ cliapp.runcmd(['kpartx', '-d', device])
+ output = cliapp.runcmd(['kpartx', '-asv', device])
+ for line in output.splitlines():
+ print 'kpartx:', line
+ words = line.split()
+ if words[0] == 'add':
+ name = words[2]
+ device_file = '/dev/mapper/{}'.format(name)
+
+ parts = getattr(state, 'parts', {})
+ parts[part_tag] = device_file
+ state.parts = parts
+
+ def teardown(self, step_spec, settings, state):
+ device = step_spec['device']
+ sys.stdout.write(
+ 'Undoing loopback devices for partitions on {}\n'.format(device))
+ cliapp.runcmd(['kpartx', '-d', device])