mirror of https://github.com/apache/jclouds.git
name field isn't always settable, switch to displayName
This commit is contained in:
parent
d53d473481
commit
122338ba6a
|
@ -96,7 +96,7 @@ public class VirtualMachineToNodeMetadata implements Function<VirtualMachine, No
|
||||||
builder.name(from.getName());
|
builder.name(from.getName());
|
||||||
builder.hostname(from.getHostname());
|
builder.hostname(from.getHostname());
|
||||||
builder.location(findLocationForVirtualMachine.apply(from));
|
builder.location(findLocationForVirtualMachine.apply(from));
|
||||||
builder.group(parseGroupFromName(from.getHostname()));
|
builder.group(parseGroupFromName(from.getDisplayName()));
|
||||||
Image image = findImageForVirtualMachine.apply(from);
|
Image image = findImageForVirtualMachine.apply(from);
|
||||||
if (image != null) {
|
if (image != null) {
|
||||||
builder.imageId(image.getId());
|
builder.imageId(image.getId());
|
||||||
|
|
|
@ -20,10 +20,13 @@ package org.jclouds.cloudstack.compute.strategy;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkArgument;
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static com.google.common.base.Predicates.and;
|
||||||
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 static org.jclouds.cloudstack.options.DeployVirtualMachineOptions.Builder.displayName;
|
||||||
|
import static org.jclouds.cloudstack.predicates.NetworkPredicates.supportsStaticNAT;
|
||||||
|
import static org.jclouds.cloudstack.predicates.TemplatePredicates.isReady;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
@ -47,7 +50,6 @@ import org.jclouds.cloudstack.domain.Zone;
|
||||||
import org.jclouds.cloudstack.functions.StaticNATVirtualMachineInNetwork;
|
import org.jclouds.cloudstack.functions.StaticNATVirtualMachineInNetwork;
|
||||||
import org.jclouds.cloudstack.functions.StaticNATVirtualMachineInNetwork.Factory;
|
import org.jclouds.cloudstack.functions.StaticNATVirtualMachineInNetwork.Factory;
|
||||||
import org.jclouds.cloudstack.options.DeployVirtualMachineOptions;
|
import org.jclouds.cloudstack.options.DeployVirtualMachineOptions;
|
||||||
import org.jclouds.cloudstack.predicates.TemplatePredicates;
|
|
||||||
import org.jclouds.collect.Memoized;
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.compute.ComputeService;
|
import org.jclouds.compute.ComputeService;
|
||||||
import org.jclouds.compute.ComputeServiceAdapter;
|
import org.jclouds.compute.ComputeServiceAdapter;
|
||||||
|
@ -102,21 +104,22 @@ public class CloudStackComputeServiceAdapter implements
|
||||||
|
|
||||||
CloudStackTemplateOptions templateOptions = template.getOptions().as(CloudStackTemplateOptions.class);
|
CloudStackTemplateOptions templateOptions = template.getOptions().as(CloudStackTemplateOptions.class);
|
||||||
|
|
||||||
DeployVirtualMachineOptions options = name(name);
|
// not all hypervisors support setting name
|
||||||
|
DeployVirtualMachineOptions options = displayName(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) {
|
||||||
options.networkIds(templateOptions.getNetworkIds());
|
options.networkIds(templateOptions.getNetworkIds());
|
||||||
} else if (networks.size() > 0) {
|
} else if (networks.size() > 0) {
|
||||||
try {
|
try {
|
||||||
options.networkId(getOnlyElement(filter(networks.values(), new Predicate<Network>() {
|
options.networkId(getOnlyElement(filter(networks.values(), and(new Predicate<Network>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Network arg0) {
|
public boolean apply(Network arg0) {
|
||||||
return arg0.getZoneId() == zoneId && arg0.isDefault();
|
return arg0.getZoneId() == zoneId && arg0.isDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
})).getId());
|
}, supportsStaticNAT()))).getId());
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
throw new IllegalArgumentException("please choose a specific network in zone " + zoneId + ": " + networks);
|
throw new IllegalArgumentException("please choose a specific network in zone " + zoneId + ": " + networks);
|
||||||
}
|
}
|
||||||
|
@ -175,7 +178,7 @@ public class CloudStackComputeServiceAdapter implements
|
||||||
public Iterable<Template> listImages() {
|
public Iterable<Template> listImages() {
|
||||||
// TODO: we may need to filter these further
|
// TODO: we may need to filter these further
|
||||||
// we may also want to see if we can work with ssh keys
|
// we may also want to see if we can work with ssh keys
|
||||||
return filter(client.getTemplateClient().listTemplates(), TemplatePredicates.isReady());
|
return filter(client.getTemplateClient().listTemplates(), isReady());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -143,8 +143,8 @@ public class CloudStackComputeServiceAdapterLiveTest extends BaseCloudStackClien
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateNodeWithGroupEncodedIntoName() throws InterruptedException {
|
public void testCreateNodeWithGroupEncodedIntoName() throws InterruptedException {
|
||||||
String group = "foo";
|
String group = prefix + "#foo";
|
||||||
String name = "node" + new Random().nextInt();
|
String name = group + "#node#" + new Random().nextInt();
|
||||||
Template template = computeContext.getComputeService().templateBuilder().build();
|
Template template = computeContext.getComputeService().templateBuilder().build();
|
||||||
|
|
||||||
if (!client
|
if (!client
|
||||||
|
@ -157,7 +157,7 @@ public class CloudStackComputeServiceAdapterLiveTest extends BaseCloudStackClien
|
||||||
}
|
}
|
||||||
vm = adapter.createNodeWithGroupEncodedIntoName(group, name, template);
|
vm = adapter.createNodeWithGroupEncodedIntoName(group, name, template);
|
||||||
|
|
||||||
assertEquals(vm.getNode().getName(), name);
|
assertEquals(vm.getNode().getDisplayName(), 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());
|
||||||
|
|
Loading…
Reference in New Issue