Updated Branches: refs/heads/add_remove_nics aff919eab -> 89d8a478e
Summary: Don't allow a vm to join a network if another VM of same name exists Submitted-by: Brian Angus <[email protected]> Signed-off-by: Marcus Sorensen <[email protected]> 1359507543 -0700 Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/89d8a478 Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/89d8a478 Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/89d8a478 Branch: refs/heads/add_remove_nics Commit: 89d8a478e0536b73d9028f262c1d3b4f4f34b0ff Parents: aff919e Author: Marcus Sorensen <[email protected]> Authored: Tue Jan 29 17:59:03 2013 -0700 Committer: Marcus Sorensen <[email protected]> Committed: Tue Jan 29 17:59:03 2013 -0700 ---------------------------------------------------------------------- server/src/com/cloud/vm/UserVmManagerImpl.java | 13 +++++-------- 1 files changed, 5 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/89d8a478/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 e00da92..d90b266 100644 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -967,14 +967,11 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager if(_networkModel.getNicInNetwork(vmInstance.getId(),network.getId()) != null){ s_logger.debug(vmInstance + " already in " + network + " going to add another NIC"); } else { - List<NicVO> nics = _nicDao.listByNetworkId(network.getId()); - for (NicVO netnic : nics) { - VMInstanceVO vm = _vmDao.findById(netnic.getInstanceId()); - if (vm != null) { - if (vm.getHostName().equals(vmInstance.getHostName())) { - throw new CloudRuntimeException(network + " already has a vm with host name: '" + vmInstance.getHostName() + "' vmId:" + vm.getId() + " " + vm); - } - } + //* get all vms hostNames in the network + List<String> hostNames = _vmInstanceDao.listDistinctHostNames(network.getId()); + //* verify that there are no duplicates + if (hostNames.contains(vmInstance.getHostName())) { + throw new CloudRuntimeException(network + " already has a vm with host name: '" + vmInstance.getHostName()); } }
