|
20 | 20 | import org.apache.commons.lang3.StringUtils; |
21 | 21 |
|
22 | 22 | import java.util.LinkedHashMap; |
| 23 | +import java.util.List; |
23 | 24 | import java.util.Locale; |
24 | 25 | import java.util.Map; |
25 | 26 | import java.util.Objects; |
26 | 27 | import java.util.Set; |
27 | 28 | 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; |
28 | 34 |
|
29 | 35 | public class Hypervisor { |
30 | 36 | public static class HypervisorType { |
31 | | - public static enum Functionality { |
| 37 | + public enum Functionality { |
32 | 38 | DirectDownloadTemplate, |
33 | | - RootDiskSizeOverride; |
| 39 | + RootDiskSizeOverride, |
| 40 | + VmStorageMigration |
34 | 41 | } |
35 | 42 |
|
36 | 43 | private static final Map<String, HypervisorType> hypervisorTypeMap = new LinkedHashMap<>(); |
37 | 44 | 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)); |
44 | 48 | public static final HypervisorType Hyperv = new HypervisorType("Hyperv"); |
45 | 49 | public static final HypervisorType VirtualBox = new HypervisorType("VirtualBox"); |
46 | 50 | public static final HypervisorType Parralels = new HypervisorType("Parralels"); |
47 | 51 | 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)); |
50 | 53 | public static final HypervisorType Ovm = new HypervisorType("Ovm", ImageFormat.RAW); |
51 | 54 | public static final HypervisorType Ovm3 = new HypervisorType("Ovm3", ImageFormat.RAW); |
52 | 55 | 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)); |
55 | 57 | public static final HypervisorType Any = new HypervisorType("Any"); /*If you don't care about the hypervisor type*/ |
56 | 58 | private final String name; |
57 | 59 | private final ImageFormat imageFormat; |
@@ -99,6 +101,12 @@ public static HypervisorType valueOf(String name) { |
99 | 101 | return hypervisorType; |
100 | 102 | } |
101 | 103 |
|
| 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 | + |
102 | 110 | /** |
103 | 111 | * Returns the display name of a hypervisor type in case the custom hypervisor is used, |
104 | 112 | * using the 'hypervisor.custom.display.name' setting. Otherwise, returns hypervisor name |
|
0 commit comments