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.
master
Dustin 2015-08-06 15:53:19 -05:00
parent 9549fd984b
commit 7629a5dd97
2 changed files with 13 additions and 0 deletions

View File

@ -13,6 +13,7 @@ setup(
entry_points={ entry_points={
'console_scripts': [ 'console_scripts': [
'mkvm=mkvm.mkvm:main', 'mkvm=mkvm.mkvm:main',
'vmdesc2xml=mkvm.vmdesc:main',
], ],
}, },
) )

View File

@ -1,7 +1,9 @@
from . import storage from . import storage
import argparse
import logging import logging
import os import os
import re import re
import sys
import tempfile import tempfile
import yaml import yaml
try: try:
@ -400,3 +402,13 @@ class VirtualMachine(object):
storage.create_lvm_vg(self.vg_name, *pvs) storage.create_lvm_vg(self.vg_name, *pvs)
for vol in self.volumes: for vol in self.volumes:
storage.create_lvm_lv(self.vg_name, vol['name'], vol['size']) 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))