NSX: Improve NSX resource cleanup process (#3)

This commit is contained in:
Pearl Dsilva 2024-01-29 10:53:33 -05:00 committed by nvazquez
parent 9313d39315
commit 7c6c9e62ec
No known key found for this signature in database
GPG Key ID: 656E1BCC8CB54F84
2 changed files with 16 additions and 4 deletions

View File

@ -100,6 +100,7 @@ import static org.apache.cloudstack.utils.NsxControllerUtils.getServiceEntryName
import static org.apache.cloudstack.utils.NsxControllerUtils.getLoadBalancerName;
import static org.apache.cloudstack.utils.NsxControllerUtils.getLoadBalancerAlgorithm;
import static org.apache.cloudstack.utils.NsxControllerUtils.getActiveMonitorProfileName;
import static org.apache.cloudstack.utils.NsxControllerUtils.getTier1GatewayName;
public class NsxApiClient {
@ -429,6 +430,10 @@ public class NsxApiClient {
public void deleteSegment(long zoneId, long domainId, long accountId, Long vpcId, long networkId, String segmentName) {
try {
removeSegmentDistributedFirewallRules(segmentName);
if (Objects.isNull(vpcId)) {
String t1GatewayName = getTier1GatewayName(domainId, accountId, zoneId, networkId, false);
deleteLoadBalancer(getLoadBalancerName(t1GatewayName));
}
removeSegment(segmentName);
DhcpRelayConfigs dhcpRelayConfig = (DhcpRelayConfigs) nsxService.apply(DhcpRelayConfigs.class);
String dhcpRelayConfigId = NsxControllerUtils.getNsxDhcpRelayConfigId(zoneId, domainId, accountId, vpcId, networkId);
@ -445,9 +450,15 @@ public class NsxApiClient {
protected void removeSegment(String segmentName) {
LOGGER.debug(String.format("Removing the segment with ID %s", segmentName));
Segments segmentService = (Segments) nsxService.apply(Segments.class);
Segment segment = segmentService.get(segmentName);
if (segment == null) {
LOGGER.error(String.format("The segment with ID %s is not found, skipping removal", segmentName));
String errMsg = String.format("The segment with ID %s is not found, skipping removal", segmentName);
try {
Segment segment = segmentService.get(segmentName);
if (segment == null) {
LOGGER.warn(errMsg);
return;
}
} catch (Exception e) {
LOGGER.warn(errMsg);
return;
}
String siteId = getDefaultSiteId();

View File

@ -732,7 +732,8 @@ public class FirewallManagerImpl extends ManagerBase implements FirewallService,
return;
}
if (NetUtils.ICMP_PROTO.equals(protocol.toLowerCase(Locale.ROOT)) && (rule.getIcmpType() == -1 || rule.getIcmpCode() == -1)) {
if (NetUtils.ICMP_PROTO.equals(protocol.toLowerCase(Locale.ROOT)) && (rule.getIcmpType() == -1 || rule.getIcmpCode() == -1)
&& State.Add.equals(rule.getState())) {
String errorMsg = "Passing -1 for ICMP type is not supported for NSX enabled zones";
s_logger.error(errorMsg);
throw new InvalidParameterValueException(errorMsg);