mirror of https://github.com/apache/jclouds.git
Instead of setting up static NAT for all networks, we setup static NAT for default network only
This commit is contained in:
parent
4abd5dd16f
commit
75e2c6999c
|
@ -42,6 +42,7 @@ import com.google.common.cache.LoadingCache;
|
|||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSet.Builder;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.common.primitives.Ints;
|
||||
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.FirewallRule;
|
||||
import org.jclouds.cloudstack.domain.IPForwardingRule;
|
||||
import org.jclouds.cloudstack.domain.NIC;
|
||||
import org.jclouds.cloudstack.domain.Network;
|
||||
import org.jclouds.cloudstack.domain.NetworkType;
|
||||
import org.jclouds.cloudstack.domain.Project;
|
||||
|
@ -273,24 +275,30 @@ public class CloudStackComputeServiceAdapter implements
|
|||
vm = client.getVirtualMachineApi().getVirtualMachine(vm.getId());
|
||||
}
|
||||
if (templateOptions.shouldSetupStaticNat()) {
|
||||
Capabilities capabilities = client.getConfigurationApi().listCapabilities();
|
||||
// TODO: possibly not all network ids, do we want to do this
|
||||
for (String networkId : options.getNetworkIds()) {
|
||||
logger.debug(">> creating static NAT for virtualMachine(%s) in network(%s)", vm.getId(), networkId);
|
||||
PublicIPAddress ip = staticNATVMInNetwork.create(networks.get(networkId)).apply(vm);
|
||||
logger.trace("<< static NATed IPAddress(%s) to virtualMachine(%s)", ip.getId(), vm.getId());
|
||||
vm = client.getVirtualMachineApi().getVirtualMachine(vm.getId());
|
||||
List<Integer> ports = Ints.asList(templateOptions.getInboundPorts());
|
||||
if (capabilities.getCloudStackVersion().startsWith("2")) {
|
||||
logger.debug(">> setting up IP forwarding for IPAddress(%s) rules(%s)", ip.getId(), ports);
|
||||
Set<IPForwardingRule> rules = setupPortForwardingRulesForIP.apply(ip, ports);
|
||||
logger.trace("<< setup %d IP forwarding rules on IPAddress(%s)", rules.size(), ip.getId());
|
||||
} else {
|
||||
logger.debug(">> setting up firewall rules for IPAddress(%s) rules(%s)", ip.getId(), ports);
|
||||
Set<FirewallRule> rules = setupFirewallRulesForIP.apply(ip, ports);
|
||||
logger.trace("<< setup %d firewall rules on IPAddress(%s)", rules.size(), ip.getId());
|
||||
}
|
||||
}
|
||||
Capabilities capabilities = client.getConfigurationApi().listCapabilities();
|
||||
|
||||
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);
|
||||
PublicIPAddress ip = staticNATVMInNetwork.create(networks.get(networkId)).apply(vm);
|
||||
logger.trace("<< static NATed IPAddress(%s) to virtualMachine(%s)", ip.getId(), vm.getId());
|
||||
vm = client.getVirtualMachineApi().getVirtualMachine(vm.getId());
|
||||
List<Integer> ports = Ints.asList(templateOptions.getInboundPorts());
|
||||
if (capabilities.getCloudStackVersion().startsWith("2")) {
|
||||
logger.debug(">> setting up IP forwarding for IPAddress(%s) rules(%s)", ip.getId(), ports);
|
||||
Set<IPForwardingRule> rules = setupPortForwardingRulesForIP.apply(ip, ports);
|
||||
logger.trace("<< setup %d IP forwarding rules on IPAddress(%s)", rules.size(), ip.getId());
|
||||
} else {
|
||||
logger.debug(">> setting up firewall rules for IPAddress(%s) rules(%s)", ip.getId(), ports);
|
||||
Set<FirewallRule> rules = setupFirewallRulesForIP.apply(ip, ports);
|
||||
logger.trace("<< setup %d firewall rules on IPAddress(%s)", rules.size(), ip.getId());
|
||||
}
|
||||
}
|
||||
} catch (RuntimeException re) {
|
||||
logger.error("-- exception after node has been created, trying to destroy the created virtualMachine(%s)", vm.getId());
|
||||
|
|
Loading…
Reference in New Issue