Summary: Don't allow a vm to join a network if another VM of same name exists

Submitted-by: Brian Angus <brian@betterservers.com>
Signed-off-by: Marcus Sorensen <marcus@betterservers.com> 1359507543 -0700
This commit is contained in:
Marcus Sorensen 2013-01-29 17:59:03 -07:00
parent aff919eab3
commit 89d8a478e0
1 changed files with 5 additions and 8 deletions

View File

@ -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());
}
}