Skip to content

Commit bbb7f3e

Browse files
shwstpprweizhouapache
authored andcommitted
improve
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
1 parent 5eff910 commit bbb7f3e

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1979,12 +1979,19 @@ protected Pair<String, String> getNextVmHostAndDisplayName(AutoScaleVmGroupVO as
19791979
RandomStringUtils.random(VM_HOSTNAME_RANDOM_SUFFIX_LENGTH, 0, 0, true, false, (char[])null, new SecureRandom()).toLowerCase();
19801980
// Truncate vm group name because max length of vm name is 63
19811981
int subStringLength = Math.min(asGroup.getName().length(), 63 - VM_HOSTNAME_PREFIX.length() - vmHostNameSuffix.length());
1982-
String displayName = VM_HOSTNAME_PREFIX + asGroup.getName().substring(0, subStringLength) + vmHostNameSuffix;
1983-
String hostName = displayName;
1984-
if (isWindows) {
1985-
hostName = displayName.substring(Math.max(0, displayName.length() - 15));
1982+
String name = VM_HOSTNAME_PREFIX + asGroup.getName().substring(0, subStringLength) + vmHostNameSuffix;
1983+
if (!isWindows) {
1984+
return new Pair<>(name, name);
19861985
}
1987-
return new Pair<>(hostName, displayName);
1986+
String hostName = name.substring(Math.max(0, name.length() - 15));
1987+
if (Character.isLetterOrDigit(hostName.charAt(0))) {
1988+
return new Pair<>(hostName, name);
1989+
}
1990+
String temp = name.substring(0, Math.max(0, name.length() - 15)).replaceAll("[^a-zA-Z0-9]", "");
1991+
if (!temp.isEmpty()) {
1992+
return new Pair<>(temp.charAt(temp.length() - 1) + hostName.substring(1), name);
1993+
}
1994+
return new Pair<>('a' + hostName.substring(1), name);
19881995
}
19891996

19901997
@Override

0 commit comments

Comments
 (0)