2020import java .util .Date ;
2121import java .util .List ;
2222
23+ import org .apache .cloudstack .utils .CloudStackVersion ;
2324import org .apache .commons .collections .CollectionUtils ;
2425import org .springframework .stereotype .Component ;
2526
27+ import com .cloud .hypervisor .Hypervisor ;
2628import com .cloud .storage .GuestOSHypervisorVO ;
2729import com .cloud .utils .db .Filter ;
2830import com .cloud .utils .db .QueryBuilder ;
@@ -87,8 +89,7 @@ public List<GuestOSHypervisorVO> listByGuestOsId(long guestOsId) {
8789 return listBy (sc );
8890 }
8991
90- @ Override
91- public GuestOSHypervisorVO findByOsIdAndHypervisor (long guestOsId , String hypervisorType , String hypervisorVersion ) {
92+ private GuestOSHypervisorVO findByOsIdAndHypervisorInternal (long guestOsId , String hypervisorType , String hypervisorVersion ) {
9293 SearchCriteria <GuestOSHypervisorVO > sc = mappingSearch .create ();
9394 String version = "default" ;
9495 if (!(hypervisorVersion == null || hypervisorVersion .isEmpty ())) {
@@ -100,6 +101,19 @@ public GuestOSHypervisorVO findByOsIdAndHypervisor(long guestOsId, String hyperv
100101 return findOneBy (sc );
101102 }
102103
104+ @ Override
105+ public GuestOSHypervisorVO findByOsIdAndHypervisor (long guestOsId , String hypervisorType , String hypervisorVersion ) {
106+ GuestOSHypervisorVO mapping = findByOsIdAndHypervisorInternal (guestOsId , hypervisorType , hypervisorVersion );
107+ if (mapping != null || !Hypervisor .HypervisorType .VMware .toString ().equals (hypervisorType )) {
108+ return mapping ;
109+ }
110+ String parentVersion = CloudStackVersion .getVMwareParentVersion (hypervisorVersion );
111+ if (parentVersion == null ) {
112+ return null ;
113+ }
114+ return findByOsIdAndHypervisorInternal (guestOsId , hypervisorType , parentVersion );
115+ }
116+
103117 @ Override
104118 public GuestOSHypervisorVO findByOsIdAndHypervisorAndUserDefined (long guestOsId , String hypervisorType , String hypervisorVersion , boolean isUserDefined ) {
105119 SearchCriteria <GuestOSHypervisorVO > sc = userDefinedMappingSearch .create ();
@@ -123,8 +137,7 @@ public boolean removeGuestOsMapping(Long id) {
123137 return super .remove (id );
124138 }
125139
126- @ Override
127- public GuestOSHypervisorVO findByOsNameAndHypervisor (String guestOsName , String hypervisorType , String hypervisorVersion ) {
140+ private GuestOSHypervisorVO findByOsNameAndHypervisorInternal (String guestOsName , String hypervisorType , String hypervisorVersion ) {
128141 SearchCriteria <GuestOSHypervisorVO > sc = guestOsNameSearch .create ();
129142 String version = "default" ;
130143 if (!(hypervisorVersion == null || hypervisorVersion .isEmpty ())) {
@@ -138,6 +151,19 @@ public GuestOSHypervisorVO findByOsNameAndHypervisor(String guestOsName, String
138151 return CollectionUtils .isNotEmpty (results ) ? results .get (0 ) : null ;
139152 }
140153
154+ @ Override
155+ public GuestOSHypervisorVO findByOsNameAndHypervisor (String guestOsName , String hypervisorType , String hypervisorVersion ) {
156+ GuestOSHypervisorVO mapping = findByOsNameAndHypervisorInternal (guestOsName , hypervisorType , hypervisorVersion );
157+ if (mapping != null || !Hypervisor .HypervisorType .VMware .toString ().equals (hypervisorType )) {
158+ return mapping ;
159+ }
160+ String parentVersion = CloudStackVersion .getVMwareParentVersion (hypervisorVersion );
161+ if (parentVersion == null ) {
162+ return null ;
163+ }
164+ return findByOsNameAndHypervisorInternal (guestOsName , hypervisorType , parentVersion );
165+ }
166+
141167 @ Override
142168 public GuestOSHypervisorVO findByOsNameAndHypervisorOrderByCreatedDesc (String guestOsName , String hypervisorType , String hypervisorVersion ) {
143169 SearchCriteria <GuestOSHypervisorVO > sc = guestOsNameSearch .create ();
0 commit comments