mirror of https://github.com/apache/jclouds.git
Merge pull request #176 from andreisavu/option-for-static-nat
Allow users to disable the creation of a static nat for a new VM
This commit is contained in:
commit
8dd04b5ce5
|
@ -60,6 +60,7 @@ public class CloudStackTemplateOptions extends TemplateOptions implements Clonea
|
|||
protected Map<String, Long> ipsToNetworks = Maps.<String, Long>newLinkedHashMap();
|
||||
protected String ipOnDefaultNetwork;
|
||||
protected String keyPair;
|
||||
protected boolean setupStaticNat = true;
|
||||
|
||||
@Override
|
||||
public CloudStackTemplateOptions clone() {
|
||||
|
@ -118,6 +119,15 @@ public class CloudStackTemplateOptions extends TemplateOptions implements Clonea
|
|||
return networkIds;
|
||||
}
|
||||
|
||||
public CloudStackTemplateOptions setupStaticNat(boolean setupStaticNat) {
|
||||
this.setupStaticNat = setupStaticNat;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean shouldSetupStaticNat() {
|
||||
return this.setupStaticNat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DeployVirtualMachineOptions#ipOnDefaultNetwork
|
||||
*/
|
||||
|
@ -206,6 +216,14 @@ public class CloudStackTemplateOptions extends TemplateOptions implements Clonea
|
|||
return options.ipsToNetworks(ipToNetworkMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CloudStackTemplateOptions#setupStaticNat
|
||||
*/
|
||||
public static CloudStackTemplateOptions setupStaticNat(boolean setupStaticNat) {
|
||||
CloudStackTemplateOptions options = new CloudStackTemplateOptions();
|
||||
return options.setupStaticNat(setupStaticNat);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CloudStackTemplateOptions#keyPair
|
||||
*/
|
||||
|
|
|
@ -168,11 +168,13 @@ public class CloudStackComputeServiceAdapter implements
|
|||
} else {
|
||||
credentials = credentialStore.get("keypair#" + templateOptions.getKeyPair());
|
||||
}
|
||||
if (templateOptions.shouldSetupStaticNat()) {
|
||||
// TODO: possibly not all network ids, do we want to do this
|
||||
for (long networkId : options.getNetworkIds()) {
|
||||
// TODO: log this
|
||||
PublicIPAddress ip = staticNATVMInNetwork.create(networks.get(networkId)).apply(vm);
|
||||
}
|
||||
}
|
||||
return new NodeAndInitialCredentials<VirtualMachine>(vm, vm.getId() + "", credentials);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,10 @@ import static org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions.B
|
|||
import static org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions.Builder.networkIds;
|
||||
import static org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions.Builder.securityGroupId;
|
||||
import static org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions.Builder.securityGroupIds;
|
||||
import static org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions.Builder.setupStaticNat;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import org.jclouds.compute.options.TemplateOptions;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -143,6 +146,26 @@ public class CloudStackTemplateOptionsTest {
|
|||
.getIpsToNetworks().get("10.0.0.1").longValue(), 5L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetupStaticNatDefaultsTrue() {
|
||||
TemplateOptions options = new CloudStackTemplateOptions();
|
||||
assertTrue(options.as(CloudStackTemplateOptions.class)
|
||||
.shouldSetupStaticNat());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetupStaticNat() {
|
||||
TemplateOptions options = new CloudStackTemplateOptions().setupStaticNat(false);
|
||||
assertFalse(options.as(CloudStackTemplateOptions.class)
|
||||
.shouldSetupStaticNat());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetupStaticNatStatic() {
|
||||
TemplateOptions options = setupStaticNat(false);
|
||||
assertFalse(options.as(CloudStackTemplateOptions.class)
|
||||
.shouldSetupStaticNat());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testKeyPair() {
|
||||
|
|
Loading…
Reference in New Issue