Skip to content

Commit 56a8852

Browse files
Remove code that reserves extra interfaces based on the global setting router.extra.public.nics in case of VMware. (apache#5912)
Added hot plugging of vifs whenever required in case of isolated networks. VPC networks already uses hotplugging of vifs.
1 parent ecf85aa commit 56a8852

7 files changed

Lines changed: 149 additions & 105 deletions

File tree

api/src/main/java/com/cloud/agent/api/to/IpAddressTO.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import com.cloud.network.Networks.TrafficType;
2020

21+
import java.util.Map;
22+
2123
public class IpAddressTO {
2224

2325
private long accountId;
@@ -36,6 +38,8 @@ public class IpAddressTO {
3638
private Integer nicDevId;
3739
private boolean newNic;
3840
private boolean isPrivateGateway;
41+
private NicTO nicTO;
42+
Map<String, String> details;
3943

4044
public IpAddressTO(long accountId, String ipAddress, boolean add, boolean firstIP, boolean sourceNat, String broadcastUri, String vlanGateway, String vlanNetmask,
4145
String vifMacAddress, Integer networkRate, boolean isOneToOneNat) {
@@ -142,4 +146,21 @@ public boolean isPrivateGateway() {
142146
public void setPrivateGateway(boolean isPrivateGateway) {
143147
this.isPrivateGateway = isPrivateGateway;
144148
}
149+
150+
public NicTO getNicTO() {
151+
return nicTO;
152+
}
153+
154+
public void setNicTO(NicTO nicTO) {
155+
this.nicTO = nicTO;
156+
}
157+
158+
159+
public Map<String, String> getDetails() {
160+
return details;
161+
}
162+
163+
public void setDetails(Map<String, String> details) {
164+
this.details = details;
165+
}
145166
}

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/guru/VmwareVmImplementer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ private void configureDomainRouterNicsAndDetails(VirtualMachineProfile vm, Virtu
214214
NicTO[] nics = to.getNics();
215215

216216
// reserve extra NICs
217-
NicTO[] expandedNics = new NicTO[nics.length + vmwareMgr.getRouterExtraPublicNics()];
217+
NicTO[] expandedNics = new NicTO[nics.length];
218218
int i = 0;
219219
int deviceId = -1;
220220
for (i = 0; i < nics.length; i++) {
@@ -227,7 +227,7 @@ private void configureDomainRouterNicsAndDetails(VirtualMachineProfile vm, Virtu
227227
long networkId = publicNicProfile.getNetworkId();
228228
NetworkVO network = networkDao.findById(networkId);
229229

230-
for (; i < nics.length + vmwareMgr.getRouterExtraPublicNics(); i++) {
230+
for (; i < nics.length; i++) {
231231
NicTO nicTo = new NicTO();
232232

233233
nicTo.setDeviceId(deviceId++);

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManager.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ public interface VmwareManager {
8585

8686
Pair<Integer, Integer> getAddiionalVncPortRange();
8787

88-
int getRouterExtraPublicNics();
89-
9088
boolean beginExclusiveOperation(int timeOutSeconds);
9189

9290
void endExclusiveOperation();

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,6 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
253253
private String _recycleHungWorker = "false";
254254
private int _additionalPortRangeStart;
255255
private int _additionalPortRangeSize;
256-
private int _routerExtraPublicNics = 2;
257256
private int _vCenterSessionTimeout = 1200000; // Timeout in milliseconds
258257
private String _rootDiskController = DiskControllerType.ide.toString();
259258

@@ -374,8 +373,6 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
374373
_additionalPortRangeSize = Math.min(1000, 65535 - _additionalPortRangeStart);
375374
}
376375

377-
_routerExtraPublicNics = NumbersUtil.parseInt(_configDao.getValue(Config.RouterExtraPublicNics.key()), 2);
378-
379376
_vCenterSessionTimeout = NumbersUtil.parseInt(_configDao.getValue(Config.VmwareVcenterSessionTimeout.key()), 1200) * 1000;
380377
s_logger.info("VmwareManagerImpl config - vmware.vcenter.session.timeout: " + _vCenterSessionTimeout);
381378

@@ -1069,11 +1066,6 @@ public Pair<Integer, Integer> getAddiionalVncPortRange() {
10691066
return new Pair<Integer, Integer>(_additionalPortRangeStart, _additionalPortRangeSize);
10701067
}
10711068

1072-
@Override
1073-
public int getRouterExtraPublicNics() {
1074-
return _routerExtraPublicNics;
1075-
}
1076-
10771069
@Override
10781070
public Map<String, String> getNexusVSMCredentialsByClusterId(Long clusterId) {
10791071
CiscoNexusVSMDeviceVO nexusVSM = null;

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java

Lines changed: 67 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,26 +1268,38 @@ private PlugNicAnswer execute(PlugNicCommand cmd) {
12681268
s_logger.info("Executing resource PlugNicCommand " + _gson.toJson(cmd));
12691269
}
12701270

1271+
try {
1272+
VirtualEthernetCardType nicDeviceType = null;
1273+
if (cmd.getDetails() != null) {
1274+
nicDeviceType = VirtualEthernetCardType.valueOf(cmd.getDetails().get("nicAdapter"));
1275+
}
1276+
plugNicCommandInternal(cmd.getVmName(), nicDeviceType, cmd.getNic(), cmd.getVMType());
1277+
return new PlugNicAnswer(cmd, true, "success");
1278+
} catch (Exception e) {
1279+
s_logger.error("Unexpected exception: ", e);
1280+
return new PlugNicAnswer(cmd, false, "Unable to execute PlugNicCommand due to " + e.toString());
1281+
}
1282+
}
1283+
1284+
private void plugNicCommandInternal(String vmName, VirtualEthernetCardType nicDeviceType, NicTO nicTo, VirtualMachine.Type vmType) throws Exception {
12711285
getServiceContext().getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
12721286
VmwareContext context = getServiceContext();
1273-
try {
1274-
VmwareHypervisorHost hyperHost = getHyperHost(context);
1287+
VmwareHypervisorHost hyperHost = getHyperHost(context);
12751288

1276-
String vmName = cmd.getVmName();
1277-
VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(vmName);
1289+
VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(vmName);
12781290

1279-
if (vmMo == null) {
1280-
if (hyperHost instanceof HostMO) {
1281-
ClusterMO clusterMo = new ClusterMO(hyperHost.getContext(), ((HostMO) hyperHost).getParentMor());
1282-
vmMo = clusterMo.findVmOnHyperHost(vmName);
1283-
}
1291+
if (vmMo == null) {
1292+
if (hyperHost instanceof HostMO) {
1293+
ClusterMO clusterMo = new ClusterMO(hyperHost.getContext(), ((HostMO) hyperHost).getParentMor());
1294+
vmMo = clusterMo.findVmOnHyperHost(vmName);
12841295
}
1296+
}
12851297

1286-
if (vmMo == null) {
1287-
String msg = "Router " + vmName + " no longer exists to execute PlugNic command";
1288-
s_logger.error(msg);
1289-
throw new Exception(msg);
1290-
}
1298+
if (vmMo == null) {
1299+
String msg = "Router " + vmName + " no longer exists to execute PlugNic command";
1300+
s_logger.error(msg);
1301+
throw new Exception(msg);
1302+
}
12911303

12921304
/*
12931305
if(!isVMWareToolsInstalled(vmMo)){
@@ -1296,54 +1308,45 @@ private PlugNicAnswer execute(PlugNicCommand cmd) {
12961308
return new PlugNicAnswer(cmd, false, "Unable to execute PlugNicCommand due to " + errMsg);
12971309
}
12981310
*/
1299-
// Fallback to E1000 if no specific nicAdapter is passed
1300-
VirtualEthernetCardType nicDeviceType = VirtualEthernetCardType.E1000;
1301-
Map<String, String> details = cmd.getDetails();
1302-
if (details != null) {
1303-
nicDeviceType = VirtualEthernetCardType.valueOf((String) details.get("nicAdapter"));
1304-
}
1305-
1306-
// find a usable device number in VMware environment
1307-
VirtualDevice[] nicDevices = vmMo.getSortedNicDevices();
1308-
int deviceNumber = -1;
1309-
for (VirtualDevice device : nicDevices) {
1310-
if (device.getUnitNumber() > deviceNumber)
1311-
deviceNumber = device.getUnitNumber();
1312-
}
1313-
deviceNumber++;
1311+
// Fallback to E1000 if no specific nicAdapter is passed
1312+
if (nicDeviceType == null) {
1313+
nicDeviceType = VirtualEthernetCardType.E1000;
1314+
}
13141315

1315-
NicTO nicTo = cmd.getNic();
1316-
VirtualDevice nic;
1317-
Pair<ManagedObjectReference, String> networkInfo = prepareNetworkFromNicInfo(vmMo.getRunningHost(), nicTo, false, cmd.getVMType());
1318-
String dvSwitchUuid = null;
1319-
if (VmwareHelper.isDvPortGroup(networkInfo.first())) {
1320-
ManagedObjectReference dcMor = hyperHost.getHyperHostDatacenter();
1321-
DatacenterMO dataCenterMo = new DatacenterMO(context, dcMor);
1322-
ManagedObjectReference dvsMor = dataCenterMo.getDvSwitchMor(networkInfo.first());
1323-
dvSwitchUuid = dataCenterMo.getDvSwitchUuid(dvsMor);
1324-
s_logger.info("Preparing NIC device on dvSwitch : " + dvSwitchUuid);
1325-
nic = VmwareHelper.prepareDvNicDevice(vmMo, networkInfo.first(), nicDeviceType, networkInfo.second(), dvSwitchUuid,
1326-
nicTo.getMac(), deviceNumber + 1, true, true);
1327-
} else {
1328-
s_logger.info("Preparing NIC device on network " + networkInfo.second());
1329-
nic = VmwareHelper.prepareNicDevice(vmMo, networkInfo.first(), nicDeviceType, networkInfo.second(),
1330-
nicTo.getMac(), deviceNumber + 1, true, true);
1331-
}
1316+
// find a usable device number in VMware environment
1317+
VirtualDevice[] nicDevices = vmMo.getSortedNicDevices();
1318+
int deviceNumber = -1;
1319+
for (VirtualDevice device : nicDevices) {
1320+
if (device.getUnitNumber() > deviceNumber)
1321+
deviceNumber = device.getUnitNumber();
1322+
}
1323+
deviceNumber++;
13321324

1333-
VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
1334-
VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
1335-
deviceConfigSpec.setDevice(nic);
1336-
deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD);
1325+
VirtualDevice nic;
1326+
Pair<ManagedObjectReference, String> networkInfo = prepareNetworkFromNicInfo(vmMo.getRunningHost(), nicTo, false, vmType);
1327+
String dvSwitchUuid = null;
1328+
if (VmwareHelper.isDvPortGroup(networkInfo.first())) {
1329+
ManagedObjectReference dcMor = hyperHost.getHyperHostDatacenter();
1330+
DatacenterMO dataCenterMo = new DatacenterMO(context, dcMor);
1331+
ManagedObjectReference dvsMor = dataCenterMo.getDvSwitchMor(networkInfo.first());
1332+
dvSwitchUuid = dataCenterMo.getDvSwitchUuid(dvsMor);
1333+
s_logger.info("Preparing NIC device on dvSwitch : " + dvSwitchUuid);
1334+
nic = VmwareHelper.prepareDvNicDevice(vmMo, networkInfo.first(), nicDeviceType, networkInfo.second(), dvSwitchUuid,
1335+
nicTo.getMac(), deviceNumber + 1, true, true);
1336+
} else {
1337+
s_logger.info("Preparing NIC device on network " + networkInfo.second());
1338+
nic = VmwareHelper.prepareNicDevice(vmMo, networkInfo.first(), nicDeviceType, networkInfo.second(),
1339+
nicTo.getMac(), deviceNumber + 1, true, true);
1340+
}
13371341

1338-
vmConfigSpec.getDeviceChange().add(deviceConfigSpec);
1339-
if (!vmMo.configureVm(vmConfigSpec)) {
1340-
throw new Exception("Failed to configure devices when running PlugNicCommand");
1341-
}
1342+
VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
1343+
VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
1344+
deviceConfigSpec.setDevice(nic);
1345+
deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD);
13421346

1343-
return new PlugNicAnswer(cmd, true, "success");
1344-
} catch (Exception e) {
1345-
s_logger.error("Unexpected exception: ", e);
1346-
return new PlugNicAnswer(cmd, false, "Unable to execute PlugNicCommand due to " + e.toString());
1347+
vmConfigSpec.getDeviceChange().add(deviceConfigSpec);
1348+
if (!vmMo.configureVm(vmConfigSpec)) {
1349+
throw new Exception("Failed to configure devices when running PlugNicCommand");
13471350
}
13481351
}
13491352

@@ -1613,7 +1616,12 @@ private ExecutionResult prepareNetworkElementCommand(IpAssocCommand cmd) {
16131616
}
16141617

16151618
if (addVif) {
1616-
plugPublicNic(vmMo, vlanId, ip);
1619+
NicTO nicTO = ip.getNicTO();
1620+
VirtualEthernetCardType nicDeviceType = null;
1621+
if (ip.getDetails() != null) {
1622+
nicDeviceType = VirtualEthernetCardType.valueOf(ip.getDetails().get("nicAdapter"));
1623+
}
1624+
plugNicCommandInternal(routerName, nicDeviceType, nicTO, VirtualMachine.Type.DomainRouter);
16171625
publicNicInfo = vmMo.getNicDeviceIndex(publicNeworkName);
16181626
if (publicNicInfo.first().intValue() >= 0) {
16191627
networkUsage(controlIp, "addVif", "eth" + publicNicInfo.first());
@@ -2313,39 +2321,6 @@ protected StartAnswer execute(StartCommand cmd) {
23132321
int nicMask = 0;
23142322
int nicCount = 0;
23152323

2316-
if (vmSpec.getType() == VirtualMachine.Type.DomainRouter) {
2317-
int extraPublicNics = mgr.getRouterExtraPublicNics();
2318-
if (extraPublicNics > 0 && vmSpec.getDetails().containsKey("PeerRouterInstanceName")) {
2319-
//Set identical MAC address for RvR on extra public interfaces
2320-
String peerRouterInstanceName = vmSpec.getDetails().get("PeerRouterInstanceName");
2321-
2322-
VirtualMachineMO peerVmMo = hyperHost.findVmOnHyperHost(peerRouterInstanceName);
2323-
if (peerVmMo == null) {
2324-
peerVmMo = hyperHost.findVmOnPeerHyperHost(peerRouterInstanceName);
2325-
}
2326-
2327-
if (peerVmMo != null) {
2328-
String oldMacSequence = generateMacSequence(nics);
2329-
2330-
for (int nicIndex = nics.length - extraPublicNics; nicIndex < nics.length; nicIndex++) {
2331-
VirtualDevice nicDevice = peerVmMo.getNicDeviceByIndex(nics[nicIndex].getDeviceId());
2332-
if (nicDevice != null) {
2333-
String mac = ((VirtualEthernetCard) nicDevice).getMacAddress();
2334-
if (mac != null) {
2335-
s_logger.info("Use same MAC as previous RvR, the MAC is " + mac + " for extra NIC with device id: " + nics[nicIndex].getDeviceId());
2336-
nics[nicIndex].setMac(mac);
2337-
}
2338-
}
2339-
}
2340-
2341-
if (!StringUtils.isBlank(vmSpec.getBootArgs())) {
2342-
String newMacSequence = generateMacSequence(nics);
2343-
vmSpec.setBootArgs(replaceNicsMacSequenceInBootArgs(oldMacSequence, newMacSequence, vmSpec));
2344-
}
2345-
}
2346-
}
2347-
}
2348-
23492324
VirtualEthernetCardType nicDeviceType;
23502325

23512326
NiciraNvpApiVersion.logNiciraApiVersion();

server/src/main/java/com/cloud/network/router/CommandSetupHelper.java

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@
2626

2727
import javax.inject.Inject;
2828

29+
import com.cloud.configuration.ConfigurationManager;
30+
import com.cloud.hypervisor.Hypervisor;
31+
import com.cloud.network.dao.NetworkDetailVO;
32+
import com.cloud.network.dao.NetworkDetailsDao;
33+
import com.cloud.offerings.dao.NetworkOfferingDetailsDao;
34+
import com.cloud.vm.VmDetailConstants;
35+
import org.apache.cloudstack.api.ApiConstants;
36+
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
2937
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
3038
import org.apache.log4j.Logger;
3139
import org.springframework.beans.factory.annotation.Autowired;
@@ -179,6 +187,12 @@ public class CommandSetupHelper {
179187
private RouterControlHelper _routerControlHelper;
180188
@Inject
181189
private HostDao _hostDao;
190+
@Inject
191+
ConfigurationManager _configMgr;
192+
@Inject
193+
private NetworkOfferingDetailsDao networkOfferingDetailsDao;
194+
@Inject
195+
private NetworkDetailsDao networkDetailsDao;
182196

183197
@Autowired
184198
@Qualifier("networkHelper")
@@ -848,6 +862,15 @@ public int compare(final PublicIpAddress o1, final PublicIpAddress o2) {
848862
vifMacAddress, networkRate, ipAddr.isOneToOneNat());
849863

850864
setIpAddressNetworkParams(ip, network, router);
865+
if (router.getHypervisorType() == Hypervisor.HypervisorType.VMware) {
866+
Map<String, String> details = new HashMap<>();
867+
String defaultSystemVmNicAdapterType = _configDao.getValue(Config.VmwareSystemVmNicDeviceType.key());
868+
if (defaultSystemVmNicAdapterType == null) {
869+
defaultSystemVmNicAdapterType = Config.VmwareSystemVmNicDeviceType.getDefaultValue();
870+
}
871+
details.put(VmDetailConstants.NIC_ADAPTER, defaultSystemVmNicAdapterType);
872+
ip.setDetails(details);
873+
}
851874
ipsToSend[i++] = ip;
852875
/*
853876
* send the firstIP = true for the first Add, this is to create
@@ -1152,6 +1175,41 @@ private void setIpAddressNetworkParams(IpAddressTO ipAddress, final Network netw
11521175
ipAddress.setPrivateGateway(false);
11531176
}
11541177
ipAddress.setNetworkName(_networkModel.getNetworkTag(router.getHypervisorType(), network));
1178+
1179+
final NetworkOfferingVO networkOfferingVO = _networkOfferingDao.findById(network.getNetworkOfferingId());
1180+
NicTO nicTO = new NicTO();
1181+
nicTO.setMac(ipAddress.getVifMacAddress());
1182+
nicTO.setType(ipAddress.getTrafficType());
1183+
nicTO.setGateway(ipAddress.getVlanGateway());
1184+
nicTO.setBroadcastUri(BroadcastDomainType.fromString(ipAddress.getBroadcastUri()));
1185+
nicTO.setType(network.getTrafficType());
1186+
nicTO.setName(_networkModel.getNetworkTag(router.getHypervisorType(), network));
1187+
nicTO.setBroadcastType(network.getBroadcastDomainType());
1188+
nicTO.setIsolationuri(network.getBroadcastUri());
1189+
nicTO.setNetworkRateMbps(_configMgr.getNetworkOfferingNetworkRate(networkOfferingVO.getId(), network.getDataCenterId()));
1190+
nicTO.setSecurityGroupEnabled(_networkModel.isSecurityGroupSupportedInNetwork(network));
1191+
nicTO.setDetails(getNicDetails(network));
1192+
1193+
ipAddress.setNicTO(nicTO);
1194+
}
1195+
1196+
private Map<NetworkOffering.Detail, String> getNicDetails(Network network) {
1197+
if (network == null) {
1198+
s_logger.debug("Unable to get NIC details as the network is null");
1199+
return null;
1200+
}
1201+
Map<NetworkOffering.Detail, String> details = networkOfferingDetailsDao.getNtwkOffDetails(network.getNetworkOfferingId());
1202+
if (details != null) {
1203+
details.putIfAbsent(NetworkOffering.Detail.PromiscuousMode, NetworkOrchestrationService.PromiscuousMode.value().toString());
1204+
details.putIfAbsent(NetworkOffering.Detail.MacAddressChanges, NetworkOrchestrationService.MacAddressChanges.value().toString());
1205+
details.putIfAbsent(NetworkOffering.Detail.ForgedTransmits, NetworkOrchestrationService.ForgedTransmits.value().toString());
1206+
details.putIfAbsent(NetworkOffering.Detail.MacLearning, NetworkOrchestrationService.MacLearning.value().toString());
1207+
}
1208+
NetworkDetailVO pvlantypeDetail = networkDetailsDao.findDetail(network.getId(), ApiConstants.ISOLATED_PVLAN_TYPE);
1209+
if (pvlantypeDetail != null) {
1210+
details.putIfAbsent(NetworkOffering.Detail.pvlanType, pvlantypeDetail.getValue());
1211+
}
1212+
return details;
11551213
}
11561214

11571215
}

server/src/main/java/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2063,7 +2063,7 @@ public boolean finalizeVirtualMachineProfile(final VirtualMachineProfile profile
20632063
buf.append(" dnssearchorder=").append(domain_suffix);
20642064
}
20652065

2066-
if (profile.getHypervisorType() == HypervisorType.VMware || profile.getHypervisorType() == HypervisorType.Hyperv) {
2066+
if (profile.getHypervisorType() == HypervisorType.Hyperv) {
20672067
buf.append(" extra_pubnics=" + _routerExtraPublicNics);
20682068
}
20692069

0 commit comments

Comments
 (0)