});
for (DiskTO volume : disks) {
KVMPhysicalDisk physicalDisk = null;
KVMStoragePool pool = null;
DataTO data = volume.getData();
if (volume.getType() == Volume.Type.ISO && data.getPath() != null) {
NfsTO nfsStore = (NfsTO)data.getDataStore();
String volPath = nfsStore.getUrl() + File.separator + data.getPath();
int index = volPath.lastIndexOf("/");
String volDir = volPath.substring(0, index);
String volName = volPath.substring(index + 1);
KVMStoragePool secondaryStorage = _storagePoolMgr.
getStoragePoolByURI(volDir);
physicalDisk = secondaryStorage.getPhysicalDisk(volName);
} else if (volume.getType() != Volume.Type.ISO) {
PrimaryDataStoreTO store = (PrimaryDataStoreTO)data.getDataStore();
physicalDisk = _storagePoolMgr.getPhysicalDisk( store.getPoolType(),
store.getUuid(),
data.getPath());
pool = physicalDisk.getPool();
}
String volPath = null;
if (physicalDisk != null) {
volPath = physicalDisk.getPath();
}
DiskDef.diskBus diskBusType = getGuestDiskModel(vmSpec.getOs());
DiskDef disk = new DiskDef();
if (volume.getType() == Volume.Type.ISO) {
if (volPath == null) {
/* Add iso as placeholder */
disk.defISODisk(null);
} else {
disk.defISODisk(volPath);
}
} else {
int devId = volume.getDiskSeq().intValue();
if (pool.getType() == StoragePoolType.RBD) {
/*
For RBD pools we use the secret mechanism in libvirt.
We store the secret under the UUID of the pool, that's why
we pass the pool's UUID as the authSecret
*/
disk.defNetworkBasedDisk(physicalDisk.getPath().replace("rbd:", ""), pool.getSourceHost(), pool.getSourcePort(),
pool.getAuthUserName(), pool.getUuid(),
devId, diskBusType, diskProtocol.RBD);
} else if (pool.getType() == StoragePoolType.CLVM || physicalDisk.getFormat() == PhysicalDiskFormat.RAW) {
disk.defBlockBasedDisk(physicalDisk.getPath(), devId,
diskBusType);
} else {
if (volume.getType() == Volume.Type.DATADISK) {
disk.defFileBasedDisk(physicalDisk.getPath(), devId,
DiskDef.diskBus.VIRTIO,
DiskDef.diskFmtType.QCOW2);
} else {
disk.defFileBasedDisk(physicalDisk.getPath(), devId, diskBusType, DiskDef.diskFmtType.QCOW2);
}
}
}
if (data instanceof VolumeObjectTO) {
VolumeObjectTO volumeObjectTO = (VolumeObjectTO)data;
if ((volumeObjectTO.getBytesReadRate() != null) && (volumeObjectTO.getBytesReadRate() > 0))
disk.setBytesReadRate(volumeObjectTO.getBytesReadRate());
if ((volumeObjectTO.getBytesWriteRate() != null) && (volumeObjectTO.getBytesWriteRate() > 0))
disk.setBytesWriteRate(volumeObjectTO.getBytesWriteRate());
if ((volumeObjectTO.getIopsReadRate() != null) && (volumeObjectTO.getIopsReadRate() > 0))
disk.setIopsReadRate(volumeObjectTO.getIopsReadRate());
if ((volumeObjectTO.getIopsWriteRate() != null) && (volumeObjectTO.getIopsWriteRate() > 0))
disk.setIopsWriteRate(volumeObjectTO.getIopsWriteRate());
}
vm.getDevices().addDevice(disk);
}
if (vmSpec.getType() != VirtualMachine.Type.User) {
if (_sysvmISOPath != null) {
DiskDef iso = new DiskDef();
iso.defISODisk(_sysvmISOPath);
vm.getDevices().addDevice(iso);
}
}
// For LXC, find and add the root filesystem
if (HypervisorType.LXC.toString().toLowerCase().equals(vm.getHvsType())) {
for (DiskTO volume : disks) {
if (volume.getType() == Volume.Type.ROOT) {
DataTO data = volume.getData();
PrimaryDataStoreTO store = (PrimaryDataStoreTO)data.getDataStore();
KVMPhysicalDisk physicalDisk = _storagePoolMgr.getPhysicalDisk( store.getPoolType(),
store.getUuid(),
data.getPath());
FilesystemDef rootFs = new FilesystemDef(physicalDisk.getPath(), "/");
vm.getDevices().addDevice(rootFs);
break;
}
}