cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ke4...@apache.org
Subject [37/50] git commit: CS-9919: Support for Nexus Swiches (Cisco Vswitches)
Date Sun, 27 May 2012 22:30:44 GMT
CS-9919: Support for Nexus Swiches (Cisco Vswitches)

Description:

	Instance configuration to join distributed vNetwork.

Conflicts:

	core/src/com/cloud/hypervisor/vmware/manager/VmwareManager.java
	core/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
	vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareHelper.java


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

Branch: refs/heads/master
Commit: 9709774b4b0afbcf2536b52931c39f222c8017f7
Parents: 7838b3f
Author: Sateesh Chodapuneedi <sateesh.chodapuneedi@citrix.com>
Authored: Tue May 15 05:28:39 2012 +0530
Committer: Vijayendra Bhamidipati <vijayendra.bhamidipati@citrix.com>
Committed: Fri May 25 17:53:00 2012 -0700

----------------------------------------------------------------------
 .../hypervisor/vmware/manager/VmwareManager.java   |    7 +
 .../hypervisor/vmware/resource/VmwareResource.java |  104 +++++++++------
 .../cloud/hypervisor/vmware/VmwareManagerImpl.java |   17 +++-
 .../cloud/hypervisor/vmware/mo/DatacenterMO.java   |    4 +-
 .../cloud/hypervisor/vmware/util/VmwareHelper.java |   84 +++++++++---
 5 files changed, 152 insertions(+), 64 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/9709774b/core/src/com/cloud/hypervisor/vmware/manager/VmwareManager.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/hypervisor/vmware/manager/VmwareManager.java b/core/src/com/cloud/hypervisor/vmware/manager/VmwareManager.java
index 0f10bfa..ade3c41 100755
--- a/core/src/com/cloud/hypervisor/vmware/manager/VmwareManager.java
+++ b/core/src/com/cloud/hypervisor/vmware/manager/VmwareManager.java
@@ -16,6 +16,7 @@ import java.io.File;
 import java.util.List;
 import java.util.Map;
 
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
 import com.cloud.hypervisor.vmware.mo.HostMO;
 import com.cloud.hypervisor.vmware.util.VmwareContext;
 import com.cloud.utils.Pair;
@@ -71,4 +72,10 @@ public interface VmwareManager {
     String getPublicVSwitchTypeGlobalParameter();
 
     String getGuestVSwitchTypeGlobalParameter();
+
+    String getPrivateVSwitchName(long dcId, HypervisorType hypervisorType);
+
+    String getPublicVSwitchName(long dcId, HypervisorType hypervisorType);
+
+    String getGuestVSwitchName(long dcId, HypervisorType hypervisorType);
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/9709774b/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 3c1848f..07bbeb0 100755
--- a/core/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
+++ b/core/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
@@ -156,7 +156,6 @@ import com.cloud.hypervisor.vmware.mo.DatastoreMO;
 import com.cloud.hypervisor.vmware.mo.DiskControllerType;
 import com.cloud.hypervisor.vmware.mo.HostFirewallSystemMO;
 import com.cloud.hypervisor.vmware.mo.HostMO;
-import com.cloud.hypervisor.vmware.mo.HostVirtualNicType;
 import com.cloud.hypervisor.vmware.mo.HypervisorHostHelper;
 import com.cloud.hypervisor.vmware.mo.NetworkDetails;
 import com.cloud.hypervisor.vmware.mo.VirtualEthernetCardType;
@@ -1445,35 +1444,39 @@ public class VmwareResource implements StoragePoolResource, ServerResource,
Vmwa
                 if (vol.getType() != Volume.Type.ISO) {
                     Pair<ManagedObjectReference, DatastoreMO> volumeDsDetails = dataStoresDetails.get(vol.getPoolUuid());
                     assert (volumeDsDetails != null);
-                	VirtualDevice device;
-                    datastoreDiskPath = String.format("[%s] %s.vmdk", volumeDsDetails.second().getName(),
vol.getPath());
-                    String chainInfo = vol.getChainInfo();
-
-                    if (chainInfo != null && !chainInfo.isEmpty()) {
-                        String[] diskChain = _gson.fromJson(chainInfo, String[].class);
-                        if (diskChain == null || diskChain.length < 1) {
-                            s_logger.warn("Empty previously-saved chain info, fall back to
the original");
-                            device = VmwareHelper.prepareDiskDevice(vmMo, controllerKey,
new String[] { datastoreDiskPath }, volumeDsDetails.first(), i, i + 1);
-                        } else {
-                            s_logger.info("Attach the disk with stored chain info: " + chainInfo);
-                            for (int j = 0; j < diskChain.length; j++) {
-                                diskChain[j] = String.format("[%s] %s", volumeDsDetails.second().getName(),
diskChain[j]);
-                            }
+                	VirtualDevice device;
+                    datastoreDiskPath = String.format("[%s] %s.vmdk", volumeDsDetails.second().getName(),
vol.getPath());
+                    String chainInfo = vol.getChainInfo();
+
+                    if (chainInfo != null && !chainInfo.isEmpty()) {
+                        String[] diskChain = _gson.fromJson(chainInfo, String[].class);
+                        if (diskChain == null || diskChain.length < 1) {
+                            s_logger.warn("Empty previously-saved chain info, fall back to
the original");
+                            device = VmwareHelper.prepareDiskDevice(vmMo, controllerKey,
new String[] { datastoreDiskPath }, volumeDsDetails.first(), i, i + 1);
+                        } else {
+                            s_logger.info("Attach the disk with stored chain info: " + chainInfo);
+                            for (int j = 0; j < diskChain.length; j++) {
+                                diskChain[j] = String.format("[%s] %s", volumeDsDetails.second().getName(),
diskChain[j]);
+                            }
+
+                            device = VmwareHelper.prepareDiskDevice(vmMo, controllerKey,
diskChain, volumeDsDetails.first(), i, i + 1);
+                        }
+                    } else {
+                        device = VmwareHelper.prepareDiskDevice(vmMo, controllerKey, new
String[] { datastoreDiskPath }, volumeDsDetails.first(), i, i + 1);
+                    }
+                    deviceConfigSpecArray[i].setDevice(device);
+                    deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.add);
+
+                	if(s_logger.isDebugEnabled())
+                		s_logger.debug("Prepare volume at new device " + _gson.toJson(device));
+                    
+                    i++;
+                }
+            }
 
-                            device = VmwareHelper.prepareDiskDevice(vmMo, controllerKey,
diskChain, volumeDsDetails.first(), i, i + 1);
-                        }
-                    } else {
-                        device = VmwareHelper.prepareDiskDevice(vmMo, controllerKey, new
String[] { datastoreDiskPath }, volumeDsDetails.first(), i, i + 1);
-                    }
-                    deviceConfigSpecArray[i].setDevice(device);
-                    deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.add);
-
-                	if(s_logger.isDebugEnabled())
-                		s_logger.debug("Prepare volume at new device " + _gson.toJson(device));
-                    
-                    i++;
-                }
-            }
+            String switchUuid;
+            ManagedObjectReference dcMor = hyperHost.getHyperHostDatacenter();
+            DatacenterMO dataCenterMo = new DatacenterMO(context, dcMor);
 
             VirtualDevice nic;
             int nicMask = 0;
@@ -1482,13 +1485,17 @@ public class VmwareResource implements StoragePoolResource, ServerResource,
Vmwa
                 s_logger.info("Prepare NIC device based on NicTO: " + _gson.toJson(nicTo));
 
                 Pair<ManagedObjectReference, String> networkInfo = prepareNetworkFromNicInfo(vmMo.getRunningHost(),
nicTo);
-                
-                nic = VmwareHelper.prepareNicDevice(vmMo, networkInfo.first(), nicDeviceType,
networkInfo.second(), nicTo.getMac(), i, i + 1, true, true);
-                deviceConfigSpecArray[i] = new VirtualDeviceConfigSpec();
-                deviceConfigSpecArray[i].setDevice(nic);
-                deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.add);
-                
-            	if(s_logger.isDebugEnabled())
+
+                ManagedObjectReference dvsMor = dataCenterMo.getDvSwitchMor(networkInfo.first());
+                switchUuid = dataCenterMo.getDvSwitchUuid(dvsMor);
+                s_logger.info("Preparing NIC device on dvSwitch : " + switchUuid);
+
+                nic = VmwareHelper.prepareNicDevice(vmMo, networkInfo.first(), nicDeviceType,
networkInfo.second(), nicTo.getMac(), i, i + 1, true, true);
+                deviceConfigSpecArray[i] = new VirtualDeviceConfigSpec();
+                deviceConfigSpecArray[i].setDevice(nic);
+                deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.add);
+                
+            	if(s_logger.isDebugEnabled())
             		s_logger.debug("Prepare NIC at new device " + _gson.toJson(deviceConfigSpecArray[i]));
  
             	// this is really a hacking for DomR, upon DomR startup, we will reset all the
NIC allocation after eth3
@@ -4022,16 +4029,25 @@ public class VmwareResource implements StoragePoolResource, ServerResource,
Vmwa
             cfmMo.ensureCustomFieldDef("Network", CustomFieldConstants.CLOUD_GC);
             cfmMo.ensureCustomFieldDef("VirtualMachine", CustomFieldConstants.CLOUD_UUID);
             cfmMo.ensureCustomFieldDef("VirtualMachine", CustomFieldConstants.CLOUD_NIC_MASK);
-
-            VmwareHypervisorHost hostMo = this.getHyperHost(context);
+
+            VmwareHypervisorHost hostMo = this.getHyperHost(context);
             _hostName = hostMo.getHyperHostName();
-        } catch (Exception e) {
-            s_logger.error("Unexpected Exception ", e);
+            _privateNetworkVSwitchName = mgr.getPrivateVSwitchName(Long.parseLong(_dcId),
HypervisorType.VMware);
+            _publicNetworkVSwitchName = mgr.getPublicVSwitchName(Long.parseLong(_dcId), HypervisorType.VMware);
+            _guestNetworkVSwitchName = mgr.getGuestVSwitchName(Long.parseLong(_dcId), HypervisorType.VMware);
+        } catch (Exception e) {
+            s_logger.error("Unexpected Exception ", e);
+        }
+
+        if(_privateNetworkVSwitchName == null) {
+            _privateNetworkVSwitchName = (String) params.get("private.network.vswitch.name");
+        }    
+        if(_publicNetworkVSwitchName == null) {
+            _publicNetworkVSwitchName = (String) params.get("public.network.vswitch.name");
+        }
+        if(_guestNetworkVSwitchName == null) {
+            _guestNetworkVSwitchName = (String) params.get("guest.network.vswitch.name");
         }
-
-        _privateNetworkVSwitchName = (String) params.get("private.network.vswitch.name");
-        _publicNetworkVSwitchName = (String) params.get("public.network.vswitch.name");
-        _guestNetworkVSwitchName = (String) params.get("guest.network.vswitch.name");
         
         String value = (String) params.get("cpu.overprovisioning.factor");
         if(value != null)

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/9709774b/server/src/com/cloud/hypervisor/vmware/VmwareManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/hypervisor/vmware/VmwareManagerImpl.java b/server/src/com/cloud/hypervisor/vmware/VmwareManagerImpl.java
index 34de26e..24113bc 100755
--- a/server/src/com/cloud/hypervisor/vmware/VmwareManagerImpl.java
+++ b/server/src/com/cloud/hypervisor/vmware/VmwareManagerImpl.java
@@ -379,7 +379,22 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount,
Lis
     public String composeWorkerName() {
         return UUID.randomUUID().toString().replace("-", "");
     }
-
+    
+    @Override
+    public String getPrivateVSwitchName(long dcId, HypervisorType hypervisorType) {
+        return _netMgr.getDefaultManagementTrafficLabel(dcId, hypervisorType);
+    }
+    
+    @Override
+    public String getPublicVSwitchName(long dcId, HypervisorType hypervisorType) {
+        return _netMgr.getDefaultPublicTrafficLabel(dcId, hypervisorType);
+    }
+    
+    @Override
+    public String getGuestVSwitchName(long dcId, HypervisorType hypervisorType) {
+        return _netMgr.getDefaultGuestTrafficLabel(dcId, hypervisorType);
+    }
+    
     @Override
     public List<ManagedObjectReference> addHostToPodCluster(VmwareContext serviceContext,
long dcId, Long podId, Long clusterId,
             String hostInventoryPath) throws Exception {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/9709774b/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 91cff67..428c88a 100755
--- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/DatacenterMO.java
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/DatacenterMO.java
@@ -395,7 +395,7 @@ public class DatacenterMO extends BaseMO {
 	    return null;
 	}
 
-    public ManagedObjectReference getDvSwitchMor(ManagedObjectReference morDatacenter, ManagedObjectReference
dvPortGroupMor) throws Exception {
+    public ManagedObjectReference getDvSwitchMor(ManagedObjectReference dvPortGroupMor) throws
Exception {
         String dvPortGroupKey = null;
         ManagedObjectReference dvSwitchMor = null;
         PropertySpec pSpec = new PropertySpec();
@@ -408,7 +408,7 @@ public class DatacenterMO extends BaseMO {
         datacenter2DvPortGroupTraversal.setName("datacenter2DvPortgroupTraversal");
 
         ObjectSpec oSpec = new ObjectSpec();
-        oSpec.setObj(morDatacenter);
+        oSpec.setObj(_mor);
         oSpec.setSkip(Boolean.TRUE);
         oSpec.setSelectSet(new SelectionSpec[] { datacenter2DvPortGroupTraversal });
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/9709774b/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareHelper.java
----------------------------------------------------------------------
diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareHelper.java b/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareHelper.java
index db079ea..db11701 100644
--- a/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareHelper.java
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareHelper.java
@@ -10,7 +10,8 @@
 // limitations under the License.
 // 
 // Automatically generated by addcopyright.py at 04/03/2012
-package com.cloud.hypervisor.vmware.util;
+
+package com.cloud.hypervisor.vmware.util;
 
 import java.io.BufferedWriter;
 import java.io.ByteArrayOutputStream;
@@ -32,6 +33,7 @@ import com.cloud.hypervisor.vmware.mo.VirtualMachineMO;
 import com.cloud.utils.Pair;
 import com.cloud.utils.Ternary;
 import com.cloud.utils.exception.ExceptionUtil;
+import com.vmware.vim25.DistributedVirtualSwitchPortConnection;
 import com.vmware.vim25.DynamicProperty;
 import com.vmware.vim25.ManagedObjectReference;
 import com.vmware.vim25.MethodFault;
@@ -53,6 +55,7 @@ import com.vmware.vim25.VirtualDiskSparseVer1BackingInfo;
 import com.vmware.vim25.VirtualDiskSparseVer2BackingInfo;
 import com.vmware.vim25.VirtualE1000;
 import com.vmware.vim25.VirtualEthernetCard;
+import com.vmware.vim25.VirtualEthernetCardDistributedVirtualPortBackingInfo;
 import com.vmware.vim25.VirtualEthernetCardNetworkBackingInfo;
 import com.vmware.vim25.VirtualMachineConfigSpec;
 import com.vmware.vim25.VirtualMachineSnapshotTree;
@@ -101,25 +104,72 @@ public class VmwareHelper {
 		nic.setAddressType("Manual");
 		nic.setConnectable(connectInfo);
 		nic.setMacAddress(macAddress);
-	
-		nic.setUnitNumber(deviceNumber);
-		nic.setKey(-contextNumber);
-		return nic;
+		nic.setUnitNumber(deviceNumber);
+		nic.setKey(-contextNumber);
+		return nic;
 	}
 	
-	// vmdkDatastorePath: [datastore name] vmdkFilePath
-	public static VirtualDevice prepareDiskDevice(VirtualMachineMO vmMo, int controllerKey,
String vmdkDatastorePath, 
-		int sizeInMb, ManagedObjectReference morDs, int deviceNumber, int contextNumber) throws
Exception {
-		
-		VirtualDisk disk = new VirtualDisk();
+    public static VirtualDevice prepareDvNicDevice(VirtualMachineMO vmMo, ManagedObjectReference
morNetwork, VirtualEthernetCardType deviceType,
+            String dvPortGroupName, String dvSwitchUuid, String macAddress, int deviceNumber,
int contextNumber, boolean conntected, boolean connectOnStart) throws Exception {
 
-		VirtualDiskFlatVer2BackingInfo backingInfo = new VirtualDiskFlatVer2BackingInfo();
-        backingInfo.setDiskMode(VirtualDiskMode.persistent.toString());
-    	backingInfo.setThinProvisioned(true);
-    	backingInfo.setEagerlyScrub(false);
-        backingInfo.setDatastore(morDs);
-        backingInfo.setFileName(vmdkDatastorePath);
-        disk.setBacking(backingInfo);
+        VirtualEthernetCard nic;
+        switch (deviceType) {
+        case E1000:
+            nic = new VirtualE1000();
+            break;
+
+        case PCNet32:
+            nic = new VirtualPCNet32();
+            break;
+
+        case Vmxnet2:
+            nic = new VirtualVmxnet2();
+            break;
+
+        case Vmxnet3:
+            nic = new VirtualVmxnet3();
+            break;
+
+        default:
+            assert (false);
+            nic = new VirtualE1000();
+        }
+
+        final VirtualEthernetCardDistributedVirtualPortBackingInfo dvPortBacking = new VirtualEthernetCardDistributedVirtualPortBackingInfo();
+        final DistributedVirtualSwitchPortConnection dvPortConnection = new DistributedVirtualSwitchPortConnection();
+        final VirtualDeviceConnectInfo connectInfo = new VirtualDeviceConnectInfo();
+
+        dvPortConnection.setSwitchUuid(dvSwitchUuid);
+        dvPortConnection.setPortgroupKey(morNetwork.get_value());
+        dvPortBacking.setPort(dvPortConnection);
+        nic.setBacking(dvPortBacking);
+        nic.setKey(30);
+
+        connectInfo.setAllowGuestControl(true);
+        connectInfo.setConnected(conntected);
+        connectInfo.setStartConnected(connectOnStart);
+        nic.setAddressType("Manual");
+        nic.setConnectable(connectInfo);
+        nic.setMacAddress(macAddress);
+
+        nic.setUnitNumber(deviceNumber);
+        nic.setKey(-contextNumber);
+        return nic;
+    }
+
+	// vmdkDatastorePath: [datastore name] vmdkFilePath
+	public static VirtualDevice prepareDiskDevice(VirtualMachineMO vmMo, int controllerKey,
String vmdkDatastorePath, 
+		int sizeInMb, ManagedObjectReference morDs, int deviceNumber, int contextNumber) throws
Exception {
+		
+		VirtualDisk disk = new VirtualDisk();
+
+		VirtualDiskFlatVer2BackingInfo backingInfo = new VirtualDiskFlatVer2BackingInfo();
+        backingInfo.setDiskMode(VirtualDiskMode.persistent.toString());
+    	backingInfo.setThinProvisioned(true);
+    	backingInfo.setEagerlyScrub(false);
+        backingInfo.setDatastore(morDs);
+        backingInfo.setFileName(vmdkDatastorePath);
+        disk.setBacking(backingInfo);
 
 		if(controllerKey < 0)
 			controllerKey = vmMo.getIDEDeviceControllerKey();


Mime
View raw message