Skip to content

Commit 5142de4

Browse files
author
Marcus Sorensen
committed
Summary: update user data on all networks a VM is connected to
Detail: Get list of all nics and update user data on them, rather than just the default nic for the VM. This makes the results consistent with the password and SSH key metadata. BUG-ID: CLOUDSTACK-3408 Bugfix-for: 4.1.1, 4.2.0 Signed-off-by: Marcus Sorensen <marcus@betterservers.com> 1373345338 -0600
1 parent 7755986 commit 5142de4

1 file changed

Lines changed: 19 additions & 13 deletions

File tree

‎server/src/com/cloud/vm/UserVmManagerImpl.java‎

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2543,24 +2543,30 @@ public UserVm updateVirtualMachine(UpdateVMCmd cmd)
25432543
private boolean updateUserDataInternal(UserVm vm)
25442544
throws ResourceUnavailableException, InsufficientCapacityException {
25452545
VMTemplateVO template = _templateDao.findByIdIncludingRemoved(vm.getTemplateId());
2546-
Nic defaultNic = _networkModel.getDefaultNic(vm.getId());
2547-
if (defaultNic == null) {
2548-
s_logger.error("Unable to update userdata for vm id=" + vm.getId() + " as the instance doesn't have default nic");
2549-
return false;
2546+
2547+
List<? extends Nic> nics = _nicDao.listByVmId(vm.getId());
2548+
if (nics == null || nics.isEmpty()) {
2549+
s_logger.error("unable to find any nics for vm " + vm.getUuid());
2550+
return false;
25502551
}
25512552

2552-
Network defaultNetwork = _networkDao.findById(defaultNic.getNetworkId());
2553-
NicProfile defaultNicProfile = new NicProfile(defaultNic, defaultNetwork, null, null, null,
2554-
_networkModel.isSecurityGroupSupportedInNetwork(defaultNetwork),
2555-
_networkModel.getNetworkTag(template.getHypervisorType(), defaultNetwork));
2553+
for (Nic nic : nics) {
2554+
Network network = _networkDao.findById(nic.getNetworkId());
2555+
NicProfile nicProfile = new NicProfile(nic, network, null, null, null,
2556+
_networkModel.isSecurityGroupSupportedInNetwork(network),
2557+
_networkModel.getNetworkTag(template.getHypervisorType(), network));
25562558

2557-
VirtualMachineProfile<VMInstanceVO> vmProfile = new VirtualMachineProfileImpl<VMInstanceVO>((VMInstanceVO)vm);
2559+
VirtualMachineProfile<VMInstanceVO> vmProfile = new VirtualMachineProfileImpl<VMInstanceVO>((VMInstanceVO)vm);
25582560

2559-
UserDataServiceProvider element = _networkModel.getUserDataUpdateProvider(defaultNetwork);
2560-
if (element == null) {
2561-
throw new CloudRuntimeException("Can't find network element for " + Service.UserData.getName() + " provider needed for UserData update");
2561+
UserDataServiceProvider element = _networkModel.getUserDataUpdateProvider(network);
2562+
if (element == null) {
2563+
throw new CloudRuntimeException("Can't find network element for " + Service.UserData.getName() + " provider needed for UserData update");
2564+
}
2565+
boolean result = element.saveUserData(network, nicProfile, vmProfile);
2566+
if (!result) {
2567+
s_logger.error("Failed to update userdata for vm " + vm + " and nic " + nic);
2568+
}
25622569
}
2563-
boolean result = element.saveUserData(defaultNetwork, defaultNicProfile, vmProfile);
25642570

25652571
return true;
25662572
}

0 commit comments

Comments
 (0)