summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--vmdb/plugins/kpartx.mdwn11
-rw-r--r--vmdb/plugins/kpartx_plugin.py19
-rw-r--r--vmdb/plugins/mount_plugin.py19
3 files changed, 44 insertions, 5 deletions
diff --git a/vmdb/plugins/kpartx.mdwn b/vmdb/plugins/kpartx.mdwn
index 9bb81a7..0074f38 100644
--- a/vmdb/plugins/kpartx.mdwn
+++ b/vmdb/plugins/kpartx.mdwn
@@ -8,6 +8,17 @@ Step keys:
* `kpartx` — REQUIRED; filename of block device with partitions.
+* `tags` — OPTIONAL; list of tags to apply to partitions when re-using
+ an existing image that has already been populated with formatted partitions
+
Example (in the .vmdb file):
+ # typical use
+ - kpartx: "{{ output }}"
+
+ # using an image that already contains partitions containing filesystems
+ # that should be mounted as `/boot` and `/`
- kpartx: "{{ output }}"
+ tags:
+ - boot
+ - root
diff --git a/vmdb/plugins/kpartx_plugin.py b/vmdb/plugins/kpartx_plugin.py
index baa4f54..2432a16 100644
--- a/vmdb/plugins/kpartx_plugin.py
+++ b/vmdb/plugins/kpartx_plugin.py
@@ -28,14 +28,21 @@ class KpartxPlugin(vmdb.Plugin):
class KpartxStepRunner(vmdb.StepRunnerInterface):
def get_key_spec(self):
- return {"kpartx": str}
+ return {"kpartx": str, "tags": []}
def run(self, values, settings, state):
device = values["kpartx"]
- tags = state.tags.get_tags()
+ tags = values["tags"]
+ if not tags:
+ tags = state.tags.get_tags()
+ else:
+ # add the tags defined in the plugin spec
+ for tag in tags:
+ state.tags.append(tag)
+
devs = self.kpartx(device)
for tag, dev in zip(tags, devs):
- vmdb.progress("remembering {} as {}".format(dev, tag))
+ vmdb.progress(f"remembering {dev} as {tag}")
state.tags.set_dev(tag, dev)
def kpartx(self, device):
@@ -78,6 +85,8 @@ class KpartxStepRunner(vmdb.StepRunnerInterface):
loopdev_info = loopdev_info.pop()
if loopdev_info["back-file"] is None:
continue
- vmdb.progress("Loop device {} is still bound to back-file {}, "
- "removing loop device".format(loop_dev, loopdev_info["back-file"]))
+ vmdb.progress(
+ "Loop device {} is still bound to back-file {}, "
+ "removing loop device".format(loop_dev, loopdev_info["back-file"])
+ )
vmdb.runcmd(["losetup", "-d", loop_dev])
diff --git a/vmdb/plugins/mount_plugin.py b/vmdb/plugins/mount_plugin.py
index b8ebcb1..30554b7 100644
--- a/vmdb/plugins/mount_plugin.py
+++ b/vmdb/plugins/mount_plugin.py
@@ -76,6 +76,25 @@ class MountStepRunner(vmdb.StepRunnerInterface):
state.tags.set_builder_mount_point(tag, mount_point, cached=True)
state.tags.set_target_mount_point(tag, dirname)
+ # detect the filesystem and uuid if they are not already known. This
+ # will be the case if the tags were defined via the kpartx plugin,
+ # rather than by the mkfs plugin
+ if not state.tags.get_fstype(tag):
+ fstype = (
+ vmdb.runcmd(["blkid", "-c/dev/null", "-ovalue", "-sTYPE", device])
+ .decode()
+ .strip()
+ )
+ state.tags.set_fstype(tag, fstype)
+ uuid = state.tags.get_fsuuid(tag)
+ if not uuid:
+ uuid = (
+ vmdb.runcmd(["blkid", "-c/dev/null", "-ovalue", "-sUUID", device])
+ .decode()
+ .strip()
+ )
+ state.tags.set_fsuuid(tag, uuid)
+
return mount_point
def unmount_rootfs(self, values, settings, state):