Add LB service to Custom Netris VPC/Network offerings (#11410)

* Add LB service to Custom VPC/Network offerings

* fix offering

* externalize common checks to a utility file

* remove trailing spaces
This commit is contained in:
Pearl Dsilva 2025-09-16 00:10:33 -04:00 committed by GitHub
parent 9317a46513
commit 23a53e213e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 50 additions and 4 deletions

View File

@ -61,6 +61,10 @@ import static com.cloud.network.Network.Service.NetworkACL;
import static com.cloud.network.Network.Service.UserData;
import static com.cloud.network.Network.Service.Firewall;
import static org.apache.cloudstack.api.command.utils.OfferingUtils.isNetrisNatted;
import static org.apache.cloudstack.api.command.utils.OfferingUtils.isNetrisRouted;
import static org.apache.cloudstack.api.command.utils.OfferingUtils.isNsxWithoutLb;
@APICommand(name = "createNetworkOffering", description = "Creates a network offering.", responseObject = NetworkOfferingResponse.class, since = "3.0.0",
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
public class CreateNetworkOfferingCmd extends BaseCmd {
@ -297,7 +301,7 @@ public class CreateNetworkOfferingCmd extends BaseCmd {
SourceNat.getName(),
PortForwarding.getName()));
}
if (getNsxSupportsLbService()) {
if (getNsxSupportsLbService() || (provider != null && isNetrisNatted(getProvider(), getNetworkMode()))) {
services.add(Lb.getName());
}
if (Boolean.TRUE.equals(forVpc)) {
@ -410,7 +414,7 @@ public class CreateNetworkOfferingCmd extends BaseCmd {
else if (NetworkOffering.NetworkMode.NATTED.name().equalsIgnoreCase(getNetworkMode()) || NetworkACL.getName().equalsIgnoreCase(service)) {
serviceProviderMap.put(service, List.of(provider));
}
if (!getNsxSupportsLbService()) {
if (isNsxWithoutLb(getProvider(), getNsxSupportsLbService()) || isNetrisRouted(getProvider(), getNetworkMode())) {
serviceProviderMap.remove(Lb.getName());
}
}

View File

@ -62,6 +62,10 @@ import static com.cloud.network.Network.Service.NetworkACL;
import static com.cloud.network.Network.Service.UserData;
import static com.cloud.network.Network.Service.Gateway;
import static org.apache.cloudstack.api.command.utils.OfferingUtils.isNetrisNatted;
import static org.apache.cloudstack.api.command.utils.OfferingUtils.isNetrisRouted;
import static org.apache.cloudstack.api.command.utils.OfferingUtils.isNsxWithoutLb;
@APICommand(name = "createVPCOffering", description = "Creates VPC offering", responseObject = VpcOfferingResponse.class,
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
public class CreateVPCOfferingCmd extends BaseAsyncCreateCmd {
@ -194,7 +198,7 @@ public class CreateVPCOfferingCmd extends BaseAsyncCreateCmd {
if (NetworkOffering.NetworkMode.ROUTED.name().equalsIgnoreCase(getNetworkMode())) {
supportedServices.add(Gateway.getName());
}
if (getNsxSupportsLbService()) {
if (getNsxSupportsLbService() || isNetrisNatted(getProvider(), getNetworkMode())) {
supportedServices.add(Lb.getName());
}
}
@ -259,7 +263,7 @@ public class CreateVPCOfferingCmd extends BaseAsyncCreateCmd {
serviceProviderMap.put(service, List.of(provider));
}
}
if (!getNsxSupportsLbService()) {
if ((isNsxWithoutLb(getProvider(), getNsxSupportsLbService())) || isNetrisRouted(getProvider(), getNetworkMode())) {
serviceProviderMap.remove(Lb.getName());
}
}

View File

@ -0,0 +1,38 @@
// 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.
package org.apache.cloudstack.api.command.utils;
import com.cloud.offering.NetworkOffering;
public class OfferingUtils {
private OfferingUtils() {
}
public static boolean isNetrisNatted(String provider, String networkMode) {
return "Netris".equalsIgnoreCase(provider) &&
NetworkOffering.NetworkMode.NATTED.name().equalsIgnoreCase(networkMode);
}
public static boolean isNsxWithoutLb(String provider, boolean nsxSupportsLbService) {
return "Nsx".equalsIgnoreCase(provider) && !nsxSupportsLbService;
}
public static boolean isNetrisRouted(String provider, String networkMode) {
return "Netris".equalsIgnoreCase(provider) && NetworkOffering.NetworkMode.ROUTED.name().equalsIgnoreCase(networkMode);
}
}