mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 20:02:29 +01:00
Validate VM state before the reboot operation (#156)
* Prevent NPE on reboot stopped VM and start VM output with null display name * Upstream PR: apache/cloudstack#6397
This commit is contained in:
parent
de1414138b
commit
dcf68b272e
@ -26,6 +26,8 @@ import javax.persistence.FetchType;
|
||||
import javax.persistence.PrimaryKeyJoinColumn;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.uservm.UserVm;
|
||||
|
||||
@ -141,4 +143,8 @@ public class UserVmVO extends VMInstanceVO implements UserVm {
|
||||
public String getName() {
|
||||
return instanceName;
|
||||
}
|
||||
|
||||
public String getDisplayNameOrHostName() {
|
||||
return StringUtils.isNotBlank(displayName) ? displayName : getHostName();
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,7 +127,7 @@ public class UserVmJoinDaoImpl extends GenericDaoBaseWithTagInformation<UserVmJo
|
||||
userVmResponse.setName(userVm.getName());
|
||||
|
||||
if (userVm.getDisplayName() != null) {
|
||||
userVmResponse.setDisplayName(userVm.getDisplayName());
|
||||
userVmResponse.setDisplayName(userVm.getDisplayName());
|
||||
} else {
|
||||
userVmResponse.setDisplayName(userVm.getName());
|
||||
}
|
||||
|
||||
@ -3132,6 +3132,11 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
||||
throw new InvalidParameterValueException("Unable to find a virtual machine with id " + vmId);
|
||||
}
|
||||
|
||||
if (vmInstance.getState() != State.Running) {
|
||||
throw new InvalidParameterValueException(String.format("The VM %s (%s) is not running, unable to reboot it",
|
||||
vmInstance.getUuid(), vmInstance.getDisplayNameOrHostName()));
|
||||
}
|
||||
|
||||
_accountMgr.checkAccess(caller, null, true, vmInstance);
|
||||
|
||||
checkIfHostOfVMIsInPrepareForMaintenanceState(vmInstance.getHostId(), vmId, "Reboot");
|
||||
@ -5121,8 +5126,9 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
||||
throw new InvalidParameterValueException("unable to find a virtual machine with id " + vmId);
|
||||
}
|
||||
|
||||
if (vm.getState()== State.Running) {
|
||||
throw new InvalidParameterValueException("The virtual machine "+ vm.getUuid()+ " ("+ vm.getDisplayName()+ ") is already running");
|
||||
if (vm.getState() == State.Running) {
|
||||
throw new InvalidParameterValueException(String.format("The virtual machine %s (%s) is already running",
|
||||
vm.getUuid(), vm.getDisplayNameOrHostName()));
|
||||
}
|
||||
|
||||
_accountMgr.checkAccess(callerAccount, null, true, vm);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user