summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2017-06-17 12:29:39 +0300
committerLars Wirzenius <liw@liw.fi>2017-06-17 12:29:39 +0300
commit012a088c8c9db83d167025b5a68d58621dda689d (patch)
treebb357a5d848c44a42f59da9c3a78c4f01f19e489
parentc6018d49125b834b8f2157077d4ce68f50339de4 (diff)
downloadvmdb2-012a088c8c9db83d167025b5a68d58621dda689d.tar.gz
Add: mount plugin will mount virtual filesystems
-rw-r--r--vmdb/plugins/mount_plugin.py46
1 files changed, 45 insertions, 1 deletions
diff --git a/vmdb/plugins/mount_plugin.py b/vmdb/plugins/mount_plugin.py
index 5e92705..c563181 100644
--- a/vmdb/plugins/mount_plugin.py
+++ b/vmdb/plugins/mount_plugin.py
@@ -35,10 +35,28 @@ class MountPlugin(cliapp.Plugin):
class MountStepRunner(vmdb.StepRunnerInterface):
+ virtuals = [
+ ['none', '/proc', 'proc'],
+ ['none', '/dev', 'devtmpfs'],
+ ['none', '/dev/pts', 'devpts'],
+ ['none', '/dev/shm', 'tmpfs'],
+ ['none', '/run', 'tmpfs'],
+ ['none', '/run/lock', 'tmpfs'],
+ ['none', '/sys', 'sysfs'],
+ ]
+
def get_required_keys(self):
return ['mount', 'fs-tag']
def run(self, step, settings, state):
+ rootfs = self.mount_rootfs(step, settings, state)
+ self.mount_virtuals(rootfs, state)
+
+ def teardown(self, step, settings, state):
+ self.unmount_virtuals()
+ self.unmount_rootfs(step, settings, state)
+
+ def mount_rootfs(self, step, settings, state):
if not hasattr(state, 'mounts'):
state.mounts = {}
@@ -55,7 +73,9 @@ class MountStepRunner(vmdb.StepRunnerInterface):
vmdb.runcmd(['mount', device, mount_point])
state.mounts[fs_tag] = mount_point
- def teardown(self, step, settings, state):
+ return mount_point
+
+ def unmount_rootfs(self, step, settings, state):
part_tag = step['mount']
device = state.parts[part_tag]
fs_tag = step['fs-tag']
@@ -65,3 +85,27 @@ class MountStepRunner(vmdb.StepRunnerInterface):
'Unmounting {} ({}) from {}'.format(mount_point, fs_tag, device))
vmdb.runcmd(['umount', mount_point])
os.rmdir(mount_point)
+
+ def mount_virtuals(self, rootfs, state):
+ if not hasattr(state, 'virtuals'):
+ state.virtuals = []
+
+ for device, mount_point, fstype in self.virtuals:
+ path = os.path.join(rootfs, './' + mount_point)
+ vmdb.progress(
+ 'Mounting virtual {} ({}) on {}'.format(device, fstype, path))
+ if not os.path.exists(path):
+ os.mkdir(path)
+ vmdb.runcmd(['mount', '-t', fstype, device, path])
+ state.virtuals.append(path)
+ logging.debug('mounted virtuals: %r', state.virtuals)
+
+ def unmount_virtuals(self):
+ logging.debug('unmounting virtuals: %r', state.virtuals)
+ for mount_point in reversed(state.virtuals):
+ vmdb.progress(
+ 'Unmounting virtual {}'.format(mount_point))
+ try:
+ vmdb.runcmd(['umount', mount_point])
+ except cliapp.AppException:
+ vmdb.error('Something went wrong while unmounting. Ignoring.')