Skip to content
Open
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
2 changes: 1 addition & 1 deletion api/src/main/java/com/cloud/vm/UserVmService.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public interface UserVmService {
* - the command specifying vmId, password
* @return the VM if reset worked successfully, null otherwise
*/
UserVm resetVMPassword(ResetVMPasswordCmd cmd, String password) throws ResourceUnavailableException, InsufficientCapacityException;
UserVm resetVMPassword(ResetVMPasswordCmd cmd) throws ResourceUnavailableException, InsufficientCapacityException;

/**
* Resets the SSH Key of a virtual machine.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
// under the License.
package org.apache.cloudstack.api.command.user.vm;

import org.apache.commons.lang3.StringUtils;

import org.apache.cloudstack.acl.SecurityChecker.AccessType;
import org.apache.cloudstack.api.ACL;
import org.apache.cloudstack.api.APICommand;
Expand Down Expand Up @@ -116,16 +114,8 @@ public Long getApiResourceId() {

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException {
password = getPassword();
UserVm vm = _responseGenerator.findUserVmById(getId());
if (StringUtils.isBlank(password)) {
password = _mgr.generateRandomPassword();
logger.debug(String.format("Resetting VM [%s] password to a randomly generated password.", vm.getUuid()));
} else {
logger.debug(String.format("Resetting VM [%s] password to password defined by user.", vm.getUuid()));
}
CallContext.current().setEventDetails("Vm Id: " + getId());
UserVm result = _userVmService.resetVMPassword(this, password);
UserVm result = _userVmService.resetVMPassword(this);
if (result != null){
UserVmResponse response = _responseGenerator.createUserVmResponse(getResponseView(), "virtualmachine", result).get(0);
response.setResponseName(getCommandName());
Expand Down
12 changes: 10 additions & 2 deletions server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,12 @@
import com.cloud.kubernetes.cluster.KubernetesServiceHelper;
import com.cloud.network.IpAddressManager;
import com.cloud.network.Network;
import com.cloud.network.NetworkService;
import com.cloud.network.Network.GuestType;
import com.cloud.network.Network.IpAddresses;
import com.cloud.network.Network.Provider;
import com.cloud.network.Network.Service;
import com.cloud.network.NetworkModel;
import com.cloud.network.NetworkService;
import com.cloud.network.Networks.TrafficType;
import com.cloud.network.PhysicalNetwork;
import com.cloud.network.as.AutoScaleManager;
Expand Down Expand Up @@ -837,7 +837,7 @@ private void addVmUefiBootOptionsToParams(Map<VirtualMachineProfile.Param, Objec

@Override
@ActionEvent(eventType = EventTypes.EVENT_VM_RESETPASSWORD, eventDescription = "resetting Vm password", async = true)
public UserVm resetVMPassword(ResetVMPasswordCmd cmd, String password) throws ResourceUnavailableException, InsufficientCapacityException {
public UserVm resetVMPassword(ResetVMPasswordCmd cmd) throws ResourceUnavailableException, InsufficientCapacityException {
Account caller = CallContext.current().getCallingAccount();
Long vmId = cmd.getId();
UserVmVO userVm = _vmDao.findById(cmd.getId());
Expand All @@ -847,6 +847,14 @@ public UserVm resetVMPassword(ResetVMPasswordCmd cmd, String password) throws Re
throw new InvalidParameterValueException("unable to find an Instance with id " + cmd.getId());
}

String logSuffix = "password defined by user";
String password = cmd.getPassword();
if (StringUtils.isBlank(password)) {
password = _mgr.generateRandomPassword();
logSuffix = "a randomly generated password";
}
logger.debug("Resetting {} password to {}.", userVm, logSuffix);

_vmDao.loadDetails(userVm);

VMTemplateVO template = _templateDao.findByIdIncludingRemoved(userVm.getTemplateId());
Expand Down
Loading