2020import org .apache .commons .lang3 .StringUtils ;
2121
2222import java .util .LinkedHashMap ;
23+ import java .util .List ;
2324import java .util .Locale ;
2425import java .util .Map ;
2526import java .util .Objects ;
27+ import java .util .Set ;
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 ;
2634
2735public class Hypervisor {
2836 public static class HypervisorType {
37+ public enum Functionality {
38+ DirectDownloadTemplate ,
39+ RootDiskSizeOverride ,
40+ VmStorageMigration
41+ }
42+
2943 private static final Map <String , HypervisorType > hypervisorTypeMap = new LinkedHashMap <>();
3044 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 );
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 ) );
3448 public static final HypervisorType Hyperv = new HypervisorType ("Hyperv" );
3549 public static final HypervisorType VirtualBox = new HypervisorType ("VirtualBox" );
3650 public static final HypervisorType Parralels = new HypervisorType ("Parralels" );
3751 public static final HypervisorType BareMetal = new HypervisorType ("BareMetal" );
38- public static final HypervisorType Simulator = new HypervisorType ("Simulator" );
52+ public static final HypervisorType Simulator = new HypervisorType ("Simulator" , null , EnumSet . of ( RootDiskSizeOverride , VmStorageMigration ) );
3953 public static final HypervisorType Ovm = new HypervisorType ("Ovm" , ImageFormat .RAW );
4054 public static final HypervisorType Ovm3 = new HypervisorType ("Ovm3" , ImageFormat .RAW );
4155 public static final HypervisorType LXC = new HypervisorType ("LXC" );
42- public static final HypervisorType Custom = new HypervisorType ("Custom" );
56+ public static final HypervisorType Custom = new HypervisorType ("Custom" , null , EnumSet . of ( RootDiskSizeOverride ) );
4357 public static final HypervisorType Any = new HypervisorType ("Any" ); /*If you don't care about the hypervisor type*/
4458 private final String name ;
4559 private final ImageFormat imageFormat ;
60+ private final Set <Functionality > supportedFunctionalities ;
4661
4762 public HypervisorType (String name ) {
48- this (name , null );
63+ this (name , null , EnumSet . noneOf ( Functionality . class ) );
4964 }
5065
5166 public HypervisorType (String name , ImageFormat imageFormat ) {
67+ this (name , imageFormat , EnumSet .noneOf (Functionality .class ));
68+ }
69+
70+ public HypervisorType (String name , ImageFormat imageFormat , Set <Functionality > supportedFunctionalities ) {
5271 this .name = name ;
5372 this .imageFormat = imageFormat ;
73+ this .supportedFunctionalities = supportedFunctionalities ;
5474 if (name .equals ("Parralels" )){ // typo in the original code
5575 hypervisorTypeMap .put ("parallels" , this );
5676 } else {
@@ -81,6 +101,12 @@ public static HypervisorType valueOf(String name) {
81101 return hypervisorType ;
82102 }
83103
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+
84110 /**
85111 * Returns the display name of a hypervisor type in case the custom hypervisor is used,
86112 * using the 'hypervisor.custom.display.name' setting. Otherwise, returns hypervisor name
@@ -102,6 +128,15 @@ public String name() {
102128 return name ;
103129 }
104130
131+ /**
132+ * Make this method to be part of the properties of the hypervisor type itself.
133+ *
134+ * @return true if the hypervisor plugin support the specified functionality
135+ */
136+ public boolean isFunctionalitySupported (Functionality functionality ) {
137+ return supportedFunctionalities .contains (functionality );
138+ }
139+
105140 @ Override
106141 public int hashCode () {
107142 return Objects .hash (name );
0 commit comments