shwstppr commented on code in PR #11327:
URL: https://github.com/apache/cloudstack/pull/11327#discussion_r2412959628


##########
server/src/main/java/com/cloud/network/as/AutoScaleManagerImpl.java:
##########
@@ -1954,13 +1960,46 @@ public void updateVmDetails(Map<String, String> 
deployParams, Map<String, String
         }
     }
 
-    @Override
-    public String getNextVmHostName(AutoScaleVmGroupVO asGroup) {
+    protected String getTrimmedHostNameForWindows(String name) {
+        String valid = name.replaceAll("[^a-zA-Z0-9-]", "");
+        String hostName = valid.length() > 15 ? valid.substring(valid.length() 
- 15) : valid;
+        if (!hostName.isEmpty() && !Character.isLetter(hostName.charAt(0))) {
+            for (int i = 0; i < hostName.length(); i++) {
+                if (Character.isLetter(hostName.charAt(i))) {
+                    hostName = hostName.charAt(i) + hostName.substring(i + 1);
+                    break;
+                }
+            }
+            if (!Character.isLetter(hostName.charAt(0))) {
+                hostName = hostName.length() < 15 ? "a" + hostName : "a" + 
hostName.substring(1);
+            }
+        }
+        return hostName;
+    }
+
+    protected boolean isWindowsOs(VirtualMachineTemplate template) {
+        GuestOSVO guestOSVO = guestOSDao.findById(template.getGuestOSId());
+        if (guestOSVO == null) {
+            return false;
+        }
+        String osName = StringUtils.firstNonBlank(guestOSVO.getName(), 
guestOSVO.getDisplayName());
+        if (StringUtils.isBlank(osName)) {
+            return false;
+        }
+        return osName.toLowerCase().contains("windows");
+    }
+
+    protected Pair<String, String> 
getNextVmHostAndDisplayName(AutoScaleVmGroupVO asGroup, VirtualMachineTemplate 
template) {
+        boolean isWindows = isWindowsOs(template);
         String vmHostNameSuffix = "-" + asGroup.getNextVmSeq() + "-" +
                 RandomStringUtils.random(VM_HOSTNAME_RANDOM_SUFFIX_LENGTH, 0, 
0, true, false, (char[])null, new SecureRandom()).toLowerCase();
         // Truncate vm group name because max length of vm name is 63
         int subStringLength = Math.min(asGroup.getName().length(), 63 - 
VM_HOSTNAME_PREFIX.length() - vmHostNameSuffix.length());
-        return VM_HOSTNAME_PREFIX + asGroup.getName().substring(0, 
subStringLength) + vmHostNameSuffix;
+        String name = VM_HOSTNAME_PREFIX + asGroup.getName().substring(0, 
subStringLength) + vmHostNameSuffix;
+        if (!isWindows || name.length() <= 15) {

Review Comment:
   Documentation PR is there already 
https://github.com/apache/cloudstack-documentation/pull/575



-- 
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