cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject git commit: updated refs/heads/4.2 to 87a2a95
Date Fri, 12 Jul 2013 06:25:41 GMT
Updated Branches:
  refs/heads/4.2 e69ebab34 -> 87a2a9544


CLOUDSTACK-3094: Adding a shared network to already deployed VM is failing.

Signed-off-by: Mice Xia <mice_xia@tcloudcomputing.com>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/87a2a954
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/87a2a954
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/87a2a954

Branch: refs/heads/4.2
Commit: 87a2a95445d195e96cde493a577b62a5734a9ec9
Parents: e69ebab
Author: Saksham Srivastava <saksham.srivastava@citrix.com>
Authored: Mon Jul 8 19:50:03 2013 +0530
Committer: Mice Xia <mice_xia@tcloudcomputing.com>
Committed: Fri Jul 12 14:30:40 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/87a2a954/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/87a2a954/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/87a2a954/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());
+                }
             }
         }
 


Mime
View raw message