Skip to content

Commit d1982db

Browse files
committed
Address comments
1 parent e68bc29 commit d1982db

File tree

2 files changed

+34
-26
lines changed

2 files changed

+34
-26
lines changed

api/src/main/java/com/cloud/hypervisor/Hypervisor.java

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,38 +20,40 @@
2020
import org.apache.commons.lang3.StringUtils;
2121

2222
import java.util.LinkedHashMap;
23+
import java.util.List;
2324
import java.util.Locale;
2425
import java.util.Map;
2526
import java.util.Objects;
2627
import java.util.Set;
2728
import java.util.EnumSet;
29+
import java.util.stream.Collectors;
30+
31+
import static com.cloud.hypervisor.Hypervisor.HypervisorType.Functionality.DirectDownloadTemplate;
32+
import static com.cloud.hypervisor.Hypervisor.HypervisorType.Functionality.RootDiskSizeOverride;
33+
import static com.cloud.hypervisor.Hypervisor.HypervisorType.Functionality.VmStorageMigration;
2834

2935
public class Hypervisor {
3036
public static class HypervisorType {
31-
public static enum Functionality {
37+
public enum Functionality {
3238
DirectDownloadTemplate,
33-
RootDiskSizeOverride;
39+
RootDiskSizeOverride,
40+
VmStorageMigration
3441
}
3542

3643
private static final Map<String, HypervisorType> hypervisorTypeMap = new LinkedHashMap<>();
3744
public static final HypervisorType None = new HypervisorType("None"); //for storage hosts
38-
public static final HypervisorType XenServer = new HypervisorType("XenServer", ImageFormat.VHD,
39-
EnumSet.of(Functionality.RootDiskSizeOverride));
40-
public static final HypervisorType KVM = new HypervisorType("KVM", ImageFormat.QCOW2,
41-
EnumSet.of(Functionality.DirectDownloadTemplate, Functionality.RootDiskSizeOverride));
42-
public static final HypervisorType VMware = new HypervisorType("VMware", ImageFormat.OVA,
43-
EnumSet.of(Functionality.RootDiskSizeOverride));
45+
public static final HypervisorType XenServer = new HypervisorType("XenServer", ImageFormat.VHD, EnumSet.of(RootDiskSizeOverride, VmStorageMigration));
46+
public static final HypervisorType KVM = new HypervisorType("KVM", ImageFormat.QCOW2, EnumSet.of(DirectDownloadTemplate, RootDiskSizeOverride, VmStorageMigration));
47+
public static final HypervisorType VMware = new HypervisorType("VMware", ImageFormat.OVA, EnumSet.of(RootDiskSizeOverride, VmStorageMigration));
4448
public static final HypervisorType Hyperv = new HypervisorType("Hyperv");
4549
public static final HypervisorType VirtualBox = new HypervisorType("VirtualBox");
4650
public static final HypervisorType Parralels = new HypervisorType("Parralels");
4751
public static final HypervisorType BareMetal = new HypervisorType("BareMetal");
48-
public static final HypervisorType Simulator = new HypervisorType("Simulator", null,
49-
EnumSet.of(Functionality.RootDiskSizeOverride));
52+
public static final HypervisorType Simulator = new HypervisorType("Simulator", null, EnumSet.of(RootDiskSizeOverride, VmStorageMigration));
5053
public static final HypervisorType Ovm = new HypervisorType("Ovm", ImageFormat.RAW);
5154
public static final HypervisorType Ovm3 = new HypervisorType("Ovm3", ImageFormat.RAW);
5255
public static final HypervisorType LXC = new HypervisorType("LXC");
53-
public static final HypervisorType Custom = new HypervisorType("Custom", null,
54-
EnumSet.of(Functionality.RootDiskSizeOverride));
56+
public static final HypervisorType Custom = new HypervisorType("Custom", null, EnumSet.of(RootDiskSizeOverride));
5557
public static final HypervisorType Any = new HypervisorType("Any"); /*If you don't care about the hypervisor type*/
5658
private final String name;
5759
private final ImageFormat imageFormat;
@@ -99,6 +101,12 @@ public static HypervisorType valueOf(String name) {
99101
return hypervisorType;
100102
}
101103

104+
public static List<HypervisorType> getListOfHypervisorsSupportingFunctionality(Functionality functionality) {
105+
return hypervisorTypeMap.values().stream()
106+
.filter(hypervisor -> hypervisor.supportedFunctionalities.contains(functionality))
107+
.collect(Collectors.toList());
108+
}
109+
102110
/**
103111
* Returns the display name of a hypervisor type in case the custom hypervisor is used,
104112
* using the 'hypervisor.custom.display.name' setting. Otherwise, returns hypervisor name

server/src/main/java/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -679,15 +679,6 @@ public void setKubernetesServiceHelpers(final List<KubernetesServiceHelper> kube
679679
private static final ConfigKey<Boolean> VmDestroyForcestop = new ConfigKey<Boolean>("Advanced", Boolean.class, "vm.destroy.forcestop", "false",
680680
"On destroy, force-stop takes this value ", true);
681681

682-
public static final List<HypervisorType> VM_STORAGE_MIGRATION_SUPPORTING_HYPERVISORS = new ArrayList<>(Arrays.asList(
683-
HypervisorType.KVM,
684-
HypervisorType.VMware,
685-
HypervisorType.XenServer,
686-
HypervisorType.Simulator
687-
));
688-
689-
private static final List<HypervisorType> HYPERVISORS_THAT_CAN_DO_STORAGE_MIGRATION_ON_NON_USER_VMS = Arrays.asList(HypervisorType.KVM, HypervisorType.VMware);
690-
691682
@Override
692683
public UserVmVO getVirtualMachine(long vmId) {
693684
return _vmDao.findById(vmId);
@@ -6598,9 +6589,15 @@ private VMInstanceVO preVmStorageMigrationCheck(Long vmId) {
65986589
}
65996590

66006591
HypervisorType hypervisorType = vm.getHypervisorType();
6601-
if (vm.getType() != VirtualMachine.Type.User && !HYPERVISORS_THAT_CAN_DO_STORAGE_MIGRATION_ON_NON_USER_VMS.contains(hypervisorType)) {
6602-
throw new InvalidParameterValueException(String.format("Unable to migrate storage of non-user VMs for hypervisor [%s]. Operation only supported for the following"
6603-
+ " hypervisors: [%s].", hypervisorType, HYPERVISORS_THAT_CAN_DO_STORAGE_MIGRATION_ON_NON_USER_VMS));
6592+
if (vm.getType() != VirtualMachine.Type.User &&
6593+
(!hypervisorType.isFunctionalitySupported(HypervisorType.Functionality.VmStorageMigration)
6594+
|| hypervisorType.equals(HypervisorType.XenServer))) {
6595+
6596+
List<HypervisorType> supportedHypervisors = HypervisorType.getListOfHypervisorsSupportingFunctionality(HypervisorType.Functionality.VmStorageMigration)
6597+
.stream().filter(hypervisor -> !hypervisor.equals(HypervisorType.XenServer)).collect(Collectors.toList());
6598+
throw new InvalidParameterValueException(String.format(
6599+
"Unable to migrate storage of non-user VMs for hypervisor [%s]. Operation only supported for the following hypervisors: [%s].",
6600+
hypervisorType, supportedHypervisors));
66046601
}
66056602

66066603
List<VolumeVO> vols = _volsDao.findByInstance(vm.getId());
@@ -7310,8 +7307,11 @@ public VirtualMachine migrateVirtualMachineWithVolume(Long vmId, Host destinatio
73107307
throw new InvalidParameterValueException("Live Migration of GPU enabled VM is not supported");
73117308
}
73127309

7313-
if (!VM_STORAGE_MIGRATION_SUPPORTING_HYPERVISORS.contains(vm.getHypervisorType())) {
7314-
throw new InvalidParameterValueException(String.format("Unsupported hypervisor: %s for VM migration, we support XenServer/VMware/KVM only", vm.getHypervisorType()));
7310+
if (!vm.getHypervisorType().isFunctionalitySupported(HypervisorType.Functionality.VmStorageMigration)) {
7311+
throw new InvalidParameterValueException(
7312+
String.format("Unsupported hypervisor: %s for VM migration, we support [%s] only",
7313+
vm.getHypervisorType(),
7314+
HypervisorType.getListOfHypervisorsSupportingFunctionality(HypervisorType.Functionality.VmStorageMigration)));
73157315
}
73167316

73177317
if (_vmSnapshotDao.findByVm(vmId).size() > 0) {

0 commit comments

Comments
 (0)