1 #!/usr/bin/env /usr/share/plc_api/plcsh
8 image_types = ['node-iso', 'node-usb', 'generic-iso', 'generic-usb']
10 class boot_node(Test):
12 Attempts to boot the specified node using qemu.
15 def call(self, hostname, image_type = 'node-iso', disk_size="4G"):
19 nodes = GetNodes([hostname], ['hostname'])
21 raise Exception, "No such node %(hostname)s" % locals()
23 bootimage = GetBootMedium(hostname, image_type, '')
24 bootimage_path = '/%(tdir)s/%(hostname)s-bootcd.iso' % locals()
26 if self.config.verbose:
27 utils.header("Creating bootcd for %(hostname)s at %(bootimage_path)s" % locals())
28 # Create a temporary bootcd file
29 file = open(bootimage_path, 'w')
30 file.write(base64.b64decode(bootimage))
33 # Create a temporary disk image
34 diskimage_path = "/%(tdir)s/%(hostname)s-hda.img" % locals()
35 qemu_img_cmd = "qemu-img create -f qcow2 %(diskimage_path)s %(disk_size)s" % locals()
36 (stdin, stdout, stderr) = os.popen3(qemu_img_cmd)
37 self.errors = stderr.readlines()
39 raise Exception, "Unable to create disk image\n" + \
40 "\n".join(self.errors)
42 if self.config.verbose:
43 utils.header("Booting %(hostname)s" % locals())
44 # Attempt to boot this node image
45 bootcmd = "qemu -hda %(diskimage_path)s -cdrom %(bootimage_path)s -smp 1 -m 256 -monitor stdio" % \
47 (stdin, stdout, stderr) = os.popen3(bootcmd)
48 self.errors = stderr.readlines()
50 raise Exception, "Unable to boot node image\n" + \
51 "\n".join(self.errors)
55 if __name__ == '__main__':
56 args = tuple(sys.argv[1:])