mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
CLOUDSTACK-3094: Adding a shared network to already deployed VM is failing.
Signed-off-by: Mice Xia <mice_xia@tcloudcomputing.com>
This commit is contained in:
parent
dd91974920
commit
bdc7e4ce33
@ -76,6 +76,8 @@ public interface VMInstanceDao extends GenericDao<VMInstanceVO, Long>, StateDao<
|
||||
|
||||
VMInstanceVO findVMByInstanceName(String name);
|
||||
|
||||
VMInstanceVO findVMByHostName(String hostName);
|
||||
|
||||
void updateProxyId(long id, Long proxyId, Date time);
|
||||
|
||||
List<VMInstanceVO> listByHostIdTypes(long hostid, VirtualMachine.Type... types);
|
||||
|
||||
@ -78,6 +78,7 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
|
||||
protected SearchBuilder<VMInstanceVO> HostIdUpTypesSearch;
|
||||
protected SearchBuilder<VMInstanceVO> HostUpSearch;
|
||||
protected SearchBuilder<VMInstanceVO> InstanceNameSearch;
|
||||
protected SearchBuilder<VMInstanceVO> HostNameSearch;
|
||||
protected GenericSearchBuilder<VMInstanceVO, Long> CountVirtualRoutersByAccount;
|
||||
protected GenericSearchBuilder<VMInstanceVO, Long> CountRunningByHost;
|
||||
protected GenericSearchBuilder<VMInstanceVO, Long> CountRunningByAccount;
|
||||
@ -192,6 +193,10 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
|
||||
InstanceNameSearch.and("instanceName", InstanceNameSearch.entity().getInstanceName(), Op.EQ);
|
||||
InstanceNameSearch.done();
|
||||
|
||||
HostNameSearch = createSearchBuilder();
|
||||
HostNameSearch.and("hostName", HostNameSearch.entity().getHostName(), Op.EQ);
|
||||
HostNameSearch.done();
|
||||
|
||||
CountVirtualRoutersByAccount = createSearchBuilder(Long.class);
|
||||
CountVirtualRoutersByAccount.select(null, Func.COUNT, null);
|
||||
CountVirtualRoutersByAccount.and("account", CountVirtualRoutersByAccount.entity().getAccountId(), SearchCriteria.Op.EQ);
|
||||
@ -361,6 +366,13 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
|
||||
return findOneBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VMInstanceVO findVMByHostName(String hostName) {
|
||||
SearchCriteria<VMInstanceVO> sc = HostNameSearch.create();
|
||||
sc.setParameters("hostName", hostName);
|
||||
return findOneBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateProxyId(long id, Long proxyId, Date time) {
|
||||
VMInstanceVO vo = createForUpdate();
|
||||
|
||||
@ -870,14 +870,17 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use
|
||||
throw new CloudRuntimeException(vmInstance + " is in zone:" + vmInstance.getDataCenterId() + " but " + network + " is in zone:" + network.getDataCenterId());
|
||||
}
|
||||
|
||||
if(_networkModel.getNicInNetwork(vmInstance.getId(),network.getId()) != null){
|
||||
s_logger.debug(vmInstance + " already in " + network + " going to add another NIC");
|
||||
} else {
|
||||
//* 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());
|
||||
// Get all vms hostNames in the network
|
||||
List<String> hostNames = _vmInstanceDao.listDistinctHostNames(network.getId());
|
||||
// verify that there are no duplicates, listDistictHostNames could return hostNames even if the NIC
|
||||
//in the network is removed, so also check if the NIC is present and then throw an exception.
|
||||
//This will also check if there are multiple nics of same vm in the network
|
||||
if (hostNames.contains(vmInstance.getHostName())) {
|
||||
for (String hostName : hostNames) {
|
||||
VMInstanceVO vm = _vmInstanceDao.findVMByHostName(hostName);
|
||||
if(_networkModel.getNicInNetwork(vm.getId(),network.getId())!=null && vm.getHostName().equals(vmInstance.getHostName())) {
|
||||
throw new CloudRuntimeException(network + " already has a vm with host name: " + vmInstance.getHostName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user