From d0a2f54cb3aef35d25be9df18ed6c5e97c312b3f Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Thu, 1 Dec 2011 16:33:19 -0500 Subject: [PATCH] adjusted behavior relating to name/hostname --- .../VirtualMachineToNodeMetadata.java | 68 ++++++++++--------- .../CloudStackComputeServiceAdapter.java | 3 +- .../CreatePortForwardingRulesForIP.java | 3 +- .../options/DeployVirtualMachineOptions.java | 24 ++++--- .../VirtualMachineToNodeMetadataTest.java | 4 +- 5 files changed, 55 insertions(+), 47 deletions(-) diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/compute/functions/VirtualMachineToNodeMetadata.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/compute/functions/VirtualMachineToNodeMetadata.java index 54eebb3759..1ad575afbd 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/compute/functions/VirtualMachineToNodeMetadata.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/compute/functions/VirtualMachineToNodeMetadata.java @@ -60,16 +60,16 @@ import com.google.common.util.concurrent.UncheckedExecutionException; public class VirtualMachineToNodeMetadata implements Function { public static final Map vmStateToNodeState = ImmutableMap - .builder().put(VirtualMachine.State.STARTING, NodeState.PENDING) - .put(VirtualMachine.State.RUNNING, NodeState.RUNNING).put(VirtualMachine.State.STOPPING, NodeState.PENDING) - .put(VirtualMachine.State.STOPPED, NodeState.SUSPENDED) - .put(VirtualMachine.State.DESTROYED, NodeState.TERMINATED) - .put(VirtualMachine.State.EXPUNGING, NodeState.TERMINATED) - .put(VirtualMachine.State.MIGRATING, NodeState.PENDING).put(VirtualMachine.State.ERROR, NodeState.ERROR) - .put(VirtualMachine.State.UNKNOWN, NodeState.UNRECOGNIZED) + . builder().put(VirtualMachine.State.STARTING, NodeState.PENDING) + .put(VirtualMachine.State.RUNNING, NodeState.RUNNING).put(VirtualMachine.State.STOPPING, NodeState.PENDING) + .put(VirtualMachine.State.STOPPED, NodeState.SUSPENDED) + .put(VirtualMachine.State.DESTROYED, NodeState.TERMINATED) + .put(VirtualMachine.State.EXPUNGING, NodeState.TERMINATED) + .put(VirtualMachine.State.MIGRATING, NodeState.PENDING).put(VirtualMachine.State.ERROR, NodeState.ERROR) + .put(VirtualMachine.State.UNKNOWN, NodeState.UNRECOGNIZED) // TODO: is this really a state? - .put(VirtualMachine.State.SHUTDOWNED, NodeState.PENDING) - .put(VirtualMachine.State.UNRECOGNIZED, NodeState.UNRECOGNIZED).build(); + .put(VirtualMachine.State.SHUTDOWNED, NodeState.PENDING) + .put(VirtualMachine.State.UNRECOGNIZED, NodeState.UNRECOGNIZED).build(); private final FindLocationForVirtualMachine findLocationForVirtualMachine; private final FindHardwareForVirtualMachine findHardwareForVirtualMachine; @@ -78,14 +78,14 @@ public class VirtualMachineToNodeMetadata implements Function> getIPForwardingRulesByVirtualMachine) { + FindHardwareForVirtualMachine findHardwareForVirtualMachine, + FindImageForVirtualMachine findImageForVirtualMachine, + Cache> getIPForwardingRulesByVirtualMachine) { this.findLocationForVirtualMachine = checkNotNull(findLocationForVirtualMachine, "findLocationForVirtualMachine"); this.findHardwareForVirtualMachine = checkNotNull(findHardwareForVirtualMachine, "findHardwareForVirtualMachine"); this.findImageForVirtualMachine = checkNotNull(findImageForVirtualMachine, "findImageForVirtualMachine"); this.getIPForwardingRulesByVirtualMachine = checkNotNull(getIPForwardingRulesByVirtualMachine, - "getIPForwardingRulesByVirtualMachine"); + "getIPForwardingRulesByVirtualMachine"); } @Override @@ -94,7 +94,13 @@ public class VirtualMachineToNodeMetadata implements Function addresses = ImmutableSet.of(from.getIPAddress()); + Set addresses = ImmutableSet. of(from.getIPAddress()); if (isPrivate) builder.privateAddresses(addresses); else @@ -120,19 +126,19 @@ public class VirtualMachineToNodeMetadata implements Function() { - @Override - public boolean apply(@Nullable IPForwardingRule rule) { - return !"Deleting".equals(rule.getState()); - } - }), - new Function() { - @Override - public String apply(@Nullable IPForwardingRule rule) { - return rule.getIPAddress(); - } - })); + builder.publicAddresses(transform( + filter(getIPForwardingRulesByVirtualMachine.getUnchecked(from.getId()), + new Predicate() { + @Override + public boolean apply(@Nullable IPForwardingRule rule) { + return !"Deleting".equals(rule.getState()); + } + }), new Function() { + @Override + public String apply(@Nullable IPForwardingRule rule) { + return rule.getIPAddress(); + } + })); } catch (UncheckedExecutionException e) { if (Throwables2.getFirstThrowableOfType(e, ResourceNotFoundException.class) == null) { Throwables.propagateIfPossible(e.getCause()); @@ -181,9 +187,9 @@ public class VirtualMachineToNodeMetadata implements Function 0) { options.securityGroupIds(templateOptions.getSecurityGroupIds()); } else if (templateOptions.getNetworkIds().size() > 0) { diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/functions/CreatePortForwardingRulesForIP.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/functions/CreatePortForwardingRulesForIP.java index a34de1c075..8259bed029 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/functions/CreatePortForwardingRulesForIP.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/functions/CreatePortForwardingRulesForIP.java @@ -72,7 +72,8 @@ public class CreatePortForwardingRulesForIP { } public Set apply(PublicIPAddress ip, String protocol, Iterable ports) { - checkState(ip.getVirtualMachineId() != -1, "ip should be static NATed to a virtual machine"); + checkState(ip.getVirtualMachineId() != -1, + "ip %s should be static NATed to a virtual machine before applying rules", ip); if (Iterables.size(ports) == 0) return ImmutableSet. of(); Builder responses = ImmutableSet. builder(); diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/DeployVirtualMachineOptions.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/DeployVirtualMachineOptions.java index 40ef2e9edc..4742afcff0 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/DeployVirtualMachineOptions.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/DeployVirtualMachineOptions.java @@ -62,6 +62,9 @@ public class DeployVirtualMachineOptions extends AccountInDomainOptions { } /** + * sets the displayName - just for display purposes. We don't pass this + * parameter to the backend. + * * @param displayName * an optional user generated name for the virtual machine */ @@ -98,6 +101,10 @@ public class DeployVirtualMachineOptions extends AccountInDomainOptions { } /** + * sets the hostName, it will be propagated down to the backend and set on + * the user vm. If this parameter is not passed it, it will be defaulted to + * our usual "i-x-y' + * * @param name * host name for the virtual machine */ @@ -108,7 +115,7 @@ public class DeployVirtualMachineOptions extends AccountInDomainOptions { /** * @param ipOnDefaultNetwork - * the requested ip address (2.2.12 only option) + * the requested ip address (2.2.12 only option) */ public DeployVirtualMachineOptions ipOnDefaultNetwork(String ipOnDefaultNetwork) { this.queryParameters.replaceValues("ipaddress", ImmutableSet.of(ipOnDefaultNetwork)); @@ -117,19 +124,14 @@ public class DeployVirtualMachineOptions extends AccountInDomainOptions { /** * @param ipsToNetworks - * mapping ip addresses to network ids (2.2.12 only option) + * mapping ip addresses to network ids (2.2.12 only option) */ public DeployVirtualMachineOptions ipsToNetworks(Map ipsToNetworks) { int count = 0; - for(String ip : ipsToNetworks.keySet()) { - this.queryParameters.replaceValues( - String.format("ipnetworklist[%d].ip", count), - ImmutableSet.of(ip) - ); - this.queryParameters.replaceValues( - String.format("ipnetworklist[%d].networkid", count), - ImmutableSet.of("" + ipsToNetworks.get(ip)) - ); + for (String ip : ipsToNetworks.keySet()) { + this.queryParameters.replaceValues(String.format("ipnetworklist[%d].ip", count), ImmutableSet.of(ip)); + this.queryParameters.replaceValues(String.format("ipnetworklist[%d].networkid", count), + ImmutableSet.of("" + ipsToNetworks.get(ip))); count += 1; } return this; diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/functions/VirtualMachineToNodeMetadataTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/functions/VirtualMachineToNodeMetadataTest.java index 0fa4331d21..e666c07c67 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/functions/VirtualMachineToNodeMetadataTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/functions/VirtualMachineToNodeMetadataTest.java @@ -82,7 +82,7 @@ public class VirtualMachineToNodeMetadataTest { assertEquals( node.toString(), new NodeMetadataBuilder().id("54").providerId("54").name("i-3-54-VM").group("i-3") - .location(ZoneToLocationTest.one).state(NodeState.PENDING) + .location(ZoneToLocationTest.one).state(NodeState.PENDING).hostname("i-3-54-VM") .privateAddresses(ImmutableSet.of("10.1.1.18")).publicAddresses(ImmutableSet.of("1.1.1.1")) .hardware(ServiceOfferingToHardwareTest.one).imageId(TemplateToImageTest.one.getId()) .operatingSystem(TemplateToImageTest.one.getOperatingSystem()).build().toString()); @@ -120,7 +120,7 @@ public class VirtualMachineToNodeMetadataTest { assertEquals( node.toString(), new NodeMetadataBuilder().id("54").providerId("54").name("i-3-54-VM").group("i-3") - .location(ZoneToLocationTest.one).state(NodeState.PENDING) + .location(ZoneToLocationTest.one).state(NodeState.PENDING).hostname("i-3-54-VM") .privateAddresses(ImmutableSet.of("10.1.1.18")).hardware(ServiceOfferingToHardwareTest.one) .imageId(TemplateToImageTest.one.getId()) .operatingSystem(TemplateToImageTest.one.getOperatingSystem()).build().toString());