summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2017-03-25 20:08:49 +0200
committerLars Wirzenius <liw@liw.fi>2017-03-25 20:08:49 +0200
commit6d035574d6d5d7501168001ee9f4a5a076be12e1 (patch)
tree64d95b5ba3c31ba734fd2bf04734f1a70a606766
parente5e20233ecdc5e4b84a961ccfc0723def7273aa1 (diff)
downloadvmdb2-6d035574d6d5d7501168001ee9f4a5a076be12e1.tar.gz
Add mkimg step
-rw-r--r--vmdb/plugins/mkimg_plugin.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/vmdb/plugins/mkimg_plugin.py b/vmdb/plugins/mkimg_plugin.py
new file mode 100644
index 0000000..274187a
--- /dev/null
+++ b/vmdb/plugins/mkimg_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 MkimgPlugin(cliapp.Plugin):
+
+ def enable(self):
+ self.app.step_runners.add(MkimgStepRunner())
+ self.app.settings.bytesize(
+ ['size'],
+ 'size of output image',
+ default='1GiB')
+
+
+class MkimgStepRunner(vmdb.StepRunnerInterface):
+
+ def get_required_keys(self):
+ return ['mkimg']
+
+ def run(self, step_spec, settings, state):
+ filename = step_spec['mkimg']
+ size = step_spec['size']
+ sys.stdout.write(
+ 'Creating image file {} (size {})\n'.format(filename, size))
+ cliapp.runcmd(
+ ['qemu-img', 'create', '-f', 'raw', filename, size])