Skip to content

Commit 4c9ff4c

Browse files
committed
improve
Signed-off-by: Abhishek Kumar <[email protected]>
1 parent 4c9de62 commit 4c9ff4c

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

server/src/main/java/com/cloud/network/as/AutoScaleManagerImpl.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1968,12 +1968,19 @@ protected Pair<String, String> getNextVmHostAndDisplayName(AutoScaleVmGroupVO as
19681968
RandomStringUtils.random(VM_HOSTNAME_RANDOM_SUFFIX_LENGTH, 0, 0, true, false, (char[])null, new SecureRandom()).toLowerCase();
19691969
// Truncate vm group name because max length of vm name is 63
19701970
int subStringLength = Math.min(asGroup.getName().length(), 63 - VM_HOSTNAME_PREFIX.length() - vmHostNameSuffix.length());
1971-
String displayName = VM_HOSTNAME_PREFIX + asGroup.getName().substring(0, subStringLength) + vmHostNameSuffix;
1972-
String hostName = displayName;
1973-
if (isWindows) {
1974-
hostName = displayName.substring(Math.max(0, displayName.length() - 15));
1971+
String name = VM_HOSTNAME_PREFIX + asGroup.getName().substring(0, subStringLength) + vmHostNameSuffix;
1972+
if (!isWindows) {
1973+
return new Pair<>(name, name);
19751974
}
1976-
return new Pair<>(hostName, displayName);
1975+
String hostName = name.substring(Math.max(0, name.length() - 15));
1976+
if (Character.isLetterOrDigit(hostName.charAt(0))) {
1977+
return new Pair<>(hostName, name);
1978+
}
1979+
String temp = name.substring(0, Math.max(0, name.length() - 15)).replaceAll("[^a-zA-Z0-9]", "");
1980+
if (!temp.isEmpty()) {
1981+
return new Pair<>(temp.charAt(temp.length() - 1) + hostName.substring(1), name);
1982+
}
1983+
return new Pair<>('a' + hostName.substring(1), name);
19771984
}
19781985

19791986
@Override

0 commit comments

Comments
 (0)