From 7629a5dd97aab8ff82fcbe6e5f649afc82b56b7e Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Thu, 6 Aug 2015 15:53:19 -0500 Subject: [PATCH] vmdesc2xml: Command to print libvirt domain XML The `vmdesc2xml` command reads a VM description from a YAML document and prints the generated libvirt domain XML to stdout. This can be useful for debugging or other purposes besides creating VMs directly. --- setup.py | 1 + src/mkvm/vmdesc.py | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/setup.py b/setup.py index 4a0c12c..225ee10 100644 --- a/setup.py +++ b/setup.py @@ -13,6 +13,7 @@ setup( entry_points={ 'console_scripts': [ 'mkvm=mkvm.mkvm:main', + 'vmdesc2xml=mkvm.vmdesc:main', ], }, ) diff --git a/src/mkvm/vmdesc.py b/src/mkvm/vmdesc.py index 86529d5..a42b388 100644 --- a/src/mkvm/vmdesc.py +++ b/src/mkvm/vmdesc.py @@ -1,7 +1,9 @@ from . import storage +import argparse import logging import os import re +import sys import tempfile import yaml try: @@ -400,3 +402,13 @@ class VirtualMachine(object): storage.create_lvm_vg(self.vg_name, *pvs) for vol in self.volumes: storage.create_lvm_lv(self.vg_name, vol['name'], vol['size']) + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('description', + help='Path to VM description document') + args = parser.parse_args() + + vm = VirtualMachine.from_yaml(args.description) + sys.stdout.write(vm.to_xml(True))