Summary: Check network for same DNS name when adding VM to network

Detail: Can't add VM of same name to network where name already exists, will
break DNS in virtual router.

Submittted-by: Brian Angus <blangus@betterservers.com>
Signed-off-by: Marcus Sorensen <marcus@betterservers.com> 1359400901 -0700
This commit is contained in:
Marcus Sorensen 2013-01-28 12:21:41 -07:00
parent ea7fbd6b4f
commit 52c35a89a6

View File

@ -960,9 +960,17 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
if(_networkModel.getNicInNetwork(vmInstance.getId(),network.getId()) != null){ if(_networkModel.getNicInNetwork(vmInstance.getId(),network.getId()) != null){
s_logger.debug(vmInstance + " already in " + network + " going to add another NIC"); 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);
}
}
}
} }
//todo: verify unique hostname in network domain?
NicProfile guestNic = null; NicProfile guestNic = null;
@ -1075,7 +1083,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
} }
//make sure the VM is Running or Stopped //make sure the VM is Running or Stopped
if ((vmInstance.getState() != State.Running) || (vmInstance.getState() != State.Stopped)) { if ((vmInstance.getState() != State.Running) && (vmInstance.getState() != State.Stopped)) {
throw new CloudRuntimeException("refusing to set default " + vmInstance + " is not Running or Stopped"); throw new CloudRuntimeException("refusing to set default " + vmInstance + " is not Running or Stopped");
} }