|
23 | 23 | import java.util.Locale; |
24 | 24 | import java.util.Map; |
25 | 25 | import java.util.Objects; |
| 26 | +import java.util.Set; |
| 27 | +import java.util.EnumSet; |
26 | 28 |
|
27 | 29 | public class Hypervisor { |
28 | 30 | public static class HypervisorType { |
| 31 | + public static enum Functionality { |
| 32 | + DirectDownloadTemplate, |
| 33 | + RootDiskSizeOverride; |
| 34 | + } |
| 35 | + |
29 | 36 | private static final Map<String, HypervisorType> hypervisorTypeMap = new LinkedHashMap<>(); |
30 | 37 | public static final HypervisorType None = new HypervisorType("None"); //for storage hosts |
31 | | - public static final HypervisorType XenServer = new HypervisorType("XenServer", ImageFormat.VHD); |
32 | | - public static final HypervisorType KVM = new HypervisorType("KVM", ImageFormat.QCOW2); |
33 | | - public static final HypervisorType VMware = new HypervisorType("VMware", ImageFormat.OVA); |
| 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)); |
34 | 44 | public static final HypervisorType Hyperv = new HypervisorType("Hyperv"); |
35 | 45 | public static final HypervisorType VirtualBox = new HypervisorType("VirtualBox"); |
36 | 46 | public static final HypervisorType Parralels = new HypervisorType("Parralels"); |
37 | 47 | public static final HypervisorType BareMetal = new HypervisorType("BareMetal"); |
38 | | - public static final HypervisorType Simulator = new HypervisorType("Simulator"); |
| 48 | + public static final HypervisorType Simulator = new HypervisorType("Simulator", null, |
| 49 | + EnumSet.of(Functionality.RootDiskSizeOverride)); |
39 | 50 | public static final HypervisorType Ovm = new HypervisorType("Ovm", ImageFormat.RAW); |
40 | 51 | public static final HypervisorType Ovm3 = new HypervisorType("Ovm3", ImageFormat.RAW); |
41 | 52 | public static final HypervisorType LXC = new HypervisorType("LXC"); |
42 | | - public static final HypervisorType Custom = new HypervisorType("Custom"); |
| 53 | + public static final HypervisorType Custom = new HypervisorType("Custom", null, |
| 54 | + EnumSet.of(Functionality.RootDiskSizeOverride)); |
43 | 55 | public static final HypervisorType Any = new HypervisorType("Any"); /*If you don't care about the hypervisor type*/ |
44 | 56 | private final String name; |
45 | 57 | private final ImageFormat imageFormat; |
| 58 | + private final Set<Functionality> supportedFunctionalities; |
46 | 59 |
|
47 | 60 | public HypervisorType(String name) { |
48 | | - this(name, null); |
| 61 | + this(name, null, EnumSet.noneOf(Functionality.class)); |
49 | 62 | } |
50 | 63 |
|
51 | 64 | public HypervisorType(String name, ImageFormat imageFormat) { |
| 65 | + this(name, imageFormat, EnumSet.noneOf(Functionality.class)); |
| 66 | + } |
| 67 | + |
| 68 | + public HypervisorType(String name, ImageFormat imageFormat, Set<Functionality> supportedFunctionalities) { |
52 | 69 | this.name = name; |
53 | 70 | this.imageFormat = imageFormat; |
| 71 | + this.supportedFunctionalities = supportedFunctionalities; |
54 | 72 | if (name.equals("Parralels")){ // typo in the original code |
55 | 73 | hypervisorTypeMap.put("parallels", this); |
56 | 74 | } else { |
@@ -102,6 +120,15 @@ public String name() { |
102 | 120 | return name; |
103 | 121 | } |
104 | 122 |
|
| 123 | + /** |
| 124 | + * Make this method to be part of the properties of the hypervisor type itself. |
| 125 | + * |
| 126 | + * @return true if the hypervisor plugin support the specified functionality |
| 127 | + */ |
| 128 | + public boolean isFunctionalitySupported(Functionality functionality) { |
| 129 | + return supportedFunctionalities.contains(functionality); |
| 130 | + } |
| 131 | + |
105 | 132 | @Override |
106 | 133 | public int hashCode() { |
107 | 134 | return Objects.hash(name); |
|
0 commit comments