Updated Branches: refs/heads/master 9e5449c34 -> 6f9d5db0e
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 <mar...@betterservers.com> 1373345338 -0600 Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/6f9d5db0 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/6f9d5db0 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/6f9d5db0 Branch: refs/heads/master Commit: 6f9d5db0e33cdbe26250b48a0a8acaa1d25fd5b9 Parents: 9e5449c Author: Marcus Sorensen <mar...@betterservers.com> Authored: Mon Jul 8 22:48:58 2013 -0600 Committer: Marcus Sorensen <mar...@betterservers.com> Committed: Mon Jul 8 22:48:58 2013 -0600 ---------------------------------------------------------------------- server/src/com/cloud/vm/UserVmManagerImpl.java | 32 ++++++++++++--------- 1 file changed, 19 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6f9d5db0/server/src/com/cloud/vm/UserVmManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index e5faaf1..0486071 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -1833,24 +1833,30 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use private boolean updateUserDataInternal(UserVm vm) throws ResourceUnavailableException, InsufficientCapacityException { VMTemplateVO template = _templateDao.findByIdIncludingRemoved(vm.getTemplateId()); - Nic defaultNic = _networkModel.getDefaultNic(vm.getId()); - if (defaultNic == null) { - s_logger.error("Unable to update userdata for vm id=" + vm.getId() + " as the instance doesn't have default nic"); - return false; + + List<? extends Nic> nics = _nicDao.listByVmId(vm.getId()); + if (nics == null || nics.isEmpty()) { + s_logger.error("unable to find any nics for vm " + vm.getUuid()); + return false; } - Network defaultNetwork = _networkDao.findById(defaultNic.getNetworkId()); - NicProfile defaultNicProfile = new NicProfile(defaultNic, defaultNetwork, null, null, null, - _networkModel.isSecurityGroupSupportedInNetwork(defaultNetwork), - _networkModel.getNetworkTag(template.getHypervisorType(), defaultNetwork)); + for (Nic nic : nics) { + Network network = _networkDao.findById(nic.getNetworkId()); + NicProfile nicProfile = new NicProfile(nic, network, null, null, null, + _networkModel.isSecurityGroupSupportedInNetwork(network), + _networkModel.getNetworkTag(template.getHypervisorType(), network)); - VirtualMachineProfile<VMInstanceVO> vmProfile = new VirtualMachineProfileImpl<VMInstanceVO>((VMInstanceVO)vm); + VirtualMachineProfile<VMInstanceVO> vmProfile = new VirtualMachineProfileImpl<VMInstanceVO>((VMInstanceVO)vm); - UserDataServiceProvider element = _networkModel.getUserDataUpdateProvider(defaultNetwork); - if (element == null) { - throw new CloudRuntimeException("Can't find network element for " + Service.UserData.getName() + " provider needed for UserData update"); + UserDataServiceProvider element = _networkModel.getUserDataUpdateProvider(network); + if (element == null) { + throw new CloudRuntimeException("Can't find network element for " + Service.UserData.getName() + " provider needed for UserData update"); + } + boolean result = element.saveUserData(network, nicProfile, vmProfile); + if (!result) { + s_logger.error("Failed to update userdata for vm " + vm + " and nic " + nic); + } } - boolean result = element.saveUserData(defaultNetwork, defaultNicProfile, vmProfile); return true; }