incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ke4...@apache.org
Subject [21/50] [abbrv] git commit: CS-15073 Nexus vSwitch: Source NAT is being programmed on the wrong nic on the Virtual Router
Date Sun, 27 May 2012 22:35:41 GMT
CS-15073 Nexus vSwitch: Source NAT is being programmed on the wrong nic on the Virtual Router

Reviewed-by: Devdeep


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

Branch: refs/heads/3.0.x
Commit: 484077f4c16fea858e19c33ee9b3909baa81f4f1
Parents: 931d691
Author: Sateesh Chodapuneedi <sateesh.chodapuneedi@citrix.com>
Authored: Fri May 25 18:03:45 2012 +0530
Committer: Sateesh Chodapuneedi <sateesh.chodapuneedi@citrix.com>
Committed: Fri May 25 18:03:45 2012 +0530

----------------------------------------------------------------------
 .../hypervisor/vmware/resource/VmwareResource.java |   45 ++++++++-------
 .../cloud/hypervisor/vmware/mo/DatacenterMO.java   |   20 +++++++
 .../hypervisor/vmware/mo/VirtualMachineMO.java     |   45 +++++++++++----
 3 files changed, 79 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/484077f4/core/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java b/core/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
index 6f0ed5c..1de54a9 100755
--- a/core/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
+++ b/core/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
@@ -811,27 +811,32 @@ public class VmwareResource implements StoragePoolResource, ServerResource,
Vmwa
         // TODO : probably need to set traffic shaping
         Pair<ManagedObjectReference, String> networkInfo = null;
         
-        if(!_nexusVSwitch) {
-        	networkInfo = HypervisorHostHelper.prepareNetwork(this._publicNetworkVSwitchName,
"cloud.public",
-                	vmMo.getRunningHost(), vlanId, null, null, this._ops_timeout, true);
-        }
-        else {
-        	networkInfo = HypervisorHostHelper.prepareNetwork(this._publicNetworkVSwitchName,
"cloud.public",
-                	vmMo.getRunningHost(), vlanId, null, null, this._ops_timeout);
+        if (!_nexusVSwitch) {
+            networkInfo = HypervisorHostHelper.prepareNetwork(this._publicNetworkVSwitchName,
"cloud.public",
+                    vmMo.getRunningHost(), vlanId, null, null, this._ops_timeout, true);
+        } else {
+            networkInfo = HypervisorHostHelper.prepareNetwork(this._publicNetworkVSwitchName,
"cloud.public",
+                    vmMo.getRunningHost(), vlanId, null, null, this._ops_timeout);
         }
-        
+
         int nicIndex = allocPublicNicIndex(vmMo);
-        
+
         try {
-        	VirtualDevice[] nicDevices = vmMo.getNicDevices();
-        	
-        	VirtualEthernetCard device = (VirtualEthernetCard)nicDevices[nicIndex];
-        	
-    		VirtualEthernetCardNetworkBackingInfo nicBacking = new VirtualEthernetCardNetworkBackingInfo();
-    		nicBacking.setDeviceName(networkInfo.second());
-    		nicBacking.setNetwork(networkInfo.first());
-    		device.setBacking(nicBacking);
-        	
+            VirtualDevice[] nicDevices = vmMo.getNicDevices();
+
+            VirtualEthernetCard device = (VirtualEthernetCard) nicDevices[nicIndex];
+
+            if (!_nexusVSwitch) {
+                VirtualEthernetCardNetworkBackingInfo nicBacking = new VirtualEthernetCardNetworkBackingInfo();
+                nicBacking.setDeviceName(networkInfo.second());
+                nicBacking.setNetwork(networkInfo.first());
+                device.setBacking(nicBacking);
+            } else {
+                HostMO hostMo = vmMo.getRunningHost();
+                DatacenterMO dataCenterMo = new DatacenterMO(hostMo.getContext(), hostMo.getHyperHostDatacenter());
+                device.setBacking(dataCenterMo.getDvPortBackingInfo(networkInfo));
+            }
+
             VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
             VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[1];
             deviceConfigSpecArray[0] = new VirtualDeviceConfigSpec();
@@ -4050,9 +4055,9 @@ public class VmwareResource implements StoragePoolResource, ServerResource,
Vmwa
                 if (mgr.getPrivateVSwitchTypeGlobalParameter().equalsIgnoreCase("nexus"))
                     _privateNetworkVSwitchName = mgr.getPrivateVSwitchName(Long.parseLong(_dcId),
HypervisorType.VMware);
                 if (mgr.getPublicVSwitchTypeGlobalParameter().equalsIgnoreCase("nexus"))
-                _publicNetworkVSwitchName = mgr.getPublicVSwitchName(Long.parseLong(_dcId),
HypervisorType.VMware);
+                    _publicNetworkVSwitchName = mgr.getPublicVSwitchName(Long.parseLong(_dcId),
HypervisorType.VMware);
                 if (mgr.getGuestVSwitchTypeGlobalParameter().equalsIgnoreCase("nexus"))
-                _guestNetworkVSwitchName = mgr.getGuestVSwitchName(Long.parseLong(_dcId),
HypervisorType.VMware);
+                    _guestNetworkVSwitchName = mgr.getGuestVSwitchName(Long.parseLong(_dcId),
HypervisorType.VMware);
             }
 
         } catch (Exception e) {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/484077f4/vmware-base/src/com/cloud/hypervisor/vmware/mo/DatacenterMO.java
----------------------------------------------------------------------
diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/DatacenterMO.java b/vmware-base/src/com/cloud/hypervisor/vmware/mo/DatacenterMO.java
index c753fb7..0d31d2a 100755
--- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/DatacenterMO.java
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/DatacenterMO.java
@@ -20,6 +20,7 @@ import com.cloud.utils.Pair;
 import com.vmware.apputils.vim25.ServiceUtil;
 import com.vmware.vim25.CustomFieldStringValue;
 import com.vmware.vim25.DVPortgroupConfigInfo;
+import com.vmware.vim25.DistributedVirtualSwitchPortConnection;
 import com.vmware.vim25.DynamicProperty;
 import com.vmware.vim25.ManagedObjectReference;
 import com.vmware.vim25.ObjectContent;
@@ -28,6 +29,9 @@ import com.vmware.vim25.PropertyFilterSpec;
 import com.vmware.vim25.PropertySpec;
 import com.vmware.vim25.SelectionSpec;
 import com.vmware.vim25.TraversalSpec;
+import com.vmware.vim25.VirtualDeviceBackingInfo;
+import com.vmware.vim25.VirtualEthernetCardDistributedVirtualPortBackingInfo;
+import com.vmware.vim25.VirtualEthernetCardNetworkBackingInfo;
 
 public class DatacenterMO extends BaseMO {
 	
@@ -444,5 +448,21 @@ public class DatacenterMO extends BaseMO {
     public String getDvSwitchUuid(ManagedObjectReference dvSwitchMor) throws Exception {
         assert (dvSwitchMor != null);
         return (String) _context.getServiceUtil().getDynamicProperty(dvSwitchMor, "uuid");
+    }
+
+    public VirtualEthernetCardDistributedVirtualPortBackingInfo getDvPortBackingInfo(Pair<ManagedObjectReference,
String> networkInfo)
+            throws Exception {
+        assert (networkInfo != null);
+        assert (networkInfo.first() != null && networkInfo.first().getType().equalsIgnoreCase("DistributedVirtualPortgroup"));
+        final VirtualEthernetCardDistributedVirtualPortBackingInfo dvPortBacking = new VirtualEthernetCardDistributedVirtualPortBackingInfo();
+        final DistributedVirtualSwitchPortConnection dvPortConnection = new DistributedVirtualSwitchPortConnection();
+        ManagedObjectReference dvsMor = getDvSwitchMor(networkInfo.first());
+        String dvSwitchUuid = getDvSwitchUuid(dvsMor);
+        dvPortConnection.setSwitchUuid(dvSwitchUuid);
+        dvPortConnection.setPortgroupKey(networkInfo.first().get_value());
+        dvPortBacking.setPort(dvPortConnection);
+        System.out.println("Plugging NIC device into network " + networkInfo.second() + "
backed by dvSwitch: "
+                + dvSwitchUuid);
+        return dvPortBacking;
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/484077f4/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java
----------------------------------------------------------------------
diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java b/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java
index 3319e92..be4ca7b 100755
--- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java
@@ -38,6 +38,7 @@ import com.cloud.utils.script.Script;
 import com.google.gson.Gson;
 import com.vmware.vim25.ArrayOfManagedObjectReference;
 import com.vmware.vim25.CustomFieldStringValue;
+import com.vmware.vim25.DistributedVirtualSwitchPortConnection;
 import com.vmware.vim25.DynamicProperty;
 import com.vmware.vim25.GuestInfo;
 import com.vmware.vim25.HttpNfcLeaseDeviceUrl;
@@ -72,6 +73,7 @@ import com.vmware.vim25.VirtualDiskSparseVer1BackingInfo;
 import com.vmware.vim25.VirtualDiskSparseVer2BackingInfo;
 import com.vmware.vim25.VirtualDiskType;
 import com.vmware.vim25.VirtualEthernetCard;
+import com.vmware.vim25.VirtualEthernetCardDistributedVirtualPortBackingInfo;
 import com.vmware.vim25.VirtualIDEController;
 import com.vmware.vim25.VirtualLsiLogicController;
 import com.vmware.vim25.VirtualMachineCloneSpec;
@@ -2002,17 +2004,38 @@ public class VirtualMachineMO extends BaseMO {
                     return 1;
                 return 0;
             }
-        });
-	    
-        int index = 0; 
-        for(VirtualDevice nic : nics) {
-            if(((VirtualEthernetCard)nic).getDeviceInfo().getSummary().startsWith(networkNamePrefix))
-                return new Pair<Integer, VirtualDevice>(new Integer(index), nic);
-            index++;
-        }
-        return new Pair<Integer, VirtualDevice>(new Integer(-1), null);
-	}
-	
+        });
+        
+        int index = 0;
+        String attachedNetworkSummary;
+        String dvPortGroupName;
+        for (VirtualDevice nic : nics) {
+            attachedNetworkSummary = ((VirtualEthernetCard) nic).getDeviceInfo().getSummary();
+            if (attachedNetworkSummary.startsWith(networkNamePrefix)) {
+                return new Pair<Integer, VirtualDevice>(new Integer(index), nic);
+            } else if (attachedNetworkSummary.endsWith("DistributedVirtualPortBackingInfo.summary"))
{
+                dvPortGroupName = getDvPortGroupName((VirtualEthernetCard) nic);
+                if (dvPortGroupName != null && dvPortGroupName.startsWith(networkNamePrefix))
{
+                    s_logger.debug("Found a dvPortGroup already associated with public NIC.");
+                    return new Pair<Integer, VirtualDevice>(new Integer(index), nic);
+                }
+            }
+            index++;
+        }
+        return new Pair<Integer, VirtualDevice>(new Integer(-1), null);
+    }
+
+    public String getDvPortGroupName(VirtualEthernetCard nic) throws Exception {
+        VirtualEthernetCardDistributedVirtualPortBackingInfo dvpBackingInfo =
+                (VirtualEthernetCardDistributedVirtualPortBackingInfo) ((VirtualEthernetCard)
nic).getBacking();
+        DistributedVirtualSwitchPortConnection dvsPort = (DistributedVirtualSwitchPortConnection)
dvpBackingInfo.getPort();
+        String dvPortGroupKey = dvsPort.getPortgroupKey();
+        ManagedObjectReference dvPortGroupMor = new ManagedObjectReference();
+        dvPortGroupMor.set_value(dvPortGroupKey);
+        dvPortGroupMor.setType("DistributedVirtualPortgroup");
+        return (String) _context.getServiceUtil().getDynamicProperty(dvPortGroupMor, "name");
+    }
+
 	public VirtualDevice[] getMatchedDevices(Class<?>[] deviceClasses) throws Exception
{
 		assert(deviceClasses != null);
 		


Mime
View raw message