Skip to content

Commit 313e4d4

Browse files
committed
avoid chances of npe if both guestos name and displayname are null
Signed-off-by: Abhishek Kumar <[email protected]>
1 parent 1efc967 commit 313e4d4

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1977,11 +1977,20 @@ protected String getTrimmedHostNameForWindows(String name) {
19771977
return hostName;
19781978
}
19791979

1980-
protected Pair<String, String> getNextVmHostAndDisplayName(AutoScaleVmGroupVO asGroup, VirtualMachineTemplate template) {
1981-
template.getGuestOSId();
1980+
protected boolean isWindowsOs(VirtualMachineTemplate template) {
19821981
GuestOSVO guestOSVO = guestOSDao.findById(template.getGuestOSId());
1983-
String osName = guestOSVO != null ? StringUtils.firstNonBlank(guestOSVO.getName(), guestOSVO.getDisplayName()) : "";
1984-
boolean isWindows = osName.toLowerCase().contains("windows");
1982+
if (guestOSVO == null) {
1983+
return false;
1984+
}
1985+
String osName = StringUtils.firstNonBlank(guestOSVO.getName(), guestOSVO.getDisplayName());
1986+
if (StringUtils.isBlank(osName)) {
1987+
return false;
1988+
}
1989+
return osName.toLowerCase().contains("windows");
1990+
}
1991+
1992+
protected Pair<String, String> getNextVmHostAndDisplayName(AutoScaleVmGroupVO asGroup, VirtualMachineTemplate template) {
1993+
boolean isWindows = isWindowsOs(template);
19851994
String vmHostNameSuffix = "-" + asGroup.getNextVmSeq() + "-" +
19861995
RandomStringUtils.random(VM_HOSTNAME_RANDOM_SUFFIX_LENGTH, 0, 0, true, false, (char[])null, new SecureRandom()).toLowerCase();
19871996
// Truncate vm group name because max length of vm name is 63

0 commit comments

Comments
 (0)