This commit is contained in:
Pearl Dsilva 2024-02-27 15:53:07 -05:00
parent 4a56dbba92
commit 3e8bb8d8f8
2 changed files with 5 additions and 2 deletions

View File

@ -387,7 +387,8 @@ public class NsxResource implements ServerResource {
String privatePort = cmd.getPrivatePort();
String service = privatePort.contains("-") ? nsxApiClient.getServicePath(ruleName, privatePort, cmd.getProtocol(), null, null) :
nsxApiClient.getNsxInfraServices(ruleName, privatePort, cmd.getProtocol(), null, null);
if (nsxApiClient.doesPfRuleExist(ruleName, tier1GatewayName, cmd.getNetworkResourceName())) {
if (nsxApiClient.doesPfRuleExist(ruleName, tier1GatewayName)) {
LOGGER.debug(String.format("Port forward rule for port: %s exits on NSX, not adding it again", privatePort));
return new NsxAnswer(cmd, true, null);
}
nsxApiClient.createPortForwardingRule(ruleName, tier1GatewayName, cmd.getNetworkResourceName(), cmd.getPublicIp(),

View File

@ -572,12 +572,13 @@ public class NsxApiClient {
}
}
public boolean doesPfRuleExist(String ruleName, String tier1GatewayName, String networkName) {
public boolean doesPfRuleExist(String ruleName, String tier1GatewayName) {
try {
NatRules natService = (NatRules) nsxService.apply(NatRules.class);
PolicyNatRule rule = natService.get(tier1GatewayName, NAT_ID, ruleName);
return !Objects.isNull(rule);
} catch (Error error) {
LOGGER.debug(String.format("Found a port forward rule named: %s on NSX", ruleName));
return false;
}
}
@ -781,6 +782,7 @@ public class NsxApiClient {
return lbVirtualServer;
}
} catch (Exception e) {
LOGGER.debug(String.format("Found an LB virtual server named: %s on NSX", lbVSName));
return null;
}
return null;