From 0a35a8120ddacff63127fce9b24e326f104efef0 Mon Sep 17 00:00:00 2001 From: edison Date: Mon, 16 Aug 2010 19:35:08 -0700 Subject: [PATCH] Oh, why there is so many un-compatible libvirt... --- .../computing/LibvirtComputingResource.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java b/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java index 574b3669113..fdc050d7cca 100644 --- a/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java +++ b/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java @@ -1189,10 +1189,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv s_logger.debug(result); return new CreateAnswer(cmd, result); } + + vol = createVolume(primaryPool, tmplVol); - LibvirtStorageVolumeDef volDef = new LibvirtStorageVolumeDef(UUID.randomUUID().toString(), tmplVol.getInfo().capacity, volFormat.QCOW2, tmplVol.getPath(), volFormat.QCOW2); - s_logger.debug(volDef.toString()); - vol = primaryPool.storageVolCreateXML(volDef.toString(), 0); if (vol == null) { return new Answer(cmd, false, " Can't create storage volume on storage pool"); } @@ -3502,6 +3501,22 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv } } + private StorageVol createVolume(StoragePool destPool, StorageVol tmplVol) throws LibvirtException { + if (isCentosHost()) { + LibvirtStorageVolumeDef volDef = new LibvirtStorageVolumeDef(UUID.randomUUID().toString(), tmplVol.getInfo().capacity, volFormat.QCOW2, null, null); + s_logger.debug(volDef.toString()); + StorageVol vol = destPool.storageVolCreateXML(volDef.toString(), 0); + + /*create qcow2 image based on the name*/ + Script.runSimpleBashScript("qemu-img create -f qcow2 -b " + tmplVol.getPath() + " " + vol.getPath() ); + return vol; + } else { + LibvirtStorageVolumeDef volDef = new LibvirtStorageVolumeDef(UUID.randomUUID().toString(), tmplVol.getInfo().capacity, volFormat.QCOW2, tmplVol.getPath(), volFormat.QCOW2); + s_logger.debug(volDef.toString()); + return destPool.storageVolCreateXML(volDef.toString(), 0); + } + } + private StorageVol getVolume(StoragePool pool, String volKey) { StorageVol vol = null; try {