mirror of https://github.com/apache/jclouds.git
adjusted behavior relating to name/hostname
This commit is contained in:
parent
dc494414ba
commit
d0a2f54cb3
|
@ -60,16 +60,16 @@ import com.google.common.util.concurrent.UncheckedExecutionException;
|
|||
public class VirtualMachineToNodeMetadata implements Function<VirtualMachine, NodeMetadata> {
|
||||
|
||||
public static final Map<VirtualMachine.State, NodeState> vmStateToNodeState = ImmutableMap
|
||||
.<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.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)
|
||||
.<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.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<VirtualMachine, No
|
|||
|
||||
@Inject
|
||||
VirtualMachineToNodeMetadata(FindLocationForVirtualMachine findLocationForVirtualMachine,
|
||||
FindHardwareForVirtualMachine findHardwareForVirtualMachine,
|
||||
FindImageForVirtualMachine findImageForVirtualMachine,
|
||||
Cache<Long, Set<IPForwardingRule>> getIPForwardingRulesByVirtualMachine) {
|
||||
FindHardwareForVirtualMachine findHardwareForVirtualMachine,
|
||||
FindImageForVirtualMachine findImageForVirtualMachine,
|
||||
Cache<Long, Set<IPForwardingRule>> 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<VirtualMachine, No
|
|||
NodeMetadataBuilder builder = new NodeMetadataBuilder();
|
||||
builder.ids(from.getId() + "");
|
||||
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.group(parseGroupFromName(from.getDisplayName()));
|
||||
Image image = findImageForVirtualMachine.apply(from);
|
||||
|
@ -112,7 +118,7 @@ public class VirtualMachineToNodeMetadata implements Function<VirtualMachine, No
|
|||
// TODO: check to see public or private
|
||||
if (from.getIPAddress() != null) {
|
||||
boolean isPrivate = InetAddresses2.isPrivateIPAddress(from.getIPAddress());
|
||||
Set<String> addresses = ImmutableSet.<String>of(from.getIPAddress());
|
||||
Set<String> addresses = ImmutableSet.<String> of(from.getIPAddress());
|
||||
if (isPrivate)
|
||||
builder.privateAddresses(addresses);
|
||||
else
|
||||
|
@ -120,19 +126,19 @@ public class VirtualMachineToNodeMetadata implements Function<VirtualMachine, No
|
|||
}
|
||||
try {
|
||||
|
||||
builder.publicAddresses(transform(filter(getIPForwardingRulesByVirtualMachine.getUnchecked(from.getId()),
|
||||
new Predicate<IPForwardingRule>() {
|
||||
@Override
|
||||
public boolean apply(@Nullable IPForwardingRule rule) {
|
||||
return !"Deleting".equals(rule.getState());
|
||||
}
|
||||
}),
|
||||
new Function<IPForwardingRule, String>() {
|
||||
@Override
|
||||
public String apply(@Nullable IPForwardingRule rule) {
|
||||
return rule.getIPAddress();
|
||||
}
|
||||
}));
|
||||
builder.publicAddresses(transform(
|
||||
filter(getIPForwardingRulesByVirtualMachine.getUnchecked(from.getId()),
|
||||
new Predicate<IPForwardingRule>() {
|
||||
@Override
|
||||
public boolean apply(@Nullable IPForwardingRule rule) {
|
||||
return !"Deleting".equals(rule.getState());
|
||||
}
|
||||
}), new Function<IPForwardingRule, String>() {
|
||||
@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<VirtualMachine, No
|
|||
@Override
|
||||
public boolean matches(VirtualMachine from, Image input) {
|
||||
return input.getProviderId().equals(from.getTemplateId() + "")
|
||||
// either location free image (location is null)
|
||||
// or in the same zone as the VM
|
||||
&& (input.getLocation() == null || input.getId().equals(from.getZoneId() + ""));
|
||||
// either location free image (location is null)
|
||||
// or in the same zone as the VM
|
||||
&& (input.getLocation() == null || input.getId().equals(from.getZoneId() + ""));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -121,8 +121,7 @@ public class CloudStackComputeServiceAdapter implements
|
|||
|
||||
CloudStackTemplateOptions templateOptions = template.getOptions().as(CloudStackTemplateOptions.class);
|
||||
|
||||
// not all hypervisors support setting name
|
||||
DeployVirtualMachineOptions options = displayName(name);
|
||||
DeployVirtualMachineOptions options = displayName(name).name(name);
|
||||
if (templateOptions.getSecurityGroupIds().size() > 0) {
|
||||
options.securityGroupIds(templateOptions.getSecurityGroupIds());
|
||||
} else if (templateOptions.getNetworkIds().size() > 0) {
|
||||
|
|
|
@ -72,7 +72,8 @@ public class CreatePortForwardingRulesForIP {
|
|||
}
|
||||
|
||||
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)
|
||||
return ImmutableSet.<IPForwardingRule> of();
|
||||
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
|
||||
* 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<String, Long> 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;
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Reference in New Issue