vm-import: kvm import and fix volume size when lesser than 1GiB (#8500)

Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
Co-authored-by: Daan Hoogland <daan@onecht.net>
This commit is contained in:
Abhishek Kumar 2024-01-12 18:02:02 +05:30 committed by GitHub
parent a3a4833c3e
commit 3936f7c2cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 12 deletions

View File

@ -153,7 +153,7 @@ public interface VolumeOrchestrationService {
* @param type Type of the volume - ROOT, DATADISK, etc
* @param name Name of the volume
* @param offering DiskOffering for the volume
* @param size DiskOffering for the volume
* @param sizeInBytes size of the volume in bytes
* @param minIops minimum IOPS for the disk, if not passed DiskOffering value will be used
* @param maxIops maximum IOPS for the disk, if not passed DiskOffering value will be used
* @param vm VirtualMachine this volume is attached to
@ -165,7 +165,7 @@ public interface VolumeOrchestrationService {
* @param chainInfo chain info for the volume. Hypervisor specific.
* @return DiskProfile of imported volume
*/
DiskProfile importVolume(Type type, String name, DiskOffering offering, Long size, Long minIops, Long maxIops, VirtualMachine vm, VirtualMachineTemplate template,
DiskProfile importVolume(Type type, String name, DiskOffering offering, Long sizeInBytes, Long minIops, Long maxIops, VirtualMachine vm, VirtualMachineTemplate template,
Account owner, Long deviceId, Long poolId, String path, String chainInfo);
DiskProfile updateImportedVolume(Type type, DiskOffering offering, VirtualMachine vm, VirtualMachineTemplate template,

View File

@ -2172,19 +2172,17 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati
}
@Override
public DiskProfile importVolume(Type type, String name, DiskOffering offering, Long size, Long minIops, Long maxIops,
public DiskProfile importVolume(Type type, String name, DiskOffering offering, Long sizeInBytes, Long minIops, Long maxIops,
VirtualMachine vm, VirtualMachineTemplate template, Account owner,
Long deviceId, Long poolId, String path, String chainInfo) {
if (size == null) {
size = offering.getDiskSize();
} else {
size = (size * 1024 * 1024 * 1024);
if (sizeInBytes == null) {
sizeInBytes = offering.getDiskSize();
}
minIops = minIops != null ? minIops : offering.getMinIops();
maxIops = maxIops != null ? maxIops : offering.getMaxIops();
VolumeVO vol = new VolumeVO(type, name, vm.getDataCenterId(), owner.getDomainId(), owner.getId(), offering.getId(), offering.getProvisioningType(), size, minIops, maxIops, null);
VolumeVO vol = new VolumeVO(type, name, vm.getDataCenterId(), owner.getDomainId(), owner.getId(), offering.getId(), offering.getProvisioningType(), sizeInBytes, minIops, maxIops, null);
if (vm != null) {
vol.setInstanceId(vm.getId());
}

View File

@ -1113,7 +1113,8 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager {
}
allDetails.put(VmDetailConstants.ROOT_DISK_CONTROLLER, rootDisk.getController());
if (cluster.getHypervisorType() == Hypervisor.HypervisorType.KVM && isImportUnmanagedFromSameHypervisor) {
allDetails.put(VmDetailConstants.ROOT_DISK_SIZE, String.valueOf(rootDisk.getCapacity() / Resource.ResourceType.bytesToGiB));
long size = Double.valueOf(Math.ceil((double)rootDisk.getCapacity() / Resource.ResourceType.bytesToGiB)).longValue();
allDetails.put(VmDetailConstants.ROOT_DISK_SIZE, String.valueOf(size));
}
try {
@ -1172,8 +1173,7 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager {
}
DiskOfferingVO diskOffering = diskOfferingDao.findById(serviceOffering.getDiskOfferingId());
diskProfileStoragePoolList.add(importDisk(rootDisk, userVm, cluster, diskOffering, Volume.Type.ROOT, String.format("ROOT-%d", userVm.getId()),
(rootDisk.getCapacity() / Resource.ResourceType.bytesToGiB), minIops, maxIops,
template, owner, null));
rootDisk.getCapacity(), minIops, maxIops, template, owner, null));
long deviceId = 1L;
for (UnmanagedInstanceTO.Disk disk : dataDisks) {
if (disk.getCapacity() == null || disk.getCapacity() == 0) {
@ -1181,7 +1181,7 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager {
}
DiskOffering offering = diskOfferingDao.findById(dataDiskOfferingMap.get(disk.getDiskId()));
diskProfileStoragePoolList.add(importDisk(disk, userVm, cluster, offering, Volume.Type.DATADISK, String.format("DATA-%d-%s", userVm.getId(), disk.getDiskId()),
(disk.getCapacity() / Resource.ResourceType.bytesToGiB), offering.getMinIops(), offering.getMaxIops(),
disk.getCapacity(), offering.getMinIops(), offering.getMaxIops(),
template, owner, deviceId));
deviceId++;
}