summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2017-03-28 22:57:18 +0300
committerLars Wirzenius <liw@liw.fi>2017-03-28 22:57:18 +0300
commit47474ebdaa91b4797e48b25a260fff8ffe04c19f (patch)
treec58bb4521c189650c88c9b35e7b8dbc5d4030324
parentb3391c9c7937beeaf1e3481113e4bd149881577e (diff)
downloadvmdb2-47474ebdaa91b4797e48b25a260fff8ffe04c19f.tar.gz
Add a chroot plugin
-rw-r--r--vmdb/plugins/chroot_plugin.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/vmdb/plugins/chroot_plugin.py b/vmdb/plugins/chroot_plugin.py
new file mode 100644
index 0000000..c8eac68
--- /dev/null
+++ b/vmdb/plugins/chroot_plugin.py
@@ -0,0 +1,49 @@
+# Copyright 2017 Lars Wirzenius
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# =*= License: GPL-3+ =*=
+
+
+
+import logging
+import sys
+
+import cliapp
+
+import vmdb
+
+
+class ChrootPlugin(cliapp.Plugin):
+
+ def enable(self):
+ self.app.step_runners.add(ChrootStepRunner())
+
+
+class ChrootStepRunner(vmdb.StepRunnerInterface):
+
+ def get_required_keys(self):
+ return ['chroot', 'shell']
+
+ def run(self, step_spec, settings, state):
+ fs_tag = step_spec['chroot']
+ shell= step_spec['shell']
+
+ mount_point = state.mounts[fs_tag]
+
+ sys.stdout.write(
+ 'chroot {} to {}\n'.format(mount_point, ' '.join(shell.split('\n'))))
+ cliapp.runcmd(
+ ['chroot', mount_point, 'sh', '-c', shell],
+ stdout=None, stderr=None)