Change node power subcommands.
[mclu.git] / mclu_build.py
index ce077a6..431602b 100644 (file)
@@ -25,6 +25,7 @@ import libvirt
 
 import config
 import lib
+import libvirt_xml
 
 def cmdline (subparsers):
     p = subparsers.add_parser (
@@ -71,7 +72,7 @@ def run (c, args, nodes):
         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" %
+                sys.exit ("error: requested node (%s) is not up, use mclu on %s" %
                           (node_name, node_name))
         else:
             sys.exit ("error: requested node (%s) does not exist" % node_name)
@@ -105,75 +106,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 = """
-<domain type='kvm'>
-  <name>%s</name>
-  <memory unit='MiB'>%d</memory>
-  <currentMemory unit='MiB'>%d</currentMemory>
-  <vcpu>%d</vcpu>
-  <os>
-    <type>hvm</type>
-    <boot dev='hd'/>
-  </os>
-  <features>
-    <acpi/>
-    <apic/>
-    <pae/>
-  </features>
-  <cpu mode='host-model' fallback='allow' />
-  <clock offset='utc'>
-    <timer name='rtc' tickpolicy='catchup'/>
-    <timer name='pit' tickpolicy='delay'/>
-    <timer name='hpet' present='no'/>
-  </clock>
-  <on_poweroff>destroy</on_poweroff>
-  <on_reboot>restart</on_reboot>
-  <on_crash>restart</on_crash>
-  <devices>
-    <interface type='bridge'>
-      <source bridge='br0'/>
-      <model type='%s'/>
-    </interface>
-    <console type='pty'>
-      <target type='virtio' port='0'/>
-    </console>
-    <input type='tablet' bus='usb'/>
-    <input type='mouse' bus='ps2'/>
-    <!-- <input type='keyboard' bus='ps2'/> -->
-    <graphics type='vnc' autoport='yes'/>
-    <video>
-      <model type='cirrus' vram='9216' heads='1'/>
-    </video>
-""" % (vm_name, args.memory, args.memory, args.vcpus, network_model)
-
-    # virtio-scsi or IDE disk:
-    if args.virtio:
-        xml += """
-    <controller type="scsi" index="0" model="virtio-scsi"/>
-    <disk type='file' device='disk'>
-      <driver name='qemu' type='qcow2' cache='none' io='native'/>
-      <source file='%s'/>
-      <target dev='sda' bus='scsi'/>
-    </disk>
-""" % output
-    else:
-        xml += """
-    <disk type='file' device='disk'>
-      <driver name='qemu' type='qcow2' cache='none' io='native'/>
-      <source file='%s'/>
-      <target dev='sda' bus='ide'/>
-    </disk>
-""" % output
-
-    xml += """
-  </devices>
-</domain>
-"""
+    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")
@@ -182,3 +119,4 @@ def run (c, args, nodes):
 
     # Start the guest.
     lib.start_guest (c, node, vm_name)
+    print "guest built and started on node %s" % node.name