Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions engine/schema/src/main/java/com/cloud/vm/UserVmVO.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.uservm.UserVm;
import org.apache.commons.lang3.StringUtils;

@Entity
@Table(name = "user_vm")
Expand Down Expand Up @@ -141,4 +142,8 @@ public void setUserVmType(String userVmType) {
public String getName() {
return instanceName;
}

public String getDisplayNameOrHostName() {
return StringUtils.isNotBlank(displayName) ? displayName : getHostName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public UserVmResponse newUserVmResponse(ResponseView view, String objectName, Us
userVmResponse.setName(userVm.getName());

if (userVm.getDisplayName() != null) {
userVmResponse.setDisplayName(userVm.getDisplayName());
userVmResponse.setDisplayName(userVm.getDisplayName());
} else {
userVmResponse.setDisplayName(userVm.getName());
}
Expand Down
10 changes: 8 additions & 2 deletions server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -3130,6 +3130,11 @@ public UserVm rebootVirtualMachine(RebootVMCmd cmd) throws InsufficientCapacityE
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");
Expand Down Expand Up @@ -5119,8 +5124,9 @@ public Pair<UserVmVO, Map<VirtualMachineProfile.Param, Object>> startVirtualMach
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);
Expand Down