hsato03 commented on code in PR #10098:
URL: https://github.com/apache/cloudstack/pull/10098#discussion_r3381250229


##########
server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java:
##########
@@ -805,18 +806,49 @@ protected boolean checkVmProfileAndHost(final 
VirtualMachineProfile vmProfile, f
                 return false;
             }
         }
+
+        DetailVO guestOsRule = _hostDetailsDao.findDetail(host.getId(), 
HostVO.GUEST_OS_RULE);
+        if (guestOsRule != null) {
+            return isHostGuestOsCompatible(vmProfile, host, guestOsRule);
+        }
+
+        DetailVO guestOsCategoryId = _hostDetailsDao.findDetail(host.getId(), 
HostVO.GUEST_OS_CATEGORY_ID);
+        if (guestOsCategoryId != null) {
+            return isHostGuestOsCategoryCompatible(vmProfile, host, 
guestOsCategoryId);
+        }
+
+        return true;
+    }
+
+    private boolean isHostGuestOsCategoryCompatible(VirtualMachineProfile 
vmProfile, HostVO host, DetailVO guestOsCategoryId) {
         long guestOSId = vmProfile.getTemplate().getGuestOSId();
         GuestOSVO guestOS = _guestOSDao.findById(guestOSId);
-        if (guestOS != null) {
-            long guestOSCategoryId = guestOS.getCategoryId();
-            DetailVO hostDetail = _hostDetailsDao.findDetail(host.getId(), 
"guest.os.category.id");
-            if (hostDetail != null) {
-                String guestOSCategoryIdString = hostDetail.getValue();
-                if (String.valueOf(guestOSCategoryId) != 
guestOSCategoryIdString) {
-                    logger.debug("The last host has different 
guest.os.category.id than guest os category of VM, skipping");
-                    return false;
-                }
-            }
+
+        if (guestOS == null) {
+            return true;
+        }
+
+        long guestOSCategoryId = guestOS.getCategoryId();
+        String guestOSCategoryIdString = guestOsCategoryId.getValue();
+        if 
(!String.valueOf(guestOSCategoryId).equals(guestOSCategoryIdString)) {
+            logger.debug("The last host has different `{}` than guest os 
category of VM, skipping", Host.GUEST_OS_CATEGORY_ID);
+            return false;
+        }
+
+        return true;
+    }
+
+    private boolean isHostGuestOsCompatible(VirtualMachineProfile vmProfile, 
HostVO host, DetailVO guestOsRule) {
+        VMTemplateVO template = (VMTemplateVO) vmProfile.getTemplate();
+        String templateGuestOSName = 
ApiDBUtils.getTemplateGuestOSName(template);
+
+        List<HostVO> incompatibleHosts = 
_hostDao.findHostsWithGuestOsRulesThatDidNotMatchOsOfGuestVm(templateGuestOSName);
+
+        boolean isIncompatibleHost = 
incompatibleHosts.stream().noneMatch(incompatibleHost -> 
incompatibleHost.getId() == host.getId());

Review Comment:
   The `isIncompatibleHost` variable actually checks if the host is compatible. 
It would be good to rename it or change its value.



##########
ui/public/locales/pt_BR.json:
##########
@@ -1090,6 +1090,8 @@
 "label.guestnetwork": "Rede guest",
 "label.guestnetworkid": "ID de rede",
 "label.guestnetworkname": "Nome da rede",
+"label.guestosasrule": "SO guest como regra JS",
+"label.guestosrule": "Regra SO guest",

Review Comment:
   These labels can also be added to the `en.json` file.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to