X-Git-Url: http://git.annexia.org/?p=mclu.git;a=blobdiff_plain;f=mclu_build.py;h=929f45a3b74bc5b0d8ffdd2403b5d9bca4d13a0d;hp=ce077a657c45e8ce63a0bc8d158759fbc3db4ecc;hb=2a55aedad2ca66ede45f62ca0b55b7e6dddc736f;hpb=8f509fea52826d18df504f18ad0e702f54320f48 diff --git a/mclu_build.py b/mclu_build.py index ce077a6..929f45a 100644 --- a/mclu_build.py +++ b/mclu_build.py @@ -25,6 +25,7 @@ import libvirt import config import lib +import libvirt_xml def cmdline (subparsers): p = subparsers.add_parser ( @@ -61,26 +62,19 @@ def cmdline (subparsers): ) p.set_defaults (run=run) -def run (c, args, nodes): +def run (c, args): # Did the user request a particular node? If not, we'll run it # on any node which is up. m = re.match (r'^(.*):(.*)$', args.name) if m: node_name = m.group (1) vm_name = m.group (2) - if node_name in nodes: - node = nodes[node_name] - if not node.ping (): - sys.exit ("error: requested node (%s) is not up, use mclu wake %s" % - (node_name, node_name)) - else: - sys.exit ("error: requested node (%s) does not exist" % node_name) else: - node = lib.pick_any_node_which_is_up (nodes) + node = lib.pick_any_node_which_is_up (c) vm_name = args.name # Get all the guests, so we can tell if the name is a duplicate. - running, inactive = lib.get_all_guests (c, nodes.values ()) + running, inactive = lib.get_all_guests (c) if vm_name in running or vm_name in inactive: sys.exit ("error: node name (%s) already exists" % vm_name) @@ -105,75 +99,11 @@ def run (c, args, nodes): # Generate the XML. Would be nice to use virt-install here, but # it doesn't work: RHBZ#1095789 - network_model = "virtio" - if not args.virtio: - network_model = "e1000" - - # XXX Quoting, and we should use a real XML generator. - xml = """ - - %s - %d - %d - %d - - hvm - - - - - - - - - - - - - - destroy - restart - restart - - - - - - - - - - - - - -""" % (vm_name, args.memory, args.memory, args.vcpus, network_model) - - # virtio-scsi or IDE disk: - if args.virtio: - xml += """ - - - - - - -""" % output - else: - xml += """ - - - - - -""" % output - - xml += """ - - -""" + xml = libvirt_xml.generate_libvirt_xml (vm_name, + args.memory, + args.vcpus, + args.virtio, + output) # Write the XML to the xmls_dir. fp = open ("%s/%s.xml" % (c['xmls_dir'], vm_name), "w") @@ -181,4 +111,5 @@ def run (c, args, nodes): fp.close () # Start the guest. - lib.start_guest (c, node, vm_name) + lib.start_guest (c, node_name, vm_name) + print "guest built and started on node %s" % node_name