You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by mi...@apache.org on 2013/07/12 08:26:03 UTC
git commit: updated refs/heads/master to bdc7e4c
Updated Branches:
refs/heads/master dd9197492 -> bdc7e4ce3
CLOUDSTACK-3094: Adding a shared network to already deployed VM is failing.
Signed-off-by: Mice Xia <mi...@tcloudcomputing.com>
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/bdc7e4ce
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/bdc7e4ce
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/bdc7e4ce
Branch: refs/heads/master
Commit: bdc7e4ce337f2f7cba8320808755119a835de07c
Parents: dd91974
Author: Saksham Srivastava <sa...@citrix.com>
Authored: Mon Jul 8 19:50:03 2013 +0530
Committer: Mice Xia <mi...@tcloudcomputing.com>
Committed: Fri Jul 12 14:30:10 2013 +0800
----------------------------------------------------------------------
.../src/com/cloud/vm/dao/VMInstanceDao.java | 2 ++
.../src/com/cloud/vm/dao/VMInstanceDaoImpl.java | 12 ++++++++++++
server/src/com/cloud/vm/UserVmManagerImpl.java | 19 +++++++++++--------
3 files changed, 25 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bdc7e4ce/engine/schema/src/com/cloud/vm/dao/VMInstanceDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/vm/dao/VMInstanceDao.java b/engine/schema/src/com/cloud/vm/dao/VMInstanceDao.java
index 830e464..e564052 100644
--- a/engine/schema/src/com/cloud/vm/dao/VMInstanceDao.java
+++ b/engine/schema/src/com/cloud/vm/dao/VMInstanceDao.java
@@ -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);
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bdc7e4ce/engine/schema/src/com/cloud/vm/dao/VMInstanceDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/vm/dao/VMInstanceDaoImpl.java b/engine/schema/src/com/cloud/vm/dao/VMInstanceDaoImpl.java
index ffb1a0b..ec04085 100644
--- a/engine/schema/src/com/cloud/vm/dao/VMInstanceDaoImpl.java
+++ b/engine/schema/src/com/cloud/vm/dao/VMInstanceDaoImpl.java
@@ -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);
@@ -362,6 +367,13 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
}
@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();
vo.setProxyId(proxyId);
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bdc7e4ce/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 f95123e..79e7f5a 100755
--- a/server/src/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/com/cloud/vm/UserVmManagerImpl.java
@@ -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());
+ }
}
}