Skip to content
Closed
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
21 changes: 13 additions & 8 deletions server/src/com/cloud/network/element/VirtualRouterElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -775,28 +775,33 @@ public boolean savePassword(final Network network, final NicProfile nic, final V
}

final VirtualMachineProfile uservm = vm;

final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);

// If any router is running then send save password command otherwise
// save the password in DB
if (!network.isRedundant()) {
return networkTopology.savePasswordToRouter(network, nic, uservm, routers.get(0));
}

for (final VirtualRouter router : routers) {
if (router.getState() == State.Running) {
return networkTopology.savePasswordToRouter(network, nic, uservm, router);
}
if (router.getState() == State.Running && router.getRedundantState() == VirtualRouter.RedundantState.MASTER) {
return networkTopology.savePasswordToRouter(network, nic, uservm, router);
}
}
Copy link
Copy Markdown
Contributor

@ustcweizhou ustcweizhou May 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line 781 to line 794 can be more simple like

        for (final VirtualRouter router : routers) {
            if (router.getState() == State.Running && (!router.getIsRedundantRouter() || router.getRedundantState() == RedundantState.MASTER)) {
                return networkTopology.savePasswordToRouter(network, nic, uservm, router);
            }
        }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ustcweizhou
modified this code.

return savePassword(uservm);
}

private boolean savePassword(VirtualMachineProfile uservm) {
//save password
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

save password should be moved to a seperate method, as password should be saved to user_vm_details table if it is not applied to VR, at around line 773.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ustcweizhou
moved this code to a method.

final String password = (String) uservm.getParameter(VirtualMachineProfile.Param.VmPassword);
final String password_encrypted = DBEncryptionUtil.encrypt(password);
final UserVmVO userVmVO = _userVmDao.findById(vm.getId());
final UserVmVO userVmVO = _userVmDao.findById(uservm.getId());

_userVmDao.loadDetails(userVmVO);
userVmVO.setDetail("password", password_encrypted);
_userVmDao.saveDetails(userVmVO);

userVmVO.setUpdateParameters(true);
_userVmDao.update(userVmVO.getId(), userVmVO);

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,17 @@ public class AdvancedNetworkVisitor extends BasicNetworkVisitor {
@Override
public boolean visit(final UserdataPwdRules userdata) throws ResourceUnavailableException {
final VirtualRouter router = userdata.getRouter();

final Commands commands = new Commands(Command.OnError.Stop);
final VirtualMachineProfile profile = userdata.getProfile();
final NicVO nicVo = userdata.getNicVo();
final UserVmVO userVM = userdata.getUserVM();

_commandSetupHelper.createPasswordCommand(router, profile, nicVo, commands);
if (router.getIsRedundantRouter() && router.getVpcId() == null && router.getRedundantState() == VirtualRouter.RedundantState.MASTER) {
_commandSetupHelper.createPasswordCommand(router, profile, nicVo, commands);
}else if (!router.getIsRedundantRouter() || router.getVpcId()!= null){
_commandSetupHelper.createPasswordCommand(router, profile, nicVo, commands);
}

_commandSetupHelper.createVmDataCommand(router, userVM, nicVo, userVM.getDetail("SSH.PublicKey"), commands);

return _networkGeneralHelper.sendCommandsToRouter(router, commands);
Expand Down