diff options
author | Lars Wirzenius <liw@liw.fi> | 2017-03-29 13:38:06 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2017-03-29 13:38:06 +0300 |
commit | 200dd2cc0862e6729e813a7226ca030daeb2a442 (patch) | |
tree | 89f30e5c0d41e735ba00f303ee20f4a668962e7a | |
parent | ca865f806f0040272533167f9152861e7422faf9 (diff) | |
download | vmdb2-200dd2cc0862e6729e813a7226ca030daeb2a442.tar.gz |
Add shell step
-rw-r--r-- | vmdb/plugins/chroot_plugin.py | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/vmdb/plugins/chroot_plugin.py b/vmdb/plugins/chroot_plugin.py index 0252b95..f49af59 100644 --- a/vmdb/plugins/chroot_plugin.py +++ b/vmdb/plugins/chroot_plugin.py @@ -18,6 +18,7 @@ import logging +import os import sys import cliapp @@ -29,6 +30,8 @@ class ChrootPlugin(cliapp.Plugin): def enable(self): self.app.step_runners.add(ChrootStepRunner()) + def enable(self): + self.app.step_runners.add(ShellStepRunner()) class ChrootStepRunner(vmdb.StepRunnerInterface): @@ -38,7 +41,7 @@ class ChrootStepRunner(vmdb.StepRunnerInterface): def run(self, step, settings, state): fs_tag = step['chroot'] - shell= step['shell'] + shell = step['shell'] mount_point = state.mounts[fs_tag] @@ -47,3 +50,21 @@ class ChrootStepRunner(vmdb.StepRunnerInterface): cliapp.runcmd( ['chroot', mount_point, 'sh', '-c', shell], stdout=None, stderr=None) + + +class ShellStepRunner(vmdb.StepRunnerInterface): + + def get_required_keys(self): + return ['shell', 'root-fs'] + + def run(self, step, settings, state): + shell = step['shell'] + fs_tag = step['root-fs'] + + sys.stdout.write( + 'run shell {}\n'.format(' '.join(shell.split('\n')))) + env = dict(os.environ) + env['ROOT'] = state.mounts[fs_tag] + cliapp.runcmd( + ['sh', '-c', shell], + stdout=None, stderr=None, env=env) |