- with open(temp_vm_file, 'w') as f:
- vm_xml.write(f, pretty_print=True, xml_declaration=True)
+ else:
+ err('No devices!')
+
+ def create_volume(self, pool, name, su, img_type='qcow2'):
+ log('Creating image using Libvirt volumes in pool %s, name: %s' %
+ (pool, name))
+ size, unit = get_size_and_unit(su)
+ if size == None:
+ err('Could not determine size and unit of %s' % s)
+
+ vol_xml = VOL_XML_TEMPLATE.format(name=name, unit=unit, size=size,
+ format_type=img_type)
+ fname = os.path.join(self.temp_dir, '%s_vol.xml' % name)
+ with file(fname, 'w') as f:
+ f.write(vol_xml)
+
+ exec_cmd('virsh vol-create --pool %s %s' % (pool, fname))
+ vol_path = exec_cmd('virsh vol-path --pool %s %s' % (pool, name))
+
+ delete(fname)
+
+ return vol_path
+
+ def create_image(self, disk_path, disk_size):
+ if os.environ.get('LIBVIRT_DEFAULT_URI') == None:
+ exec_cmd('qemu-img create -f qcow2 %s %s' % (disk_path, disk_size))
+ else:
+ pool = DEFAULT_POOL # FIXME
+ name = os.path.basename(disk_path)
+ disk_path = self.create_volume(pool, name, disk_size)
+
+ return disk_path