Skip to content

Commit 9709774

Browse files
Sateesh ChodapuneediVijayendra Bhamidipati
authored andcommitted
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
1 parent 7838b3f commit 9709774

5 files changed

Lines changed: 152 additions & 64 deletions

File tree

core/src/com/cloud/hypervisor/vmware/manager/VmwareManager.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.util.List;
1717
import java.util.Map;
1818

19+
import com.cloud.hypervisor.Hypervisor.HypervisorType;
1920
import com.cloud.hypervisor.vmware.mo.HostMO;
2021
import com.cloud.hypervisor.vmware.util.VmwareContext;
2122
import com.cloud.utils.Pair;
@@ -71,4 +72,10 @@ List<ManagedObjectReference> addHostToPodCluster(VmwareContext serviceContext, l
7172
String getPublicVSwitchTypeGlobalParameter();
7273

7374
String getGuestVSwitchTypeGlobalParameter();
75+
76+
String getPrivateVSwitchName(long dcId, HypervisorType hypervisorType);
77+
78+
String getPublicVSwitchName(long dcId, HypervisorType hypervisorType);
79+
80+
String getGuestVSwitchName(long dcId, HypervisorType hypervisorType);
7481
}

core/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java

Lines changed: 60 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@
156156
import com.cloud.hypervisor.vmware.mo.DiskControllerType;
157157
import com.cloud.hypervisor.vmware.mo.HostFirewallSystemMO;
158158
import com.cloud.hypervisor.vmware.mo.HostMO;
159-
import com.cloud.hypervisor.vmware.mo.HostVirtualNicType;
160159
import com.cloud.hypervisor.vmware.mo.HypervisorHostHelper;
161160
import com.cloud.hypervisor.vmware.mo.NetworkDetails;
162161
import com.cloud.hypervisor.vmware.mo.VirtualEthernetCardType;
@@ -1445,35 +1444,39 @@ protected StartAnswer execute(StartCommand cmd) {
14451444
if (vol.getType() != Volume.Type.ISO) {
14461445
Pair<ManagedObjectReference, DatastoreMO> volumeDsDetails = dataStoresDetails.get(vol.getPoolUuid());
14471446
assert (volumeDsDetails != null);
1448-
VirtualDevice device;
1449-
datastoreDiskPath = String.format("[%s] %s.vmdk", volumeDsDetails.second().getName(), vol.getPath());
1450-
String chainInfo = vol.getChainInfo();
1451-
1452-
if (chainInfo != null && !chainInfo.isEmpty()) {
1453-
String[] diskChain = _gson.fromJson(chainInfo, String[].class);
1454-
if (diskChain == null || diskChain.length < 1) {
1455-
s_logger.warn("Empty previously-saved chain info, fall back to the original");
1456-
device = VmwareHelper.prepareDiskDevice(vmMo, controllerKey, new String[] { datastoreDiskPath }, volumeDsDetails.first(), i, i + 1);
1457-
} else {
1458-
s_logger.info("Attach the disk with stored chain info: " + chainInfo);
1459-
for (int j = 0; j < diskChain.length; j++) {
1460-
diskChain[j] = String.format("[%s] %s", volumeDsDetails.second().getName(), diskChain[j]);
1461-
}
1447+
VirtualDevice device;
1448+
datastoreDiskPath = String.format("[%s] %s.vmdk", volumeDsDetails.second().getName(), vol.getPath());
1449+
String chainInfo = vol.getChainInfo();
1450+
1451+
if (chainInfo != null && !chainInfo.isEmpty()) {
1452+
String[] diskChain = _gson.fromJson(chainInfo, String[].class);
1453+
if (diskChain == null || diskChain.length < 1) {
1454+
s_logger.warn("Empty previously-saved chain info, fall back to the original");
1455+
device = VmwareHelper.prepareDiskDevice(vmMo, controllerKey, new String[] { datastoreDiskPath }, volumeDsDetails.first(), i, i + 1);
1456+
} else {
1457+
s_logger.info("Attach the disk with stored chain info: " + chainInfo);
1458+
for (int j = 0; j < diskChain.length; j++) {
1459+
diskChain[j] = String.format("[%s] %s", volumeDsDetails.second().getName(), diskChain[j]);
1460+
}
1461+
1462+
device = VmwareHelper.prepareDiskDevice(vmMo, controllerKey, diskChain, volumeDsDetails.first(), i, i + 1);
1463+
}
1464+
} else {
1465+
device = VmwareHelper.prepareDiskDevice(vmMo, controllerKey, new String[] { datastoreDiskPath }, volumeDsDetails.first(), i, i + 1);
1466+
}
1467+
deviceConfigSpecArray[i].setDevice(device);
1468+
deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.add);
1469+
1470+
if(s_logger.isDebugEnabled())
1471+
s_logger.debug("Prepare volume at new device " + _gson.toJson(device));
1472+
1473+
i++;
1474+
}
1475+
}
14621476

1463-
device = VmwareHelper.prepareDiskDevice(vmMo, controllerKey, diskChain, volumeDsDetails.first(), i, i + 1);
1464-
}
1465-
} else {
1466-
device = VmwareHelper.prepareDiskDevice(vmMo, controllerKey, new String[] { datastoreDiskPath }, volumeDsDetails.first(), i, i + 1);
1467-
}
1468-
deviceConfigSpecArray[i].setDevice(device);
1469-
deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.add);
1470-
1471-
if(s_logger.isDebugEnabled())
1472-
s_logger.debug("Prepare volume at new device " + _gson.toJson(device));
1473-
1474-
i++;
1475-
}
1476-
}
1477+
String switchUuid;
1478+
ManagedObjectReference dcMor = hyperHost.getHyperHostDatacenter();
1479+
DatacenterMO dataCenterMo = new DatacenterMO(context, dcMor);
14771480

14781481
VirtualDevice nic;
14791482
int nicMask = 0;
@@ -1482,13 +1485,17 @@ protected StartAnswer execute(StartCommand cmd) {
14821485
s_logger.info("Prepare NIC device based on NicTO: " + _gson.toJson(nicTo));
14831486

14841487
Pair<ManagedObjectReference, String> networkInfo = prepareNetworkFromNicInfo(vmMo.getRunningHost(), nicTo);
1485-
1486-
nic = VmwareHelper.prepareNicDevice(vmMo, networkInfo.first(), nicDeviceType, networkInfo.second(), nicTo.getMac(), i, i + 1, true, true);
1487-
deviceConfigSpecArray[i] = new VirtualDeviceConfigSpec();
1488-
deviceConfigSpecArray[i].setDevice(nic);
1489-
deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.add);
1490-
1491-
if(s_logger.isDebugEnabled())
1488+
1489+
ManagedObjectReference dvsMor = dataCenterMo.getDvSwitchMor(networkInfo.first());
1490+
switchUuid = dataCenterMo.getDvSwitchUuid(dvsMor);
1491+
s_logger.info("Preparing NIC device on dvSwitch : " + switchUuid);
1492+
1493+
nic = VmwareHelper.prepareNicDevice(vmMo, networkInfo.first(), nicDeviceType, networkInfo.second(), nicTo.getMac(), i, i + 1, true, true);
1494+
deviceConfigSpecArray[i] = new VirtualDeviceConfigSpec();
1495+
deviceConfigSpecArray[i].setDevice(nic);
1496+
deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.add);
1497+
1498+
if(s_logger.isDebugEnabled())
14921499
s_logger.debug("Prepare NIC at new device " + _gson.toJson(deviceConfigSpecArray[i]));
14931500

14941501
// this is really a hacking for DomR, upon DomR startup, we will reset all the NIC allocation after eth3
@@ -4022,16 +4029,25 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
40224029
cfmMo.ensureCustomFieldDef("Network", CustomFieldConstants.CLOUD_GC);
40234030
cfmMo.ensureCustomFieldDef("VirtualMachine", CustomFieldConstants.CLOUD_UUID);
40244031
cfmMo.ensureCustomFieldDef("VirtualMachine", CustomFieldConstants.CLOUD_NIC_MASK);
4025-
4026-
VmwareHypervisorHost hostMo = this.getHyperHost(context);
4032+
4033+
VmwareHypervisorHost hostMo = this.getHyperHost(context);
40274034
_hostName = hostMo.getHyperHostName();
4028-
} catch (Exception e) {
4029-
s_logger.error("Unexpected Exception ", e);
4035+
_privateNetworkVSwitchName = mgr.getPrivateVSwitchName(Long.parseLong(_dcId), HypervisorType.VMware);
4036+
_publicNetworkVSwitchName = mgr.getPublicVSwitchName(Long.parseLong(_dcId), HypervisorType.VMware);
4037+
_guestNetworkVSwitchName = mgr.getGuestVSwitchName(Long.parseLong(_dcId), HypervisorType.VMware);
4038+
} catch (Exception e) {
4039+
s_logger.error("Unexpected Exception ", e);
4040+
}
4041+
4042+
if(_privateNetworkVSwitchName == null) {
4043+
_privateNetworkVSwitchName = (String) params.get("private.network.vswitch.name");
4044+
}
4045+
if(_publicNetworkVSwitchName == null) {
4046+
_publicNetworkVSwitchName = (String) params.get("public.network.vswitch.name");
4047+
}
4048+
if(_guestNetworkVSwitchName == null) {
4049+
_guestNetworkVSwitchName = (String) params.get("guest.network.vswitch.name");
40304050
}
4031-
4032-
_privateNetworkVSwitchName = (String) params.get("private.network.vswitch.name");
4033-
_publicNetworkVSwitchName = (String) params.get("public.network.vswitch.name");
4034-
_guestNetworkVSwitchName = (String) params.get("guest.network.vswitch.name");
40354051

40364052
String value = (String) params.get("cpu.overprovisioning.factor");
40374053
if(value != null)

server/src/com/cloud/hypervisor/vmware/VmwareManagerImpl.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,22 @@ public String getGuestVSwitchTypeGlobalParameter() {
379379
public String composeWorkerName() {
380380
return UUID.randomUUID().toString().replace("-", "");
381381
}
382-
382+
383+
@Override
384+
public String getPrivateVSwitchName(long dcId, HypervisorType hypervisorType) {
385+
return _netMgr.getDefaultManagementTrafficLabel(dcId, hypervisorType);
386+
}
387+
388+
@Override
389+
public String getPublicVSwitchName(long dcId, HypervisorType hypervisorType) {
390+
return _netMgr.getDefaultPublicTrafficLabel(dcId, hypervisorType);
391+
}
392+
393+
@Override
394+
public String getGuestVSwitchName(long dcId, HypervisorType hypervisorType) {
395+
return _netMgr.getDefaultGuestTrafficLabel(dcId, hypervisorType);
396+
}
397+
383398
@Override
384399
public List<ManagedObjectReference> addHostToPodCluster(VmwareContext serviceContext, long dcId, Long podId, Long clusterId,
385400
String hostInventoryPath) throws Exception {

vmware-base/src/com/cloud/hypervisor/vmware/mo/DatacenterMO.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ public DVPortgroupConfigInfo getDvPortGroupSpec(String dvPortGroupName) throws E
395395
return null;
396396
}
397397

398-
public ManagedObjectReference getDvSwitchMor(ManagedObjectReference morDatacenter, ManagedObjectReference dvPortGroupMor) throws Exception {
398+
public ManagedObjectReference getDvSwitchMor(ManagedObjectReference dvPortGroupMor) throws Exception {
399399
String dvPortGroupKey = null;
400400
ManagedObjectReference dvSwitchMor = null;
401401
PropertySpec pSpec = new PropertySpec();
@@ -408,7 +408,7 @@ public ManagedObjectReference getDvSwitchMor(ManagedObjectReference morDatacente
408408
datacenter2DvPortGroupTraversal.setName("datacenter2DvPortgroupTraversal");
409409

410410
ObjectSpec oSpec = new ObjectSpec();
411-
oSpec.setObj(morDatacenter);
411+
oSpec.setObj(_mor);
412412
oSpec.setSkip(Boolean.TRUE);
413413
oSpec.setSelectSet(new SelectionSpec[] { datacenter2DvPortGroupTraversal });
414414

vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareHelper.java

Lines changed: 67 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
// limitations under the License.
1111
//
1212
// Automatically generated by addcopyright.py at 04/03/2012
13-
package com.cloud.hypervisor.vmware.util;
13+
14+
package com.cloud.hypervisor.vmware.util;
1415

1516
import java.io.BufferedWriter;
1617
import java.io.ByteArrayOutputStream;
@@ -32,6 +33,7 @@
3233
import com.cloud.utils.Pair;
3334
import com.cloud.utils.Ternary;
3435
import com.cloud.utils.exception.ExceptionUtil;
36+
import com.vmware.vim25.DistributedVirtualSwitchPortConnection;
3537
import com.vmware.vim25.DynamicProperty;
3638
import com.vmware.vim25.ManagedObjectReference;
3739
import com.vmware.vim25.MethodFault;
@@ -53,6 +55,7 @@
5355
import com.vmware.vim25.VirtualDiskSparseVer2BackingInfo;
5456
import com.vmware.vim25.VirtualE1000;
5557
import com.vmware.vim25.VirtualEthernetCard;
58+
import com.vmware.vim25.VirtualEthernetCardDistributedVirtualPortBackingInfo;
5659
import com.vmware.vim25.VirtualEthernetCardNetworkBackingInfo;
5760
import com.vmware.vim25.VirtualMachineConfigSpec;
5861
import com.vmware.vim25.VirtualMachineSnapshotTree;
@@ -101,25 +104,72 @@ public static VirtualDevice prepareNicDevice(VirtualMachineMO vmMo, ManagedObjec
101104
nic.setAddressType("Manual");
102105
nic.setConnectable(connectInfo);
103106
nic.setMacAddress(macAddress);
104-
105-
nic.setUnitNumber(deviceNumber);
106-
nic.setKey(-contextNumber);
107-
return nic;
107+
nic.setUnitNumber(deviceNumber);
108+
nic.setKey(-contextNumber);
109+
return nic;
108110
}
109111

110-
// vmdkDatastorePath: [datastore name] vmdkFilePath
111-
public static VirtualDevice prepareDiskDevice(VirtualMachineMO vmMo, int controllerKey, String vmdkDatastorePath,
112-
int sizeInMb, ManagedObjectReference morDs, int deviceNumber, int contextNumber) throws Exception {
113-
114-
VirtualDisk disk = new VirtualDisk();
112+
public static VirtualDevice prepareDvNicDevice(VirtualMachineMO vmMo, ManagedObjectReference morNetwork, VirtualEthernetCardType deviceType,
113+
String dvPortGroupName, String dvSwitchUuid, String macAddress, int deviceNumber, int contextNumber, boolean conntected, boolean connectOnStart) throws Exception {
115114

116-
VirtualDiskFlatVer2BackingInfo backingInfo = new VirtualDiskFlatVer2BackingInfo();
117-
backingInfo.setDiskMode(VirtualDiskMode.persistent.toString());
118-
backingInfo.setThinProvisioned(true);
119-
backingInfo.setEagerlyScrub(false);
120-
backingInfo.setDatastore(morDs);
121-
backingInfo.setFileName(vmdkDatastorePath);
122-
disk.setBacking(backingInfo);
115+
VirtualEthernetCard nic;
116+
switch (deviceType) {
117+
case E1000:
118+
nic = new VirtualE1000();
119+
break;
120+
121+
case PCNet32:
122+
nic = new VirtualPCNet32();
123+
break;
124+
125+
case Vmxnet2:
126+
nic = new VirtualVmxnet2();
127+
break;
128+
129+
case Vmxnet3:
130+
nic = new VirtualVmxnet3();
131+
break;
132+
133+
default:
134+
assert (false);
135+
nic = new VirtualE1000();
136+
}
137+
138+
final VirtualEthernetCardDistributedVirtualPortBackingInfo dvPortBacking = new VirtualEthernetCardDistributedVirtualPortBackingInfo();
139+
final DistributedVirtualSwitchPortConnection dvPortConnection = new DistributedVirtualSwitchPortConnection();
140+
final VirtualDeviceConnectInfo connectInfo = new VirtualDeviceConnectInfo();
141+
142+
dvPortConnection.setSwitchUuid(dvSwitchUuid);
143+
dvPortConnection.setPortgroupKey(morNetwork.get_value());
144+
dvPortBacking.setPort(dvPortConnection);
145+
nic.setBacking(dvPortBacking);
146+
nic.setKey(30);
147+
148+
connectInfo.setAllowGuestControl(true);
149+
connectInfo.setConnected(conntected);
150+
connectInfo.setStartConnected(connectOnStart);
151+
nic.setAddressType("Manual");
152+
nic.setConnectable(connectInfo);
153+
nic.setMacAddress(macAddress);
154+
155+
nic.setUnitNumber(deviceNumber);
156+
nic.setKey(-contextNumber);
157+
return nic;
158+
}
159+
160+
// vmdkDatastorePath: [datastore name] vmdkFilePath
161+
public static VirtualDevice prepareDiskDevice(VirtualMachineMO vmMo, int controllerKey, String vmdkDatastorePath,
162+
int sizeInMb, ManagedObjectReference morDs, int deviceNumber, int contextNumber) throws Exception {
163+
164+
VirtualDisk disk = new VirtualDisk();
165+
166+
VirtualDiskFlatVer2BackingInfo backingInfo = new VirtualDiskFlatVer2BackingInfo();
167+
backingInfo.setDiskMode(VirtualDiskMode.persistent.toString());
168+
backingInfo.setThinProvisioned(true);
169+
backingInfo.setEagerlyScrub(false);
170+
backingInfo.setDatastore(morDs);
171+
backingInfo.setFileName(vmdkDatastorePath);
172+
disk.setBacking(backingInfo);
123173

124174
if(controllerKey < 0)
125175
controllerKey = vmMo.getIDEDeviceControllerKey();

0 commit comments

Comments
 (0)