fix missing name in cloudstack and also disable static nat on destroy

This commit is contained in:
Adrian Cole 2011-11-15 18:29:38 +02:00
parent 2d31d6db23
commit 1f304ededb
2 changed files with 20 additions and 12 deletions

View File

@ -23,6 +23,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Throwables.propagate; import static com.google.common.base.Throwables.propagate;
import static com.google.common.collect.Iterables.filter; import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.getOnlyElement; import static com.google.common.collect.Iterables.getOnlyElement;
import static org.jclouds.cloudstack.options.DeployVirtualMachineOptions.Builder.name;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
@ -36,6 +37,7 @@ import org.jclouds.cloudstack.CloudStackClient;
import org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions; import org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions;
import org.jclouds.cloudstack.domain.AsyncCreateResponse; import org.jclouds.cloudstack.domain.AsyncCreateResponse;
import org.jclouds.cloudstack.domain.AsyncJob; import org.jclouds.cloudstack.domain.AsyncJob;
import org.jclouds.cloudstack.domain.IPForwardingRule;
import org.jclouds.cloudstack.domain.Network; import org.jclouds.cloudstack.domain.Network;
import org.jclouds.cloudstack.domain.PublicIPAddress; import org.jclouds.cloudstack.domain.PublicIPAddress;
import org.jclouds.cloudstack.domain.ServiceOffering; import org.jclouds.cloudstack.domain.ServiceOffering;
@ -100,7 +102,7 @@ public class CloudStackComputeServiceAdapter implements
CloudStackTemplateOptions templateOptions = template.getOptions().as(CloudStackTemplateOptions.class); CloudStackTemplateOptions templateOptions = template.getOptions().as(CloudStackTemplateOptions.class);
DeployVirtualMachineOptions options = new DeployVirtualMachineOptions(); DeployVirtualMachineOptions options = name(name);
if (templateOptions.getSecurityGroupIds().size() > 0) { if (templateOptions.getSecurityGroupIds().size() > 0) {
options.securityGroupIds(templateOptions.getSecurityGroupIds()); options.securityGroupIds(templateOptions.getSecurityGroupIds());
} else if (templateOptions.getNetworkIds().size() > 0) { } else if (templateOptions.getNetworkIds().size() > 0) {
@ -196,22 +198,29 @@ public class CloudStackComputeServiceAdapter implements
@Override @Override
public void destroyNode(String id) { public void destroyNode(String id) {
long guestId = Long.parseLong(id); long guestId = Long.parseLong(id);
client.getVirtualMachineClient().destroyVirtualMachine(guestId); Long job = client.getVirtualMachineClient().destroyVirtualMachine(guestId);
boolean completed = jobComplete.apply(job);
IPForwardingRule forwardingRule = client.getNATClient().getIPForwardingRuleForVirtualMachine(guestId);
if (forwardingRule != null)
client.getNATClient().disableStaticNat(forwardingRule.getIPAddressId());
} }
@Override @Override
public void rebootNode(String id) { public void rebootNode(String id) {
client.getVirtualMachineClient().rebootVirtualMachine(Long.parseLong(id)); Long job = client.getVirtualMachineClient().rebootVirtualMachine(Long.parseLong(id));
boolean completed = jobComplete.apply(job);
} }
@Override @Override
public void resumeNode(String id) { public void resumeNode(String id) {
client.getVirtualMachineClient().startVirtualMachine(Long.parseLong(id)); Long job = client.getVirtualMachineClient().startVirtualMachine(Long.parseLong(id));
boolean completed = jobComplete.apply(job);
} }
@Override @Override
public void suspendNode(String id) { public void suspendNode(String id) {
client.getVirtualMachineClient().stopVirtualMachine(Long.parseLong(id)); Long job = client.getVirtualMachineClient().stopVirtualMachine(Long.parseLong(id));
boolean completed = jobComplete.apply(job);
} }
} }

View File

@ -142,8 +142,7 @@ public class CloudStackComputeServiceAdapterLiveTest extends BaseCloudStackClien
new DefaultCredentialsFromImageOrOverridingCredentials()); new DefaultCredentialsFromImageOrOverridingCredentials());
@Test @Test
public void testCreateNodeWithGroupEncodedIntoName() public void testCreateNodeWithGroupEncodedIntoName() throws InterruptedException {
throws InterruptedException {
String group = "foo"; String group = "foo";
String name = "node" + new Random().nextInt(); String name = "node" + new Random().nextInt();
Template template = computeContext.getComputeService().templateBuilder().build(); Template template = computeContext.getComputeService().templateBuilder().build();
@ -158,8 +157,7 @@ public class CloudStackComputeServiceAdapterLiveTest extends BaseCloudStackClien
} }
vm = adapter.createNodeWithGroupEncodedIntoName(group, name, template); vm = adapter.createNodeWithGroupEncodedIntoName(group, name, template);
// TODO: check vm name - it should contain the group assertEquals(vm.getNode().getName(), name);
// check to see if we setup a NAT rule (conceding we could check this from // check to see if we setup a NAT rule (conceding we could check this from
// cache) // cache)
IPForwardingRule rule = client.getNATClient().getIPForwardingRuleForVirtualMachine(vm.getNode().getId()); IPForwardingRule rule = client.getNATClient().getIPForwardingRuleForVirtualMachine(vm.getNode().getId());
@ -187,14 +185,15 @@ public class CloudStackComputeServiceAdapterLiveTest extends BaseCloudStackClien
} }
private void connectWithRetry(SshClient ssh, int times, int delayInMilli) { private void connectWithRetry(SshClient ssh, int times, int delayInMilli) {
for(int i=0; i<times; i++) { for (int i = 0; i < times; i++) {
try { try {
ssh.connect(); ssh.connect();
break; break;
} catch(SshException e) { } catch (SshException e) {
try { try {
Thread.sleep(delayInMilli); Thread.sleep(delayInMilli);
} catch (InterruptedException e1) {} } catch (InterruptedException e1) {
}
} }
} }
} }