diff --git a/api/src/main/java/com/cloud/agent/api/to/IpAddressTO.java b/api/src/main/java/com/cloud/agent/api/to/IpAddressTO.java index 5be71bad0ed0..c6baf7c34e4b 100644 --- a/api/src/main/java/com/cloud/agent/api/to/IpAddressTO.java +++ b/api/src/main/java/com/cloud/agent/api/to/IpAddressTO.java @@ -18,6 +18,8 @@ import com.cloud.network.Networks.TrafficType; +import java.util.Map; + public class IpAddressTO { private long accountId; @@ -36,6 +38,8 @@ public class IpAddressTO { private Integer nicDevId; private boolean newNic; private boolean isPrivateGateway; + private NicTO nicTO; + Map details; public IpAddressTO(long accountId, String ipAddress, boolean add, boolean firstIP, boolean sourceNat, String broadcastUri, String vlanGateway, String vlanNetmask, String vifMacAddress, Integer networkRate, boolean isOneToOneNat) { @@ -142,4 +146,21 @@ public boolean isPrivateGateway() { public void setPrivateGateway(boolean isPrivateGateway) { this.isPrivateGateway = isPrivateGateway; } + + public NicTO getNicTO() { + return nicTO; + } + + public void setNicTO(NicTO nicTO) { + this.nicTO = nicTO; + } + + + public Map getDetails() { + return details; + } + + public void setDetails(Map details) { + this.details = details; + } } diff --git a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/guru/VmwareVmImplementer.java b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/guru/VmwareVmImplementer.java index 08cda5016fcd..aef50d2c2524 100644 --- a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/guru/VmwareVmImplementer.java +++ b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/guru/VmwareVmImplementer.java @@ -214,7 +214,7 @@ private void configureDomainRouterNicsAndDetails(VirtualMachineProfile vm, Virtu NicTO[] nics = to.getNics(); // reserve extra NICs - NicTO[] expandedNics = new NicTO[nics.length + vmwareMgr.getRouterExtraPublicNics()]; + NicTO[] expandedNics = new NicTO[nics.length]; int i = 0; int deviceId = -1; for (i = 0; i < nics.length; i++) { @@ -227,7 +227,7 @@ private void configureDomainRouterNicsAndDetails(VirtualMachineProfile vm, Virtu long networkId = publicNicProfile.getNetworkId(); NetworkVO network = networkDao.findById(networkId); - for (; i < nics.length + vmwareMgr.getRouterExtraPublicNics(); i++) { + for (; i < nics.length; i++) { NicTO nicTo = new NicTO(); nicTo.setDeviceId(deviceId++); diff --git a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManager.java b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManager.java index 8bd4a67209c7..c73f191f42a9 100644 --- a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManager.java +++ b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManager.java @@ -85,8 +85,6 @@ public interface VmwareManager { Pair getAddiionalVncPortRange(); - int getRouterExtraPublicNics(); - boolean beginExclusiveOperation(int timeOutSeconds); void endExclusiveOperation(); diff --git a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java index 8bef78759e1d..04a6c0150317 100644 --- a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java +++ b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java @@ -253,7 +253,6 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw private String _recycleHungWorker = "false"; private int _additionalPortRangeStart; private int _additionalPortRangeSize; - private int _routerExtraPublicNics = 2; private int _vCenterSessionTimeout = 1200000; // Timeout in milliseconds private String _rootDiskController = DiskControllerType.ide.toString(); @@ -374,8 +373,6 @@ public boolean configure(String name, Map params) throws Configu _additionalPortRangeSize = Math.min(1000, 65535 - _additionalPortRangeStart); } - _routerExtraPublicNics = NumbersUtil.parseInt(_configDao.getValue(Config.RouterExtraPublicNics.key()), 2); - _vCenterSessionTimeout = NumbersUtil.parseInt(_configDao.getValue(Config.VmwareVcenterSessionTimeout.key()), 1200) * 1000; s_logger.info("VmwareManagerImpl config - vmware.vcenter.session.timeout: " + _vCenterSessionTimeout); @@ -1069,11 +1066,6 @@ public Pair getAddiionalVncPortRange() { return new Pair(_additionalPortRangeStart, _additionalPortRangeSize); } - @Override - public int getRouterExtraPublicNics() { - return _routerExtraPublicNics; - } - @Override public Map getNexusVSMCredentialsByClusterId(Long clusterId) { CiscoNexusVSMDeviceVO nexusVSM = null; diff --git a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java index ed3739182f04..d2051f689162 100644 --- a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java +++ b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java @@ -1268,26 +1268,38 @@ private PlugNicAnswer execute(PlugNicCommand cmd) { s_logger.info("Executing resource PlugNicCommand " + _gson.toJson(cmd)); } + try { + VirtualEthernetCardType nicDeviceType = null; + if (cmd.getDetails() != null) { + nicDeviceType = VirtualEthernetCardType.valueOf(cmd.getDetails().get("nicAdapter")); + } + plugNicCommandInternal(cmd.getVmName(), nicDeviceType, cmd.getNic(), cmd.getVMType()); + return new PlugNicAnswer(cmd, true, "success"); + } catch (Exception e) { + s_logger.error("Unexpected exception: ", e); + return new PlugNicAnswer(cmd, false, "Unable to execute PlugNicCommand due to " + e.toString()); + } + } + + private void plugNicCommandInternal(String vmName, VirtualEthernetCardType nicDeviceType, NicTO nicTo, VirtualMachine.Type vmType) throws Exception { getServiceContext().getStockObject(VmwareManager.CONTEXT_STOCK_NAME); VmwareContext context = getServiceContext(); - try { - VmwareHypervisorHost hyperHost = getHyperHost(context); + VmwareHypervisorHost hyperHost = getHyperHost(context); - String vmName = cmd.getVmName(); - VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(vmName); + VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(vmName); - if (vmMo == null) { - if (hyperHost instanceof HostMO) { - ClusterMO clusterMo = new ClusterMO(hyperHost.getContext(), ((HostMO) hyperHost).getParentMor()); - vmMo = clusterMo.findVmOnHyperHost(vmName); - } + if (vmMo == null) { + if (hyperHost instanceof HostMO) { + ClusterMO clusterMo = new ClusterMO(hyperHost.getContext(), ((HostMO) hyperHost).getParentMor()); + vmMo = clusterMo.findVmOnHyperHost(vmName); } + } - if (vmMo == null) { - String msg = "Router " + vmName + " no longer exists to execute PlugNic command"; - s_logger.error(msg); - throw new Exception(msg); - } + if (vmMo == null) { + String msg = "Router " + vmName + " no longer exists to execute PlugNic command"; + s_logger.error(msg); + throw new Exception(msg); + } /* if(!isVMWareToolsInstalled(vmMo)){ @@ -1296,54 +1308,45 @@ private PlugNicAnswer execute(PlugNicCommand cmd) { return new PlugNicAnswer(cmd, false, "Unable to execute PlugNicCommand due to " + errMsg); } */ - // Fallback to E1000 if no specific nicAdapter is passed - VirtualEthernetCardType nicDeviceType = VirtualEthernetCardType.E1000; - Map details = cmd.getDetails(); - if (details != null) { - nicDeviceType = VirtualEthernetCardType.valueOf((String) details.get("nicAdapter")); - } - - // find a usable device number in VMware environment - VirtualDevice[] nicDevices = vmMo.getSortedNicDevices(); - int deviceNumber = -1; - for (VirtualDevice device : nicDevices) { - if (device.getUnitNumber() > deviceNumber) - deviceNumber = device.getUnitNumber(); - } - deviceNumber++; + // Fallback to E1000 if no specific nicAdapter is passed + if (nicDeviceType == null) { + nicDeviceType = VirtualEthernetCardType.E1000; + } - NicTO nicTo = cmd.getNic(); - VirtualDevice nic; - Pair networkInfo = prepareNetworkFromNicInfo(vmMo.getRunningHost(), nicTo, false, cmd.getVMType()); - String dvSwitchUuid = null; - if (VmwareHelper.isDvPortGroup(networkInfo.first())) { - ManagedObjectReference dcMor = hyperHost.getHyperHostDatacenter(); - DatacenterMO dataCenterMo = new DatacenterMO(context, dcMor); - ManagedObjectReference dvsMor = dataCenterMo.getDvSwitchMor(networkInfo.first()); - dvSwitchUuid = dataCenterMo.getDvSwitchUuid(dvsMor); - s_logger.info("Preparing NIC device on dvSwitch : " + dvSwitchUuid); - nic = VmwareHelper.prepareDvNicDevice(vmMo, networkInfo.first(), nicDeviceType, networkInfo.second(), dvSwitchUuid, - nicTo.getMac(), deviceNumber + 1, true, true); - } else { - s_logger.info("Preparing NIC device on network " + networkInfo.second()); - nic = VmwareHelper.prepareNicDevice(vmMo, networkInfo.first(), nicDeviceType, networkInfo.second(), - nicTo.getMac(), deviceNumber + 1, true, true); - } + // find a usable device number in VMware environment + VirtualDevice[] nicDevices = vmMo.getSortedNicDevices(); + int deviceNumber = -1; + for (VirtualDevice device : nicDevices) { + if (device.getUnitNumber() > deviceNumber) + deviceNumber = device.getUnitNumber(); + } + deviceNumber++; - VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec(); - VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec(); - deviceConfigSpec.setDevice(nic); - deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD); + VirtualDevice nic; + Pair networkInfo = prepareNetworkFromNicInfo(vmMo.getRunningHost(), nicTo, false, vmType); + String dvSwitchUuid = null; + if (VmwareHelper.isDvPortGroup(networkInfo.first())) { + ManagedObjectReference dcMor = hyperHost.getHyperHostDatacenter(); + DatacenterMO dataCenterMo = new DatacenterMO(context, dcMor); + ManagedObjectReference dvsMor = dataCenterMo.getDvSwitchMor(networkInfo.first()); + dvSwitchUuid = dataCenterMo.getDvSwitchUuid(dvsMor); + s_logger.info("Preparing NIC device on dvSwitch : " + dvSwitchUuid); + nic = VmwareHelper.prepareDvNicDevice(vmMo, networkInfo.first(), nicDeviceType, networkInfo.second(), dvSwitchUuid, + nicTo.getMac(), deviceNumber + 1, true, true); + } else { + s_logger.info("Preparing NIC device on network " + networkInfo.second()); + nic = VmwareHelper.prepareNicDevice(vmMo, networkInfo.first(), nicDeviceType, networkInfo.second(), + nicTo.getMac(), deviceNumber + 1, true, true); + } - vmConfigSpec.getDeviceChange().add(deviceConfigSpec); - if (!vmMo.configureVm(vmConfigSpec)) { - throw new Exception("Failed to configure devices when running PlugNicCommand"); - } + VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec(); + VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec(); + deviceConfigSpec.setDevice(nic); + deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD); - return new PlugNicAnswer(cmd, true, "success"); - } catch (Exception e) { - s_logger.error("Unexpected exception: ", e); - return new PlugNicAnswer(cmd, false, "Unable to execute PlugNicCommand due to " + e.toString()); + vmConfigSpec.getDeviceChange().add(deviceConfigSpec); + if (!vmMo.configureVm(vmConfigSpec)) { + throw new Exception("Failed to configure devices when running PlugNicCommand"); } } @@ -1613,7 +1616,12 @@ private ExecutionResult prepareNetworkElementCommand(IpAssocCommand cmd) { } if (addVif) { - plugPublicNic(vmMo, vlanId, ip); + NicTO nicTO = ip.getNicTO(); + VirtualEthernetCardType nicDeviceType = null; + if (ip.getDetails() != null) { + nicDeviceType = VirtualEthernetCardType.valueOf(ip.getDetails().get("nicAdapter")); + } + plugNicCommandInternal(routerName, nicDeviceType, nicTO, VirtualMachine.Type.DomainRouter); publicNicInfo = vmMo.getNicDeviceIndex(publicNeworkName); if (publicNicInfo.first().intValue() >= 0) { networkUsage(controlIp, "addVif", "eth" + publicNicInfo.first()); @@ -2313,39 +2321,6 @@ protected StartAnswer execute(StartCommand cmd) { int nicMask = 0; int nicCount = 0; - if (vmSpec.getType() == VirtualMachine.Type.DomainRouter) { - int extraPublicNics = mgr.getRouterExtraPublicNics(); - if (extraPublicNics > 0 && vmSpec.getDetails().containsKey("PeerRouterInstanceName")) { - //Set identical MAC address for RvR on extra public interfaces - String peerRouterInstanceName = vmSpec.getDetails().get("PeerRouterInstanceName"); - - VirtualMachineMO peerVmMo = hyperHost.findVmOnHyperHost(peerRouterInstanceName); - if (peerVmMo == null) { - peerVmMo = hyperHost.findVmOnPeerHyperHost(peerRouterInstanceName); - } - - if (peerVmMo != null) { - String oldMacSequence = generateMacSequence(nics); - - for (int nicIndex = nics.length - extraPublicNics; nicIndex < nics.length; nicIndex++) { - VirtualDevice nicDevice = peerVmMo.getNicDeviceByIndex(nics[nicIndex].getDeviceId()); - if (nicDevice != null) { - String mac = ((VirtualEthernetCard) nicDevice).getMacAddress(); - if (mac != null) { - s_logger.info("Use same MAC as previous RvR, the MAC is " + mac + " for extra NIC with device id: " + nics[nicIndex].getDeviceId()); - nics[nicIndex].setMac(mac); - } - } - } - - if (!StringUtils.isBlank(vmSpec.getBootArgs())) { - String newMacSequence = generateMacSequence(nics); - vmSpec.setBootArgs(replaceNicsMacSequenceInBootArgs(oldMacSequence, newMacSequence, vmSpec)); - } - } - } - } - VirtualEthernetCardType nicDeviceType; NiciraNvpApiVersion.logNiciraApiVersion(); diff --git a/server/src/main/java/com/cloud/network/router/CommandSetupHelper.java b/server/src/main/java/com/cloud/network/router/CommandSetupHelper.java index 4bff1a5187d4..9ab633da7794 100644 --- a/server/src/main/java/com/cloud/network/router/CommandSetupHelper.java +++ b/server/src/main/java/com/cloud/network/router/CommandSetupHelper.java @@ -26,6 +26,14 @@ import javax.inject.Inject; +import com.cloud.configuration.ConfigurationManager; +import com.cloud.hypervisor.Hypervisor; +import com.cloud.network.dao.NetworkDetailVO; +import com.cloud.network.dao.NetworkDetailsDao; +import com.cloud.offerings.dao.NetworkOfferingDetailsDao; +import com.cloud.vm.VmDetailConstants; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; @@ -179,6 +187,12 @@ public class CommandSetupHelper { private RouterControlHelper _routerControlHelper; @Inject private HostDao _hostDao; + @Inject + ConfigurationManager _configMgr; + @Inject + private NetworkOfferingDetailsDao networkOfferingDetailsDao; + @Inject + private NetworkDetailsDao networkDetailsDao; @Autowired @Qualifier("networkHelper") @@ -848,6 +862,15 @@ public int compare(final PublicIpAddress o1, final PublicIpAddress o2) { vifMacAddress, networkRate, ipAddr.isOneToOneNat()); setIpAddressNetworkParams(ip, network, router); + if (router.getHypervisorType() == Hypervisor.HypervisorType.VMware) { + Map details = new HashMap<>(); + String defaultSystemVmNicAdapterType = _configDao.getValue(Config.VmwareSystemVmNicDeviceType.key()); + if (defaultSystemVmNicAdapterType == null) { + defaultSystemVmNicAdapterType = Config.VmwareSystemVmNicDeviceType.getDefaultValue(); + } + details.put(VmDetailConstants.NIC_ADAPTER, defaultSystemVmNicAdapterType); + ip.setDetails(details); + } ipsToSend[i++] = ip; /* * send the firstIP = true for the first Add, this is to create @@ -1152,6 +1175,41 @@ private void setIpAddressNetworkParams(IpAddressTO ipAddress, final Network netw ipAddress.setPrivateGateway(false); } ipAddress.setNetworkName(_networkModel.getNetworkTag(router.getHypervisorType(), network)); + + final NetworkOfferingVO networkOfferingVO = _networkOfferingDao.findById(network.getNetworkOfferingId()); + NicTO nicTO = new NicTO(); + nicTO.setMac(ipAddress.getVifMacAddress()); + nicTO.setType(ipAddress.getTrafficType()); + nicTO.setGateway(ipAddress.getVlanGateway()); + nicTO.setBroadcastUri(BroadcastDomainType.fromString(ipAddress.getBroadcastUri())); + nicTO.setType(network.getTrafficType()); + nicTO.setName(_networkModel.getNetworkTag(router.getHypervisorType(), network)); + nicTO.setBroadcastType(network.getBroadcastDomainType()); + nicTO.setIsolationuri(network.getBroadcastUri()); + nicTO.setNetworkRateMbps(_configMgr.getNetworkOfferingNetworkRate(networkOfferingVO.getId(), network.getDataCenterId())); + nicTO.setSecurityGroupEnabled(_networkModel.isSecurityGroupSupportedInNetwork(network)); + nicTO.setDetails(getNicDetails(network)); + + ipAddress.setNicTO(nicTO); + } + + private Map getNicDetails(Network network) { + if (network == null) { + s_logger.debug("Unable to get NIC details as the network is null"); + return null; + } + Map details = networkOfferingDetailsDao.getNtwkOffDetails(network.getNetworkOfferingId()); + if (details != null) { + details.putIfAbsent(NetworkOffering.Detail.PromiscuousMode, NetworkOrchestrationService.PromiscuousMode.value().toString()); + details.putIfAbsent(NetworkOffering.Detail.MacAddressChanges, NetworkOrchestrationService.MacAddressChanges.value().toString()); + details.putIfAbsent(NetworkOffering.Detail.ForgedTransmits, NetworkOrchestrationService.ForgedTransmits.value().toString()); + details.putIfAbsent(NetworkOffering.Detail.MacLearning, NetworkOrchestrationService.MacLearning.value().toString()); + } + NetworkDetailVO pvlantypeDetail = networkDetailsDao.findDetail(network.getId(), ApiConstants.ISOLATED_PVLAN_TYPE); + if (pvlantypeDetail != null) { + details.putIfAbsent(NetworkOffering.Detail.pvlanType, pvlantypeDetail.getValue()); + } + return details; } } diff --git a/server/src/main/java/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/main/java/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index 1ed4f43583dc..b243c16acd81 100644 --- a/server/src/main/java/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/main/java/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -2063,7 +2063,7 @@ public boolean finalizeVirtualMachineProfile(final VirtualMachineProfile profile buf.append(" dnssearchorder=").append(domain_suffix); } - if (profile.getHypervisorType() == HypervisorType.VMware || profile.getHypervisorType() == HypervisorType.Hyperv) { + if (profile.getHypervisorType() == HypervisorType.Hyperv) { buf.append(" extra_pubnics=" + _routerExtraPublicNics); }