NSX integration - skeletal code

This commit is contained in:
Pearl Dsilva 2023-08-15 07:23:08 -04:00
parent 5559668f12
commit 446dd837a5
12 changed files with 315 additions and 2 deletions

View File

@ -205,6 +205,9 @@ public interface Network extends ControlledEntity, StateObject<Network.State>, I
//Add Tungsten Fabric provider
public static final Provider Tungsten = new Provider("Tungsten", false);
//TODO: should it be true?
public static final Provider Nsx = new Provider("Nsx", false);
private final String name;
private final boolean isExternal;

View File

@ -52,6 +52,7 @@ public interface NetworkOffering extends InfrastructureEntity, InternalIdentity,
public final static String DefaultSharedNetworkOfferingWithSGService = "DefaultSharedNetworkOfferingWithSGService";
public static final String DEFAULT_TUNGSTEN_SHARED_NETWORK_OFFERING_WITH_SGSERVICE = "DefaultTungstenSharedNetworkOfferingWithSGService";
public static final String DEFAULT_NSX_OFFERING = "DefaultNSXNetworkOffering";
public final static String QuickCloudNoServices = "QuickCloudNoServices";
public final static String DefaultIsolatedNetworkOfferingWithSourceNatService = "DefaultIsolatedNetworkOfferingWithSourceNatService";
public final static String OvsIsolatedNetworkOfferingWithSourceNatService = "OvsIsolatedNetworkOfferingWithSourceNatService";

View File

@ -226,6 +226,11 @@
<artifactId>cloud-plugin-network-tungsten</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-plugin-network-nsx</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-plugin-network-elb</artifactId>

View File

@ -469,6 +469,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
final Map<Network.Service, Set<Network.Provider>> defaultSharedNetworkOfferingProviders = new HashMap<Network.Service, Set<Network.Provider>>();
final Set<Network.Provider> defaultProviders = new HashSet<Network.Provider>();
final Set<Network.Provider> tungstenProvider = new HashSet<>();
final Set<Network.Provider> nsxProvider = new HashSet<>();
defaultProviders.add(Network.Provider.VirtualRouter);
defaultSharedNetworkOfferingProviders.put(Service.Dhcp, defaultProviders);
@ -502,6 +503,12 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
defaultTungstenSharedSGEnabledNetworkOfferingProviders.put(Service.UserData, tungstenProvider);
defaultTungstenSharedSGEnabledNetworkOfferingProviders.put(Service.SecurityGroup, tungstenProvider);
nsxProvider.add(Provider.Nsx);
final Map<Network.Service, Set<Network.Provider>> defaultNSXEnabledNetworkOfferingProviders = new HashMap<>();
defaultNSXEnabledNetworkOfferingProviders.put(Service.Connectivity, nsxProvider);
defaultNSXEnabledNetworkOfferingProviders.put(Service.Dhcp, nsxProvider);
defaultNSXEnabledNetworkOfferingProviders.put(Service.Dns, nsxProvider);
final Map<Network.Service, Set<Network.Provider>> defaultIsolatedSourceNatEnabledNetworkOfferingProviders = new HashMap<Network.Service, Set<Network.Provider>>();
defaultProviders.clear();
defaultProviders.add(Network.Provider.VirtualRouter);
@ -578,6 +585,14 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
defaultVPCOffProviders, true, Network.GuestType.Isolated, false, null, false, null, false, false, null, false, null, true, true, false, null, null, true, null);
}
if (_networkOfferingDao.findByUniqueName(NetworkOffering.DEFAULT_NSX_OFFERING) == null) {
offering = _configMgr.createNetworkOffering(NetworkOffering.DEFAULT_NSX_OFFERING, "Offering for Nsx networks",
TrafficType.Guest, null, false, Availability.Optional, null,
defaultNSXEnabledNetworkOfferingProviders, true, Network.GuestType.Isolated, false, null, false, null, false, false, null, false, null, true, true, false, null, null, true, null);
offering.setState(NetworkOffering.State.Enabled);
_networkOfferingDao.update(offering.getId(), offering);
}
//#6 - default vpc offering with no LB service
if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworksNoLB) == null) {
//remove LB service
@ -3793,8 +3808,8 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
for (final NicVO nic : result) {
if (_networkModel.isProviderForNetwork(Provider.NiciraNvp, nic.getNetworkId())) {
//For NSX Based networks, add nsxlogicalswitch, nsxlogicalswitchport to each result
s_logger.info("Listing NSX logical switch and logical switch por for each nic");
//For Nsx Based networks, add nsxlogicalswitch, nsxlogicalswitchport to each result
s_logger.info("Listing Nsx logical switch and logical switch por for each nic");
final NetworkVO network = _networksDao.findById(nic.getNetworkId());
final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName());
final NetworkGuruAdditionalFunctions guruFunctions = (NetworkGuruAdditionalFunctions) guru;

View File

@ -0,0 +1,32 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>cloud-plugin-network-nsx</artifactId>
<name>Apache CloudStack Plugin - NSX Network</name>
<parent>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloudstack-plugins</artifactId>
<version>4.19.0.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
</project>

View File

@ -0,0 +1,178 @@
package org.apache.cloudstack.service;
import com.cloud.deploy.DeployDestination;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.Network;
import com.cloud.network.PhysicalNetworkServiceProvider;
import com.cloud.network.element.DhcpServiceProvider;
import com.cloud.network.element.DnsServiceProvider;
import com.cloud.offering.NetworkOffering;
import com.cloud.utils.component.AdapterBase;
import com.cloud.vm.NicProfile;
import com.cloud.vm.ReservationContext;
import com.cloud.vm.VirtualMachineProfile;
import org.apache.log4j.Logger;
import javax.naming.ConfigurationException;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class NsxElement extends AdapterBase implements DhcpServiceProvider, DnsServiceProvider {
private static final Logger LOGGER = Logger.getLogger(NsxElement.class);
private final Map<Network.Service, Map<Network.Capability, String>> capabilities = initCapabilities();
private static Map<Network.Service, Map<Network.Capability, String>> initCapabilities() {
Map<Network.Service, Map<Network.Capability, String>> capabilities = new HashMap<>();
Map<Network.Capability, String> dhcpCapabilities = Map.of(Network.Capability.DhcpAccrossMultipleSubnets, "true");
capabilities.put(Network.Service.Dhcp, dhcpCapabilities);
Map<Network.Capability, String> dnsCapabilities = new HashMap<>();
dnsCapabilities.put(Network.Capability.AllowDnsSuffixModification, "true");
capabilities.put(Network.Service.Dns, dnsCapabilities);
capabilities.put(Network.Service.Connectivity, null);
return capabilities;
}
@Override
public boolean addDhcpEntry(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
return true;
}
@Override
public boolean configDhcpSupportForSubnet(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
return true;
}
@Override
public boolean removeDhcpSupportForSubnet(Network network) throws ResourceUnavailableException {
return true;
}
@Override
public boolean setExtraDhcpOptions(Network network, long nicId, Map<Integer, String> dhcpOptions) {
return true;
}
@Override
public boolean removeDhcpEntry(Network network, NicProfile nic, VirtualMachineProfile vmProfile) throws ResourceUnavailableException {
return true;
}
@Override
public boolean addDnsEntry(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
return true;
}
@Override
public boolean configDnsSupportForSubnet(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
return true;
}
@Override
public boolean removeDnsSupportForSubnet(Network network) throws ResourceUnavailableException {
return true;
}
@Override
public Map<Network.Service, Map<Network.Capability, String>> getCapabilities() {
return capabilities;
}
@Override
public Network.Provider getProvider() {
return Network.Provider.Nsx;
}
@Override
public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
return false;
}
@Override
public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
return false;
}
@Override
public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException {
return false;
}
@Override
public boolean shutdown(Network network, ReservationContext context, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException {
return false;
}
@Override
public boolean destroy(Network network, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException {
return false;
}
@Override
public boolean isReady(PhysicalNetworkServiceProvider provider) {
return false;
}
@Override
public boolean shutdownProviderInstances(PhysicalNetworkServiceProvider provider, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException {
return false;
}
@Override
public boolean canEnableIndividualServices() {
return false;
}
@Override
public boolean verifyServicesCombination(Set<Network.Service> services) {
return false;
}
@Override
public String getName() {
return null;
}
@Override
public void setName(String name) {
}
@Override
public void setConfigParams(Map<String, Object> params) {
}
@Override
public Map<String, Object> getConfigParams() {
return null;
}
@Override
public int getRunLevel() {
return 0;
}
@Override
public void setRunLevel(int level) {
}
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
return false;
}
@Override
public boolean start() {
return false;
}
@Override
public boolean stop() {
return false;
}
}

View File

@ -0,0 +1,4 @@
package org.apache.cloudstack.service;
public interface NsxService {
}

View File

@ -0,0 +1,4 @@
package org.apache.cloudstack.service;
public class NsxServiceImpl implements NsxService {
}

View File

@ -0,0 +1,21 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
name=nsx
parent=network

View File

@ -0,0 +1,32 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<bean id="Nsx" class="org.apache.cloudstack.service.NsxElement">
<property name="name" value="NsxElement"/>
</bean>
</beans>

View File

@ -110,6 +110,7 @@
<module>network-elements/brocade-vcs</module>
<module>network-elements/vxlan</module>
<module>network-elements/tungsten</module>
<module>network-elements/nsx</module>
<module>outofbandmanagement-drivers/ipmitool</module>
<module>outofbandmanagement-drivers/nested-cloudstack</module>

View File

@ -4021,6 +4021,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService, C
// Add the config drive provider
addConfigDriveToPhysicalNetwork(pNetwork.getId());
addNSXProviderToPhysicalNetwork(pNetwork.getId());
CallContext.current().putContextParameter(PhysicalNetwork.class, pNetwork.getUuid());
@ -5417,6 +5418,22 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService, C
}
private PhysicalNetworkServiceProvider addNSXProviderToPhysicalNetwork(long physicalNetworkId) {
PhysicalNetworkVO pvo = _physicalNetworkDao.findById(physicalNetworkId);
DataCenterVO dvo = _dcDao.findById(pvo.getDataCenterId());
if (dvo.getNetworkType() == NetworkType.Advanced) {
Provider provider = Network.Provider.getProvider("Nsx");
if (provider == null) {
return null;
}
addProviderToPhysicalNetwork(physicalNetworkId, Provider.Nsx.getName(), null, null);
enableProvider(Provider.Nsx.getName());
}
return null;
}
protected boolean isNetworkSystem(Network network) {
NetworkOffering no = _networkOfferingDao.findByIdIncludingRemoved(network.getNetworkOfferingId());
if (no.isSystemOnly()) {