Instead of setting up static NAT for all networks, we setup static NAT for default network only

This commit is contained in:
Graeme-Miller 2015-11-19 16:08:43 +00:00 committed by Andrea Turli
parent 4abd5dd16f
commit 75e2c6999c
1 changed files with 26 additions and 18 deletions

View File

@ -42,6 +42,7 @@ import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSet.Builder; import com.google.common.collect.ImmutableSet.Builder;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.google.common.primitives.Ints; import com.google.common.primitives.Ints;
import org.jclouds.cloudstack.CloudStackApi; import org.jclouds.cloudstack.CloudStackApi;
@ -50,6 +51,7 @@ import org.jclouds.cloudstack.domain.AsyncCreateResponse;
import org.jclouds.cloudstack.domain.Capabilities; import org.jclouds.cloudstack.domain.Capabilities;
import org.jclouds.cloudstack.domain.FirewallRule; import org.jclouds.cloudstack.domain.FirewallRule;
import org.jclouds.cloudstack.domain.IPForwardingRule; import org.jclouds.cloudstack.domain.IPForwardingRule;
import org.jclouds.cloudstack.domain.NIC;
import org.jclouds.cloudstack.domain.Network; import org.jclouds.cloudstack.domain.Network;
import org.jclouds.cloudstack.domain.NetworkType; import org.jclouds.cloudstack.domain.NetworkType;
import org.jclouds.cloudstack.domain.Project; import org.jclouds.cloudstack.domain.Project;
@ -274,8 +276,15 @@ public class CloudStackComputeServiceAdapter implements
} }
if (templateOptions.shouldSetupStaticNat()) { if (templateOptions.shouldSetupStaticNat()) {
Capabilities capabilities = client.getConfigurationApi().listCapabilities(); Capabilities capabilities = client.getConfigurationApi().listCapabilities();
// TODO: possibly not all network ids, do we want to do this
for (String networkId : options.getNetworkIds()) { NIC nic = Iterables.find(vm.getNICs(), new Predicate<NIC>() {
@Override
public boolean apply(NIC input) {
return (input == null) ? false : input.isDefault();
}
});
String networkId = nic.getNetworkId();
logger.debug(">> creating static NAT for virtualMachine(%s) in network(%s)", vm.getId(), networkId); logger.debug(">> creating static NAT for virtualMachine(%s) in network(%s)", vm.getId(), networkId);
PublicIPAddress ip = staticNATVMInNetwork.create(networks.get(networkId)).apply(vm); PublicIPAddress ip = staticNATVMInNetwork.create(networks.get(networkId)).apply(vm);
logger.trace("<< static NATed IPAddress(%s) to virtualMachine(%s)", ip.getId(), vm.getId()); logger.trace("<< static NATed IPAddress(%s) to virtualMachine(%s)", ip.getId(), vm.getId());
@ -291,7 +300,6 @@ public class CloudStackComputeServiceAdapter implements
logger.trace("<< setup %d firewall rules on IPAddress(%s)", rules.size(), ip.getId()); logger.trace("<< setup %d firewall rules on IPAddress(%s)", rules.size(), ip.getId());
} }
} }
}
} catch (RuntimeException re) { } catch (RuntimeException re) {
logger.error("-- exception after node has been created, trying to destroy the created virtualMachine(%s)", vm.getId()); logger.error("-- exception after node has been created, trying to destroy the created virtualMachine(%s)", vm.getId());
try { try {