You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by pe...@apache.org on 2023/08/15 11:23:25 UTC
[cloudstack] 01/01: NSX integration - skeletal code
This is an automated email from the ASF dual-hosted git repository.
pearl11594 pushed a commit to branch nsx-integration
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
commit 446dd837a5ea24dff278f20df96659c829211656
Author: Pearl Dsilva <pe...@gmail.com>
AuthorDate: Tue Aug 15 07:23:08 2023 -0400
NSX integration - skeletal code
---
api/src/main/java/com/cloud/network/Network.java | 3 +
.../java/com/cloud/offering/NetworkOffering.java | 1 +
client/pom.xml | 5 +
.../engine/orchestration/NetworkOrchestrator.java | 19 ++-
plugins/network-elements/nsx/pom.xml | 32 ++++
.../org/apache/cloudstack/service/NsxElement.java | 178 +++++++++++++++++++++
.../org/apache/cloudstack/service/NsxService.java | 4 +
.../apache/cloudstack/service/NsxServiceImpl.java | 4 +
.../META-INF.cloudstack.nsx/module.properties | 21 +++
.../META-INF.cloudstack.nsx/spring-nsx-context.xml | 32 ++++
plugins/pom.xml | 1 +
.../java/com/cloud/network/NetworkServiceImpl.java | 17 ++
12 files changed, 315 insertions(+), 2 deletions(-)
diff --git a/api/src/main/java/com/cloud/network/Network.java b/api/src/main/java/com/cloud/network/Network.java
index 458169c80aa..be0753e3e91 100644
--- a/api/src/main/java/com/cloud/network/Network.java
+++ b/api/src/main/java/com/cloud/network/Network.java
@@ -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;
diff --git a/api/src/main/java/com/cloud/offering/NetworkOffering.java b/api/src/main/java/com/cloud/offering/NetworkOffering.java
index 207880ea28c..7f0dc85b05f 100644
--- a/api/src/main/java/com/cloud/offering/NetworkOffering.java
+++ b/api/src/main/java/com/cloud/offering/NetworkOffering.java
@@ -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";
diff --git a/client/pom.xml b/client/pom.xml
index cbe45d88b6c..5c84ce2c02b 100644
--- a/client/pom.xml
+++ b/client/pom.xml
@@ -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>
diff --git a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java
index 4ff295be78a..77b14d31387 100644
--- a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java
+++ b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java
@@ -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;
diff --git a/plugins/network-elements/nsx/pom.xml b/plugins/network-elements/nsx/pom.xml
new file mode 100644
index 00000000000..9350e2aedaf
--- /dev/null
+++ b/plugins/network-elements/nsx/pom.xml
@@ -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>
diff --git a/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/service/NsxElement.java b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/service/NsxElement.java
new file mode 100644
index 00000000000..c6c305c73e9
--- /dev/null
+++ b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/service/NsxElement.java
@@ -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;
+ }
+}
diff --git a/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/service/NsxService.java b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/service/NsxService.java
new file mode 100644
index 00000000000..2782c8f050a
--- /dev/null
+++ b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/service/NsxService.java
@@ -0,0 +1,4 @@
+package org.apache.cloudstack.service;
+
+public interface NsxService {
+}
diff --git a/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/service/NsxServiceImpl.java b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/service/NsxServiceImpl.java
new file mode 100644
index 00000000000..079b35b51f7
--- /dev/null
+++ b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/service/NsxServiceImpl.java
@@ -0,0 +1,4 @@
+package org.apache.cloudstack.service;
+
+public class NsxServiceImpl implements NsxService {
+}
diff --git a/plugins/network-elements/nsx/src/main/resources/META-INF.cloudstack.nsx/module.properties b/plugins/network-elements/nsx/src/main/resources/META-INF.cloudstack.nsx/module.properties
new file mode 100644
index 00000000000..0126f2e007f
--- /dev/null
+++ b/plugins/network-elements/nsx/src/main/resources/META-INF.cloudstack.nsx/module.properties
@@ -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
\ No newline at end of file
diff --git a/plugins/network-elements/nsx/src/main/resources/META-INF.cloudstack.nsx/spring-nsx-context.xml b/plugins/network-elements/nsx/src/main/resources/META-INF.cloudstack.nsx/spring-nsx-context.xml
new file mode 100644
index 00000000000..c7be491e247
--- /dev/null
+++ b/plugins/network-elements/nsx/src/main/resources/META-INF.cloudstack.nsx/spring-nsx-context.xml
@@ -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>
diff --git a/plugins/pom.xml b/plugins/pom.xml
index d0661c01a2c..bc28c777db7 100755
--- a/plugins/pom.xml
+++ b/plugins/pom.xml
@@ -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>
diff --git a/server/src/main/java/com/cloud/network/NetworkServiceImpl.java b/server/src/main/java/com/cloud/network/NetworkServiceImpl.java
index ac698f69689..c527e6af9a4 100644
--- a/server/src/main/java/com/cloud/network/NetworkServiceImpl.java
+++ b/server/src/main/java/com/cloud/network/NetworkServiceImpl.java
@@ -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()) {