nacx commented on this pull request.


> +         String networkDomainId = server.networkInfo().networkDomainId();
+         final String internalIp = 
server.networkInfo().primaryNic().privateIpv4();
+
+         // delete nat rules associated to the server, if any
+         final NetworkApi networkApi = api.getNetworkApi();
+         List<NatRule> natRulesToBeDeleted = 
networkApi.listNatRules(networkDomainId).concat()
+               .filter(new Predicate<NatRule>() {
+                  @Override
+                  public boolean apply(NatRule natRule) {
+                     return natRule.internalIp().equals(internalIp);
+                  }
+               }).toList();
+
+         for (final NatRule natRule : natRulesToBeDeleted) {
+            if (natRule.state().isNormal()) {
+               networkApi.deleteNatRule(natRule.id());

Calls to the API can fail for a variety of reasons, say there is a conflict, a 
transient, error, whatever unexpected error that makes this raise an 
`HttpResponseException`. The `CleanupServer` is likely to be used when users 
want to destroy nodes and associated resources to "stop paying for them". We 
should be as defensive as possible and try to continue deleting stuff even if 
an unexpected exception occurred when trying to delete intermediate resources.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs/pull/422#discussion_r154615490

Reply via email to