Updated Branches: refs/heads/rbd a44e152db -> aafa7c0d7 (forced update)
rbd: Implement creating instance from a template We are now able to create instances from a template deployed onto RBD storage. Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/aafa7c0d Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/aafa7c0d Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/aafa7c0d Branch: refs/heads/rbd Commit: aafa7c0d755704b7d641e4c346555855e58ec6eb Parents: 9371a5f Author: Wido den Hollander <[email protected]> Authored: Mon Jul 2 14:16:22 2012 +0200 Committer: Wido den Hollander <[email protected]> Committed: Mon Jul 2 14:16:22 2012 +0200 ---------------------------------------------------------------------- .../cloud/agent/storage/LibvirtStorageAdaptor.java | 33 +++++++++++---- 1 files changed, 25 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/aafa7c0d/agent/src/com/cloud/agent/storage/LibvirtStorageAdaptor.java ---------------------------------------------------------------------- diff --git a/agent/src/com/cloud/agent/storage/LibvirtStorageAdaptor.java b/agent/src/com/cloud/agent/storage/LibvirtStorageAdaptor.java index 3ce018a..88b5487 100644 --- a/agent/src/com/cloud/agent/storage/LibvirtStorageAdaptor.java +++ b/agent/src/com/cloud/agent/storage/LibvirtStorageAdaptor.java @@ -708,13 +708,13 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { We then create a KVMPhysicalDisk object that we can return */ - if (format == PhysicalDiskFormat.QCOW2) { + if (destPool.getType() != StoragePoolType.RBD) { disk = destPool.createPhysicalDisk(newUuid, format, template.getVirtualSize()); Script.runSimpleBashScript("qemu-img create -f " + template.getFormat() + " -b " + template.getPath() + " " + disk.getPath()); - } else if (format == PhysicalDiskFormat.RAW) { + } else { disk = new KVMPhysicalDisk(destPool.getSourceDir() + "/" + newUuid, newUuid, destPool); disk.setFormat(format); disk.setSize(template.getVirtualSize()); @@ -731,6 +731,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { destPool.getAuthSecret(), disk.getPath())); } else { + template.setFormat(PhysicalDiskFormat.RAW); Script.runSimpleBashScript("qemu-img convert" + " -f " + template.getFormat() + " -O " + format @@ -777,8 +778,24 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { @Override public KVMPhysicalDisk copyPhysicalDisk(KVMPhysicalDisk disk, String name, KVMStoragePool destPool) { - KVMPhysicalDisk newDisk = destPool.createPhysicalDisk(name, - disk.getVirtualSize()); + + /* + With RBD you can't run qemu-img convert with an existing RBD image as destination + qemu-img will exit with the error that the destination already exists. + So for RBD we don't create the image, but let qemu-img do that for us. + + We then create a KVMPhysicalDisk object that we can return + */ + + KVMPhysicalDisk newDisk; + if (destPool.getType() != StoragePoolType.RBD) { + newDisk = destPool.createPhysicalDisk(name, disk.getVirtualSize()); + } else { + newDisk = new KVMPhysicalDisk(destPool.getSourceDir() + "/" + name, name, destPool); + newDisk.setFormat(PhysicalDiskFormat.RAW); + newDisk.setSize(disk.getVirtualSize()); + newDisk.setVirtualSize(disk.getSize()); + } KVMStoragePool srcPool = disk.getPool(); String destPath = newDisk.getPath(); @@ -795,10 +812,10 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { Script.runSimpleBashScript("qemu-img convert -f " + sourceFormat + " -O " + destFormat + " " + sourcePath - + " " + KVMPhysicalDisk.RBDStringBuilder(srcPool.getSourceHost(), - srcPool.getSourcePort(), - srcPool.getAuthUserName(), - srcPool.getAuthSecret(), + + " " + KVMPhysicalDisk.RBDStringBuilder(destPool.getSourceHost(), + destPool.getSourcePort(), + destPool.getAuthUserName(), + destPool.getAuthSecret(), destPath)); } else { Script.runSimpleBashScript("qemu-img convert -f " + sourceFormat
