Skip to content

Commit b1ddd7c

Browse files
vmware: Fix for mapping guest OS type read from OVF to existing guest OS in C… (#4553)
* Fix for mapping guest OS type read from OVF to existing guest OS in CloudStack database while registering VMware template * Added unit tests to String Utils methods and updated the code * Updated the java doc section * Updated os description logic to keep equals ignore match with guest os display name
1 parent 4617be4 commit b1ddd7c

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

engine/storage/src/main/java/org/apache/cloudstack/storage/image/deployasis/DeployAsIsHelperImpl.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,26 @@ public Long retrieveTemplateGuestOsIdFromGuestOsInfo(long templateId, String gue
167167
hypervisor.toString(), minimumHypervisorVersion);
168168

169169
if (CollectionUtils.isNotEmpty(guestOsMappings)) {
170-
GuestOSHypervisorVO mapping = guestOsMappings.get(0);
171-
return mapping.getGuestOsId();
170+
Long guestOsId = null;
171+
if (guestOsMappings.size() == 1) {
172+
GuestOSHypervisorVO mapping = guestOsMappings.get(0);
173+
guestOsId = mapping.getGuestOsId();
174+
} else {
175+
if (!StringUtils.isEmpty(guestOsDescription)) {
176+
for (GuestOSHypervisorVO guestOSHypervisorVO : guestOsMappings) {
177+
GuestOSVO guestOSVO = guestOSDao.findById(guestOSHypervisorVO.getGuestOsId());
178+
if (guestOsDescription.equalsIgnoreCase(guestOSVO.getDisplayName())) {
179+
guestOsId = guestOSHypervisorVO.getGuestOsId();
180+
break;
181+
}
182+
}
183+
}
184+
if (null == guestOsId) {
185+
GuestOSHypervisorVO mapping = guestOsMappings.get(guestOsMappings.size()-1);
186+
guestOsId = mapping.getGuestOsId();
187+
}
188+
}
189+
return guestOsId;
172190
} else {
173191
throw new CloudRuntimeException("Did not find a guest OS with type " + guestOsType);
174192
}
@@ -301,7 +319,7 @@ private void persistTemplateDeployAsIsInformationTOList(long templateId,
301319
}
302320
String propValue = null;
303321
try {
304-
propValue = getValueFromInformationTO(informationTO);
322+
propValue = getValueFromInformationTO(informationTO);
305323
} catch (RuntimeException re) {
306324
LOGGER.error("gson marshalling of property object fails: " + propKey,re);
307325
} catch (IOException e) {

0 commit comments

Comments
 (0)