1
0
mirror of https://github.com/apache/jclouds.git synced 2025-03-08 17:59:46 +00:00

adjusted behavior relating to name/hostname

This commit is contained in:
Adrian Cole 2011-12-01 16:33:19 -05:00
parent dc494414ba
commit d0a2f54cb3
5 changed files with 55 additions and 47 deletions
apis/cloudstack/src
main/java/org/jclouds/cloudstack
test/java/org/jclouds/cloudstack/compute/functions

@ -60,7 +60,7 @@ import com.google.common.util.concurrent.UncheckedExecutionException;
public class VirtualMachineToNodeMetadata implements Function<VirtualMachine, NodeMetadata> { public class VirtualMachineToNodeMetadata implements Function<VirtualMachine, NodeMetadata> {
public static final Map<VirtualMachine.State, NodeState> vmStateToNodeState = ImmutableMap public static final Map<VirtualMachine.State, NodeState> vmStateToNodeState = ImmutableMap
.<VirtualMachine.State, NodeState>builder().put(VirtualMachine.State.STARTING, NodeState.PENDING) .<VirtualMachine.State, NodeState> builder().put(VirtualMachine.State.STARTING, NodeState.PENDING)
.put(VirtualMachine.State.RUNNING, NodeState.RUNNING).put(VirtualMachine.State.STOPPING, NodeState.PENDING) .put(VirtualMachine.State.RUNNING, NodeState.RUNNING).put(VirtualMachine.State.STOPPING, NodeState.PENDING)
.put(VirtualMachine.State.STOPPED, NodeState.SUSPENDED) .put(VirtualMachine.State.STOPPED, NodeState.SUSPENDED)
.put(VirtualMachine.State.DESTROYED, NodeState.TERMINATED) .put(VirtualMachine.State.DESTROYED, NodeState.TERMINATED)
@ -94,7 +94,13 @@ public class VirtualMachineToNodeMetadata implements Function<VirtualMachine, No
NodeMetadataBuilder builder = new NodeMetadataBuilder(); NodeMetadataBuilder builder = new NodeMetadataBuilder();
builder.ids(from.getId() + ""); builder.ids(from.getId() + "");
builder.name(from.getName()); builder.name(from.getName());
builder.hostname(from.getHostname()); // TODO: in cloudstack 2.2.12, when "name" was set fine on the backend,
// but wrong API response was returned to the user
// http://bugs.cloud.com/show_bug.cgi?id=11664
//
// we set displayName to the same value as name, but this could be wrong
// on hosts not started with jclouds
builder.hostname(from.getDisplayName());
builder.location(findLocationForVirtualMachine.apply(from)); builder.location(findLocationForVirtualMachine.apply(from));
builder.group(parseGroupFromName(from.getDisplayName())); builder.group(parseGroupFromName(from.getDisplayName()));
Image image = findImageForVirtualMachine.apply(from); Image image = findImageForVirtualMachine.apply(from);
@ -112,7 +118,7 @@ public class VirtualMachineToNodeMetadata implements Function<VirtualMachine, No
// TODO: check to see public or private // TODO: check to see public or private
if (from.getIPAddress() != null) { if (from.getIPAddress() != null) {
boolean isPrivate = InetAddresses2.isPrivateIPAddress(from.getIPAddress()); boolean isPrivate = InetAddresses2.isPrivateIPAddress(from.getIPAddress());
Set<String> addresses = ImmutableSet.<String>of(from.getIPAddress()); Set<String> addresses = ImmutableSet.<String> of(from.getIPAddress());
if (isPrivate) if (isPrivate)
builder.privateAddresses(addresses); builder.privateAddresses(addresses);
else else
@ -120,14 +126,14 @@ public class VirtualMachineToNodeMetadata implements Function<VirtualMachine, No
} }
try { try {
builder.publicAddresses(transform(filter(getIPForwardingRulesByVirtualMachine.getUnchecked(from.getId()), builder.publicAddresses(transform(
filter(getIPForwardingRulesByVirtualMachine.getUnchecked(from.getId()),
new Predicate<IPForwardingRule>() { new Predicate<IPForwardingRule>() {
@Override @Override
public boolean apply(@Nullable IPForwardingRule rule) { public boolean apply(@Nullable IPForwardingRule rule) {
return !"Deleting".equals(rule.getState()); return !"Deleting".equals(rule.getState());
} }
}), }), new Function<IPForwardingRule, String>() {
new Function<IPForwardingRule, String>() {
@Override @Override
public String apply(@Nullable IPForwardingRule rule) { public String apply(@Nullable IPForwardingRule rule) {
return rule.getIPAddress(); return rule.getIPAddress();

@ -121,8 +121,7 @@ public class CloudStackComputeServiceAdapter implements
CloudStackTemplateOptions templateOptions = template.getOptions().as(CloudStackTemplateOptions.class); CloudStackTemplateOptions templateOptions = template.getOptions().as(CloudStackTemplateOptions.class);
// not all hypervisors support setting name DeployVirtualMachineOptions options = displayName(name).name(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) {

@ -72,7 +72,8 @@ public class CreatePortForwardingRulesForIP {
} }
public Set<IPForwardingRule> apply(PublicIPAddress ip, String protocol, Iterable<Integer> ports) { public Set<IPForwardingRule> apply(PublicIPAddress ip, String protocol, Iterable<Integer> 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) if (Iterables.size(ports) == 0)
return ImmutableSet.<IPForwardingRule> of(); return ImmutableSet.<IPForwardingRule> of();
Builder<AsyncCreateResponse> responses = ImmutableSet.<AsyncCreateResponse> builder(); Builder<AsyncCreateResponse> responses = ImmutableSet.<AsyncCreateResponse> builder();

@ -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 * @param displayName
* an optional user generated name for the virtual machine * 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 * @param name
* host name for the virtual machine * host name for the virtual machine
*/ */
@ -121,15 +128,10 @@ public class DeployVirtualMachineOptions extends AccountInDomainOptions {
*/ */
public DeployVirtualMachineOptions ipsToNetworks(Map<String, Long> ipsToNetworks) { public DeployVirtualMachineOptions ipsToNetworks(Map<String, Long> ipsToNetworks) {
int count = 0; int count = 0;
for(String ip : ipsToNetworks.keySet()) { for (String ip : ipsToNetworks.keySet()) {
this.queryParameters.replaceValues( this.queryParameters.replaceValues(String.format("ipnetworklist[%d].ip", count), ImmutableSet.of(ip));
String.format("ipnetworklist[%d].ip", count), this.queryParameters.replaceValues(String.format("ipnetworklist[%d].networkid", count),
ImmutableSet.of(ip) ImmutableSet.of("" + ipsToNetworks.get(ip)));
);
this.queryParameters.replaceValues(
String.format("ipnetworklist[%d].networkid", count),
ImmutableSet.of("" + ipsToNetworks.get(ip))
);
count += 1; count += 1;
} }
return this; return this;

@ -82,7 +82,7 @@ public class VirtualMachineToNodeMetadataTest {
assertEquals( assertEquals(
node.toString(), node.toString(),
new NodeMetadataBuilder().id("54").providerId("54").name("i-3-54-VM").group("i-3") 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")) .privateAddresses(ImmutableSet.of("10.1.1.18")).publicAddresses(ImmutableSet.of("1.1.1.1"))
.hardware(ServiceOfferingToHardwareTest.one).imageId(TemplateToImageTest.one.getId()) .hardware(ServiceOfferingToHardwareTest.one).imageId(TemplateToImageTest.one.getId())
.operatingSystem(TemplateToImageTest.one.getOperatingSystem()).build().toString()); .operatingSystem(TemplateToImageTest.one.getOperatingSystem()).build().toString());
@ -120,7 +120,7 @@ public class VirtualMachineToNodeMetadataTest {
assertEquals( assertEquals(
node.toString(), node.toString(),
new NodeMetadataBuilder().id("54").providerId("54").name("i-3-54-VM").group("i-3") 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) .privateAddresses(ImmutableSet.of("10.1.1.18")).hardware(ServiceOfferingToHardwareTest.one)
.imageId(TemplateToImageTest.one.getId()) .imageId(TemplateToImageTest.one.getId())
.operatingSystem(TemplateToImageTest.one.getOperatingSystem()).build().toString()); .operatingSystem(TemplateToImageTest.one.getOperatingSystem()).build().toString());