Merge branch 'master' of https://github.com/jclouds/jclouds into vbox-cleanup

This commit is contained in:
Mattias Holmqvist 2011-11-24 21:56:34 +01:00
commit 2c2eadc2e0
58 changed files with 3637 additions and 413 deletions

1
.gitignore vendored
View File

@ -8,6 +8,7 @@ bin/
.project
.idea/
*.iml
*.eml
*.ipr
*.iws
TAGS

View File

@ -22,12 +22,14 @@ import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import com.google.common.collect.ImmutableSet;
import org.jclouds.cloudstack.CloudStackAsyncClient;
import org.jclouds.cloudstack.CloudStackClient;
import org.jclouds.cloudstack.compute.functions.ServiceOfferingToHardware;
@ -104,8 +106,8 @@ public class CloudStackComputeServiceContextModule
bind(new TypeLiteral<Function<Template, OperatingSystem>>() {
}).to(TemplateToOperatingSystem.class);
install(new FactoryModuleBuilder().build(StaticNATVirtualMachineInNetwork.Factory.class));
bind(new TypeLiteral<CacheLoader<Long, IPForwardingRule>>() {
}).to(GetIPForwardingRuleByVirtualMachine.class);
bind(new TypeLiteral<CacheLoader<Long, Set<IPForwardingRule>>>() {
}).to(GetIPForwardingRulesByVirtualMachine.class);
}
@Provides
@ -171,17 +173,17 @@ public class CloudStackComputeServiceContextModule
@Provides
@Singleton
protected Cache<Long, IPForwardingRule> getIPForwardingRuleByVirtualMachine(
CacheLoader<Long, IPForwardingRule> getIPForwardingRule) {
return CacheBuilder.newBuilder().build(getIPForwardingRule);
protected Cache<Long, Set<IPForwardingRule>> getIPForwardingRulesByVirtualMachine(
CacheLoader<Long, Set<IPForwardingRule>> getIPForwardingRules) {
return CacheBuilder.newBuilder().build(getIPForwardingRules);
}
@Singleton
public static class GetIPForwardingRuleByVirtualMachine extends CacheLoader<Long, IPForwardingRule> {
public static class GetIPForwardingRulesByVirtualMachine extends CacheLoader<Long, Set<IPForwardingRule>> {
private final CloudStackClient client;
@Inject
public GetIPForwardingRuleByVirtualMachine(CloudStackClient client) {
public GetIPForwardingRulesByVirtualMachine(CloudStackClient client) {
this.client = checkNotNull(client, "client");
}
@ -190,11 +192,9 @@ public class CloudStackComputeServiceContextModule
* when there is no ip forwarding rule available for the VM
*/
@Override
public IPForwardingRule load(Long input) {
IPForwardingRule rule = client.getNATClient().getIPForwardingRuleForVirtualMachine(input);
if (rule == null)
throw new ResourceNotFoundException("no ip forwarding rule for: " + input);
return rule;
public Set<IPForwardingRule> load(Long input) {
Set<IPForwardingRule> rules = client.getNATClient().getIPForwardingRulesForVirtualMachine(input);
return rules != null ? rules : ImmutableSet.<IPForwardingRule>of();
}
}

View File

@ -19,14 +19,19 @@
package org.jclouds.cloudstack.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.transform;
import static org.jclouds.compute.util.ComputeServiceUtils.parseGroupFromName;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Singleton;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import org.jclouds.cloudstack.domain.IPForwardingRule;
import org.jclouds.cloudstack.domain.VirtualMachine;
import org.jclouds.collect.FindResourceInSet;
@ -56,7 +61,7 @@ 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)
.<VirtualMachine.State, NodeState>builder().put(VirtualMachine.State.STARTING, NodeState.PENDING)
.put(VirtualMachine.State.RUNNING, NodeState.RUNNING).put(VirtualMachine.State.STOPPING, NodeState.SUSPENDED)
.put(VirtualMachine.State.STOPPED, NodeState.PENDING)
.put(VirtualMachine.State.DESTROYED, NodeState.TERMINATED)
@ -70,18 +75,18 @@ public class VirtualMachineToNodeMetadata implements Function<VirtualMachine, No
private final FindLocationForVirtualMachine findLocationForVirtualMachine;
private final FindHardwareForVirtualMachine findHardwareForVirtualMachine;
private final FindImageForVirtualMachine findImageForVirtualMachine;
private final Cache<Long, IPForwardingRule> getIPForwardingRuleByVirtualMachine;
private final Cache<Long, Set<IPForwardingRule>> getIPForwardingRulesByVirtualMachine;
@Inject
VirtualMachineToNodeMetadata(FindLocationForVirtualMachine findLocationForVirtualMachine,
FindHardwareForVirtualMachine findHardwareForVirtualMachine,
FindImageForVirtualMachine findImageForVirtualMachine,
Cache<Long, IPForwardingRule> getIPForwardingRuleByVirtualMachine) {
Cache<Long, Set<IPForwardingRule>> getIPForwardingRulesByVirtualMachine) {
this.findLocationForVirtualMachine = checkNotNull(findLocationForVirtualMachine, "findLocationForVirtualMachine");
this.findHardwareForVirtualMachine = checkNotNull(findHardwareForVirtualMachine, "findHardwareForVirtualMachine");
this.findImageForVirtualMachine = checkNotNull(findImageForVirtualMachine, "findImageForVirtualMachine");
this.getIPForwardingRuleByVirtualMachine = checkNotNull(getIPForwardingRuleByVirtualMachine,
"getIPForwardingRuleByVirtualMachine");
this.getIPForwardingRulesByVirtualMachine = checkNotNull(getIPForwardingRulesByVirtualMachine,
"getIPForwardingRulesByVirtualMachine");
}
@Override
@ -108,15 +113,27 @@ 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
builder.publicAddresses(addresses);
}
try {
IPForwardingRule rule = getIPForwardingRuleByVirtualMachine.getUnchecked(from.getId());
builder.publicAddresses(ImmutableSet.<String> of(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());

View File

@ -29,6 +29,7 @@ import static org.jclouds.cloudstack.predicates.NetworkPredicates.supportsStatic
import static org.jclouds.cloudstack.predicates.TemplatePredicates.isReady;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import javax.annotation.Resource;
@ -214,9 +215,11 @@ public class CloudStackComputeServiceAdapter implements
long guestId = Long.parseLong(id);
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());
Set<IPForwardingRule> forwardingRules = client.getNATClient().getIPForwardingRulesForVirtualMachine(guestId);
for(IPForwardingRule rule : forwardingRules) {
job = client.getNATClient().deleteIPForwardingRule(rule.getId());
jobComplete.apply(job);
}
}
@Override

View File

@ -18,6 +18,7 @@
*/
package org.jclouds.cloudstack.domain;
import com.google.common.base.Objects;
import com.google.gson.annotations.SerializedName;
import java.util.Date;
@ -151,6 +152,11 @@ public class TemplateExtraction implements Comparable<TemplateExtraction> {
return this;
}
public TemplateExtraction build() {
return new TemplateExtraction(id, accountId, created, extractId,
extractMode, name, state, status, storageType, uploadPercentage,
url,zoneId, zoneName);
}
}
private long id;
@ -169,9 +175,33 @@ public class TemplateExtraction implements Comparable<TemplateExtraction> {
private String url;
@SerializedName("zoneid")
private long zoneId;
/**
* Construct a new TemplateExtraction instance
*/
public TemplateExtraction(long id, long accountId, Date created, long extractId,
ExtractMode extractMode, String name, String state, String status,
String storageType, int uploadPercentage, String url,
long zoneId, String zoneName) {
this.id = id;
this.accountId = accountId;
this.created = created;
this.extractId = extractId;
this.extractMode = extractMode;
this.name = name;
this.state = state;
this.status = status;
this.storageType = storageType;
this.uploadPercentage = uploadPercentage;
this.url = url;
this.zoneId = zoneId;
this.zoneName = zoneName;
}
@SerializedName("zonename")
private String zoneName;
/**
* present only for serializer
*/
@ -270,23 +300,48 @@ public class TemplateExtraction implements Comparable<TemplateExtraction> {
}
@Override
public boolean equals(Object o) {
throw new RuntimeException("FIXME: Implement me");
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
TemplateExtraction other = (TemplateExtraction) obj;
return id == other.id
&& accountId == other.accountId
&& Objects.equal(created, other.created)
&& extractId == other.extractId
&& Objects.equal(extractMode, other.extractMode)
&& Objects.equal(name, other.name)
&& Objects.equal(state, other.state)
&& Objects.equal(status, other.status)
&& Objects.equal(storageType, other.storageType)
&& uploadPercentage == other.uploadPercentage
&& Objects.equal(url, other.url)
&& zoneId == other.zoneId
&& Objects.equal(zoneName, other.zoneName);
}
@Override
public int hashCode() {
throw new RuntimeException("FIXME: Implement me");
return Objects.hashCode(id, accountId, created, extractId, extractMode,
name, state, status, storageType, uploadPercentage, url, zoneId, zoneName);
}
@Override
public String toString() {
throw new RuntimeException("FIXME: Implement me");
return "[id=" + id + ", accountId=" + accountId + ", created=" + created
+ ", extractId=" + extractId + ", extractMode=" + extractMode
+ ", name=" + name + ", state=" + state + ", status=" + status
+ ", storageType=" + storageType + ", uploadPercentage=" + uploadPercentage
+ ", url=" + url + ", zoneId=" + zoneId + ", zoneName=" + zoneName;
}
@Override
public int compareTo(TemplateExtraction other) {
throw new RuntimeException("FIXME: Implement me");
return new Long(id).compareTo(other.id);
}
}

View File

@ -78,26 +78,24 @@ public interface NATAsyncClient {
ListenableFuture<IPForwardingRule> getIPForwardingRule(@QueryParam("id") long id);
/**
* @see NATClient#getIPForwardingRuleForIPAddress
* @see NATClient#getIPForwardingRulesForIPAddress
*/
@GET
@QueryParams(keys = "command", values = "listIpForwardingRules")
@SelectJson("ipforwardingrule")
@OnlyElement
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<IPForwardingRule> getIPForwardingRuleForIPAddress(@QueryParam("ipaddressid") long id);
ListenableFuture<Set<IPForwardingRule>> getIPForwardingRulesForIPAddress(@QueryParam("ipaddressid") long id);
/**
* @see NATClient#getIPForwardingRuleForVirtualMachine
* @see NATClient#getIPForwardingRulesForVirtualMachine
*/
@GET
@QueryParams(keys = "command", values = "listIpForwardingRules")
@SelectJson("ipforwardingrule")
@OnlyElement
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<IPForwardingRule> getIPForwardingRuleForVirtualMachine(@QueryParam("virtualmachineid") long id);
ListenableFuture<Set<IPForwardingRule>> getIPForwardingRulesForVirtualMachine(@QueryParam("virtualmachineid") long id);
/**
* @see NATClient#createIPForwardingRule

View File

@ -59,22 +59,22 @@ public interface NATClient {
IPForwardingRule getIPForwardingRule(long id);
/**
* get a specific IPForwardingRule by ipaddress id
* get a set of IPForwardingRules by ipaddress id
*
* @param id
* IPAddress of rule to get
* @return IPForwardingRule or null if not found
* @return IPForwardingRule matching query or empty if not found
*/
IPForwardingRule getIPForwardingRuleForIPAddress(long id);
Set<IPForwardingRule> getIPForwardingRulesForIPAddress(long id);
/**
* get a specific IPForwardingRule by virtual machine id
* get a set of IPForwardingRules by virtual machine id
*
* @param id
* virtual machine of rule to get
* @return IPForwardingRule or null if not found
* @return IPForwardingRule matching query or empty set if not found
*/
IPForwardingRule getIPForwardingRuleForVirtualMachine(long id);
Set<IPForwardingRule> getIPForwardingRulesForVirtualMachine(long id);
/**
* Creates an ip forwarding rule

View File

@ -80,6 +80,7 @@ public interface SnapshotAsyncClient {
@GET
@Consumes(MediaType.APPLICATION_JSON)
@QueryParams(keys = "command", values = "listSnapshots")
@SelectJson("snapshot")
@Unwrap
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<Set<Snapshot>> listSnapshots(ListSnapshotsOptions... options);
@ -162,5 +163,4 @@ public interface SnapshotAsyncClient {
@Unwrap
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<Set<SnapshotPolicy>> listSnapshotPolicies(@QueryParam("volumeid") long volumeId, ListSnapshotPoliciesOptions... options);
}

View File

@ -29,12 +29,9 @@ import org.jclouds.cloudstack.domain.AsyncCreateResponse;
import org.jclouds.cloudstack.domain.Volume;
import org.jclouds.cloudstack.filters.QuerySigner;
import org.jclouds.cloudstack.options.ListVolumesOptions;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.QueryParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.Unwrap;
import org.jclouds.rest.annotations.*;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
/**
@ -58,6 +55,17 @@ public interface VolumeAsyncClient {
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<Set<Volume>> listVolumes(ListVolumesOptions... options);
/**
* @see VolumeClient#getVolume(long)
*/
@GET
@Consumes(MediaType.APPLICATION_JSON)
@QueryParams(keys = "command", values = "listVolumes")
@SelectJson("volume")
@OnlyElement
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Volume> getVolume(@QueryParam("id") long id);
/**
* @see VolumeClient#createVolumeFromDiskOfferingInZone(String, long, long)

View File

@ -59,10 +59,18 @@ public interface VolumeClient {
/**
* List volumes
*
* @return volume list or null if not found
* @return volume list, empty if not found
*/
Set<Volume> listVolumes(ListVolumesOptions... options);
/**
* Get volume by id
*
* @param id the volume id to retrieve
* @return volume or null if not found
*/
Volume getVolume(long id);
/**
* Deletes a attached disk volume
*

View File

@ -24,6 +24,7 @@ import static com.google.common.base.Preconditions.checkState;
import javax.inject.Inject;
import javax.inject.Singleton;
import com.google.common.collect.ImmutableSet;
import org.jclouds.cloudstack.CloudStackClient;
import org.jclouds.cloudstack.domain.AsyncCreateResponse;
import org.jclouds.cloudstack.domain.AsyncJob;
@ -37,6 +38,8 @@ import com.google.common.base.Predicate;
import com.google.common.cache.Cache;
import com.google.inject.assistedinject.Assisted;
import java.util.Set;
/**
*
* @author Adrian Cole
@ -51,17 +54,17 @@ public class StaticNATVirtualMachineInNetwork implements Function<VirtualMachine
private final ReuseOrAssociateNewPublicIPAddress reuseOrAssociate;
private final Network network;
private final Predicate<Long> jobComplete;
private final Cache<Long, IPForwardingRule> getIPForwardingRuleByVirtualMachine;
private final Cache<Long, Set<IPForwardingRule>> getIPForwardingRulesByVirtualMachine;
@Inject
public StaticNATVirtualMachineInNetwork(CloudStackClient client,
ReuseOrAssociateNewPublicIPAddress reuseOrAssociate, Predicate<Long> jobComplete,
Cache<Long, IPForwardingRule> getIPForwardingRuleByVirtualMachine, @Assisted Network network) {
Cache<Long, Set<IPForwardingRule>> getIPForwardingRulesByVirtualMachine, @Assisted Network network) {
this.client = checkNotNull(client, "client");
this.reuseOrAssociate = checkNotNull(reuseOrAssociate, "reuseOrAssociate");
this.jobComplete = checkNotNull(jobComplete, "jobComplete");
this.getIPForwardingRuleByVirtualMachine = checkNotNull(getIPForwardingRuleByVirtualMachine,
"getIPForwardingRuleByVirtualMachine");
this.getIPForwardingRulesByVirtualMachine = checkNotNull(getIPForwardingRulesByVirtualMachine,
"getIPForwardingRulesByVirtualMachine");
this.network = checkNotNull(network, "network");
}
@ -86,7 +89,7 @@ public class StaticNATVirtualMachineInNetwork implements Function<VirtualMachine
checkState(jobComplete.apply(job.getJobId()), "Timeout creating IP forwarding rule: ", job);
AsyncJob<IPForwardingRule> response = client.getAsyncJobClient().getAsyncJob(job.getJobId());
checkState(response.getResult() != null, "No result after creating IP forwarding rule: ", response);
getIPForwardingRuleByVirtualMachine.asMap().put(vm.getId(), response.getResult());
getIPForwardingRulesByVirtualMachine.asMap().put(vm.getId(), ImmutableSet.of(response.getResult()));
return ip;
}
}

View File

@ -18,6 +18,7 @@
*/
package org.jclouds.cloudstack.compute;
import static com.google.common.collect.Iterables.getFirst;
import static com.google.inject.name.Names.bindProperties;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
@ -26,12 +27,13 @@ import static org.testng.Assert.fail;
import java.io.IOException;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import javax.inject.Singleton;
import org.jclouds.cloudstack.CloudStackClient;
import org.jclouds.cloudstack.compute.config.CloudStackComputeServiceContextModule.GetIPForwardingRuleByVirtualMachine;
import org.jclouds.cloudstack.compute.config.CloudStackComputeServiceContextModule.GetIPForwardingRulesByVirtualMachine;
import org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions;
import org.jclouds.cloudstack.compute.strategy.CloudStackComputeServiceAdapter;
import org.jclouds.cloudstack.domain.IPForwardingRule;
@ -117,8 +119,8 @@ public class CloudStackComputeServiceAdapterLiveTest extends BaseCloudStackClien
@SuppressWarnings("unused")
@Provides
@Singleton
protected Cache<Long, IPForwardingRule> getIPForwardingRuleByVirtualMachine(
GetIPForwardingRuleByVirtualMachine getIPForwardingRule) {
protected Cache<Long, Set<IPForwardingRule>> getIPForwardingRuleByVirtualMachine(
GetIPForwardingRulesByVirtualMachine getIPForwardingRule) {
return CacheBuilder.newBuilder().build(getIPForwardingRule);
}
};
@ -160,7 +162,8 @@ public class CloudStackComputeServiceAdapterLiveTest extends BaseCloudStackClien
assertEquals(vm.getNode().getDisplayName(), name);
// check to see if we setup a NAT rule (conceding we could check this from
// cache)
IPForwardingRule rule = client.getNATClient().getIPForwardingRuleForVirtualMachine(vm.getNode().getId());
IPForwardingRule rule = getFirst(
client.getNATClient().getIPForwardingRulesForVirtualMachine(vm.getNode().getId()), null);
String address = rule != null ? rule.getIPAddress() : vm.getNode().getIPAddress();

View File

@ -64,12 +64,12 @@ public class VirtualMachineToNodeMetadataTest {
.<Image> of(TemplateToImageTest.one, TemplateToImageTest.two));
VirtualMachineToNodeMetadata parser = new VirtualMachineToNodeMetadata(new FindLocationForVirtualMachine(
locationSupplier), new FindHardwareForVirtualMachine(hardwareSupplier), new FindImageForVirtualMachine(
imageSupplier), CacheBuilder.newBuilder().<Long, IPForwardingRule> build(
new CacheLoader<Long, IPForwardingRule>() {
imageSupplier), CacheBuilder.newBuilder().<Long, Set<IPForwardingRule>> build(
new CacheLoader<Long, Set<IPForwardingRule>>() {
@Override
public IPForwardingRule load(Long arg0) throws Exception {
return IPForwardingRule.builder().id(1234l).IPAddress("1.1.1.1").build();
public Set<IPForwardingRule> load(Long arg0) throws Exception {
return ImmutableSet.of(IPForwardingRule.builder().id(1234l).IPAddress("1.1.1.1").build());
}
}));
@ -102,11 +102,11 @@ public class VirtualMachineToNodeMetadataTest {
.<Image> of(TemplateToImageTest.one, TemplateToImageTest.two));
VirtualMachineToNodeMetadata parser = new VirtualMachineToNodeMetadata(new FindLocationForVirtualMachine(
locationSupplier), new FindHardwareForVirtualMachine(hardwareSupplier), new FindImageForVirtualMachine(
imageSupplier), CacheBuilder.newBuilder().<Long, IPForwardingRule> build(
new CacheLoader<Long, IPForwardingRule>() {
imageSupplier), CacheBuilder.newBuilder().<Long, Set<IPForwardingRule>> build(
new CacheLoader<Long, Set<IPForwardingRule>>() {
@Override
public IPForwardingRule load(Long arg0) throws Exception {
public Set<IPForwardingRule> load(Long arg0) throws Exception {
throw new ResourceNotFoundException("no ip forwarding rule for: " + arg0);
}

View File

@ -115,7 +115,7 @@ public class NetworkClientLiveTest extends BaseCloudStackClientLiveTest {
.getNetworkClient()
// startIP/endIP/netmask/gateway must be specified together
.createNetworkInZone(zone.getId(), offering.getId(), name, name,
vlan("2").startIP("192.168.1.2").netmask("255.255.255.0").gateway("192.168.1.1"));
vlan("65").startIP("192.168.1.2").netmask("255.255.255.0").gateway("192.168.1.1"));
checkNetwork(network);
} catch (IllegalStateException e) {
Logger.getAnonymousLogger().log(Level.SEVERE, "couldn't create a network, skipping test", e);
@ -173,7 +173,7 @@ public class NetworkClientLiveTest extends BaseCloudStackClientLiveTest {
break;
case DIRECT:
// TODO: I've found a network that doesn't have a netmask associated
// assert network.getNetmask() != null : network;
assert network.getNetmask() != null : network;
assert network.getGateway() != null : network;
assert network.getVLAN() != null : network;
assertEquals(network.getBroadcastURI(), URI.create("vlan://" + network.getVLAN()));

View File

@ -18,9 +18,8 @@
*/
package org.jclouds.cloudstack.features;
import com.google.common.base.Functions;
import com.google.common.collect.ImmutableSet;
import com.google.inject.TypeLiteral;
import java.lang.reflect.Method;
import org.jclouds.cloudstack.domain.Snapshot;
import org.jclouds.cloudstack.domain.SnapshotPolicySchedule;
import org.jclouds.cloudstack.options.CreateSnapshotOptions;
@ -29,6 +28,7 @@ import org.jclouds.cloudstack.options.ListSnapshotsOptions;
import org.jclouds.cloudstack.util.SnapshotPolicySchedules;
import org.jclouds.functions.IdentityFunction;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
import org.jclouds.http.functions.ReleasePayloadAndReturn;
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
@ -38,7 +38,9 @@ import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test;
import java.lang.reflect.Method;
import com.google.common.base.Functions;
import com.google.common.collect.ImmutableSet;
import com.google.inject.TypeLiteral;
/**
* Tests the behaviour of SnapshotAsyncClient.
@ -92,7 +94,7 @@ public class SnapshotAsyncClientTest extends BaseCloudStackAsyncClientTest<Snaps
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyJsonValue.class);
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
@ -125,7 +127,7 @@ public class SnapshotAsyncClientTest extends BaseCloudStackAsyncClientTest<Snaps
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyJsonValue.class);
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);

View File

@ -0,0 +1,149 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.cloudstack.features;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import org.jclouds.cloudstack.domain.AsyncCreateResponse;
import org.jclouds.cloudstack.domain.Snapshot;
import org.jclouds.cloudstack.domain.Volume;
import org.jclouds.cloudstack.domain.Zone;
import org.jclouds.cloudstack.options.ListSnapshotsOptions;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import javax.annotation.Nullable;
import java.util.Set;
import static com.google.common.collect.Iterables.find;
import static org.testng.AssertJUnit.*;
/**
* Tests behavior of {@code SnapshotClient}
*
* @author grkvlt@apache.org
*/
@Test(groups = "live", singleThreaded = true, testName = "SnapshotClientLiveTest")
public class SnapshotClientLiveTest extends BaseCloudStackClientLiveTest {
protected String prefix = System.getProperty("user.name");
private long zoneId;
@BeforeMethod(groups = "live")
public void setZoneId() {
Set<Zone> zones = client.getZoneClient().listZones();
assertNotNull(zones);
assertFalse(zones.isEmpty());
zoneId = Iterables.get(zones, 0).getId();
}
public void testListSnapshots() {
Set<Snapshot> snapshots = client.getSnapshotClient().listSnapshots();
assertNotNull(snapshots);
assertFalse(snapshots.isEmpty());
for (Snapshot snapshot : snapshots) {
checkSnapshot(snapshot);
}
}
public void testListSnapshotsById() {
Iterable<Long> snapshotIds = Iterables.transform(client.getSnapshotClient().listSnapshots(), new Function<Snapshot, Long>() {
public Long apply(Snapshot input) {
return input.getId();
}
});
assertNotNull(snapshotIds);
assertFalse(Iterables.isEmpty(snapshotIds));
for (Long id : snapshotIds) {
Set<Snapshot> found = client.getSnapshotClient().listSnapshots(ListSnapshotsOptions.Builder.id(id));
assertNotNull(found);
assertEquals(1, found.size());
Snapshot snapshot = Iterables.getOnlyElement(found);
assertEquals(id.longValue(), snapshot.getId());
checkSnapshot(snapshot);
}
}
public void testListSnapshotsNonexistantId() {
Set<Snapshot> found = client.getSnapshotClient().listSnapshots(ListSnapshotsOptions.Builder.id(-1));
assertNotNull(found);
assertTrue(found.isEmpty());
}
public void testGetSnapshotById() {
Iterable<Long> snapshotIds = Iterables.transform(client.getSnapshotClient().listSnapshots(), new Function<Snapshot, Long>() {
public Long apply(Snapshot input) {
return input.getId();
}
});
assertNotNull(snapshotIds);
assertFalse(Iterables.isEmpty(snapshotIds));
for (Long id : snapshotIds) {
Snapshot found = client.getSnapshotClient().getSnapshot(id);
assertNotNull(found);
assertEquals(id.longValue(), found.getId());
checkSnapshot(found);
}
}
public void testGetSnapshotNonexistantId() {
Snapshot found = client.getSnapshotClient().getSnapshot(-1);
assertNull(found);
}
public void testCreateSnapshotFromVolume() {
// Pick some volume
long volumeId = Iterables.get(client.getVolumeClient().listVolumes(), 0).getId();
Snapshot snapshot = null;
while (snapshot == null) {
try {
AsyncCreateResponse job = client.getSnapshotClient().createSnapshot(volumeId);
assertTrue(jobComplete.apply(job.getJobId()));
snapshot = findSnapshotWithId(job.getId());
} catch (IllegalStateException e) {
// TODO snapshot creation failed - retry?
}
}
checkSnapshot(snapshot);
// Delete the snapshot
client.getSnapshotClient().deleteSnapshot(snapshot.getId());
}
private void checkSnapshot(final Snapshot snapshot) {
assertNotNull(snapshot.getId());
assertNotNull(snapshot.getName());
assertNotSame(Snapshot.Type.UNRECOGNIZED, snapshot.getSnapshotType());
}
private Snapshot findSnapshotWithId(final long id) {
return find(client.getSnapshotClient().listSnapshots(), new Predicate<Snapshot>() {
@Override
public boolean apply(Snapshot arg0) {
return arg0.getId() == id;
}
});
}
}

View File

@ -48,6 +48,7 @@ public class TemplateClientLiveTest extends BaseCloudStackClientLiveTest {
private VirtualMachine vm;
private Template template;
@Test
public void testListTemplates() throws Exception {
Set<Template> response = client.getTemplateClient().listTemplates();
assert null != response;
@ -56,6 +57,8 @@ public class TemplateClientLiveTest extends BaseCloudStackClientLiveTest {
for (Template template : response) {
Template newDetails = Iterables.getOnlyElement(client.getTemplateClient().listTemplates(
zoneId(template.getZoneId()).id(template.getId())));
Logger.CONSOLE.info("Checking template: " + template);
assertEquals(template, newDetails);
assertEquals(template, client.getTemplateClient().getTemplateInZone(template.getId(), template.getZoneId()));
assert template.getId() > 0 : template;
@ -68,7 +71,8 @@ public class TemplateClientLiveTest extends BaseCloudStackClientLiveTest {
assert template.getAccount() != null : template;
assert template.getZone() != null : template;
assert template.getZoneId() > 0 : template;
assert template.getStatus() == null : template;
assert (template.getStatus() == null ||
template.getStatus().equals("Download Complete")) : template;
assert template.getType() != null && template.getType() != Template.Type.UNRECOGNIZED : template;
assert template.getHypervisor() != null : template;
assert template.getDomain() != null : template;
@ -112,19 +116,6 @@ public class TemplateClientLiveTest extends BaseCloudStackClientLiveTest {
assertNotNull(template);
}
@AfterGroups(groups = "live")
protected void tearDown() {
if (vm != null) {
assert jobComplete.apply(client.getVirtualMachineClient().stopVirtualMachine(vm.getId())) : vm;
assert jobComplete.apply(client.getVirtualMachineClient().destroyVirtualMachine(vm.getId())) : vm;
assert virtualMachineDestroyed.apply(vm);
}
if (template != null) {
client.getTemplateClient().deleteTemplate(template.getId());
}
super.tearDown();
}
@Test(enabled = true, dependsOnMethods = "testCreateTemplate")
public void testExtractTemplate() throws Exception {
// Initiate the extraction and wait for it to complete
@ -185,4 +176,19 @@ public class TemplateClientLiveTest extends BaseCloudStackClientLiveTest {
vm = VirtualMachineClientLiveTest.createVirtualMachineInNetwork(network, template.getId(), client, jobComplete, virtualMachineRunning);
assertNotNull(vm);
}
@AfterGroups(groups = "live")
protected void tearDown() {
if (vm != null) {
assert jobComplete.apply(client.getVirtualMachineClient().stopVirtualMachine(vm.getId())) : vm;
assert jobComplete.apply(client.getVirtualMachineClient().destroyVirtualMachine(vm.getId())) : vm;
assert virtualMachineDestroyed.apply(vm);
}
if (template != null) {
client.getTemplateClient().deleteTemplate(template.getId());
}
super.tearDown();
}
}

View File

@ -25,6 +25,7 @@ import com.google.inject.TypeLiteral;
import org.jclouds.cloudstack.options.ListVolumesOptions;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test;
@ -55,6 +56,22 @@ public class VolumeAsyncClientTest extends BaseCloudStackAsyncClientTest<VolumeA
}
public void testGetVolume() throws SecurityException, NoSuchMethodException, IOException {
Method method = VolumeAsyncClient.class.getMethod("getVolume", long.class);
HttpRequest httpRequest = processor.createRequest(method, 111L);
assertRequestLineEquals(httpRequest,
"GET http://localhost:8080/client/api?response=json&command=listVolumes&id=111 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpRequest);
}
public void testCreateVolumeWithSnapshot() throws SecurityException, NoSuchMethodException, IOException {
Method method = VolumeAsyncClient.class.getMethod("createVolumeFromSnapshotInZone", String.class, long.class,
long.class);
@ -119,10 +136,10 @@ public class VolumeAsyncClientTest extends BaseCloudStackAsyncClientTest<VolumeA
public void testDeleteVolume() throws SecurityException, NoSuchMethodException, IOException {
Method method = VolumeAsyncClient.class.getMethod("deleteVolume", long.class);
HttpRequest httpRequest = processor.createRequest(method, "jclouds-volume");
HttpRequest httpRequest = processor.createRequest(method, 111L);
assertRequestLineEquals(httpRequest,
"GET http://localhost:8080/client/api?response=json&command=deleteVolume&id=jclouds-volume HTTP/1.1");
"GET http://localhost:8080/client/api?response=json&command=deleteVolume&id=111 HTTP/1.1");
assertPayloadEquals(httpRequest, null, null, false);
assertSaxResponseParserClassEquals(method, null);

View File

@ -18,103 +18,160 @@
*/
package org.jclouds.cloudstack.features;
import static com.google.common.collect.Iterables.find;
import static org.testng.AssertJUnit.assertNotNull;
import static org.testng.AssertJUnit.assertNotSame;
import static com.google.common.collect.Iterables.*;
import static org.testng.AssertJUnit.*;
import java.util.Set;
import com.google.common.base.Function;
import org.jclouds.cloudstack.domain.AsyncCreateResponse;
import org.jclouds.cloudstack.domain.Snapshot;
import org.jclouds.cloudstack.domain.Volume;
import org.jclouds.cloudstack.domain.Zone;
import org.jclouds.cloudstack.options.ListVolumesOptions;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
/**
* Tests behavior of {@code SSHKeyPairClient}
* Tests behavior of {@code VolumeClient}
*
* @author Vijay Kiran
*/
@Test(groups = "live", singleThreaded = true, testName = "VolumeClientLiveTest")
public class VolumeClientLiveTest extends BaseCloudStackClientLiveTest {
protected String prefix = System.getProperty("user.name");
private long zoneId;
private long diskOfferingId;
private long snapshotId;
private Volume volume;
@BeforeMethod(groups = "live")
public void setZoneId() {
Set<Zone> zones = client.getZoneClient().listZones();
assertNotNull(zones);
assertFalse(zones.isEmpty());
zoneId = Iterables.get(zones, 0).getId();
}
public void testListVolumes() {
final Set<Volume> volumes = client.getVolumeClient().listVolumes();
Set<Volume> volumes = client.getVolumeClient().listVolumes();
assertNotNull(volumes);
assertFalse(volumes.isEmpty());
for (Volume volume : volumes) {
checkVolume(volume);
}
}
public void testListVolumesById() {
Iterable<Long> volumeIds = Iterables.transform(client.getVolumeClient().listVolumes(), new Function<Volume, Long>() {
public Long apply(Volume input) {
return input.getId();
}
});
assertNotNull(volumeIds);
assertFalse(Iterables.isEmpty(volumeIds));
for (Long id : volumeIds) {
Set<Volume> found = client.getVolumeClient().listVolumes(ListVolumesOptions.Builder.id(id));
assertNotNull(found);
assertEquals(1, found.size());
Volume volume = Iterables.getOnlyElement(found);
assertEquals(id.longValue(), volume.getId());
checkVolume(volume);
}
}
public void testListVolumesNonexistantId() {
Set<Volume> found = client.getVolumeClient().listVolumes(ListVolumesOptions.Builder.id(-1));
assertNotNull(found);
assertTrue(found.isEmpty());
}
public void testGetVolumeById() {
Iterable<Long> volumeIds = Iterables.transform(client.getVolumeClient().listVolumes(), new Function<Volume, Long>() {
public Long apply(Volume input) {
return input.getId();
}
});
assertNotNull(volumeIds);
assertFalse(Iterables.isEmpty(volumeIds));
for (Long id : volumeIds) {
Volume found = client.getVolumeClient().getVolume(id);
assertNotNull(found);
assertEquals(id.longValue(), found.getId());
checkVolume(found);
}
}
public void testGetVolumeNonexistantId() {
Volume found = client.getVolumeClient().getVolume(-1);
assertNull(found);
}
public void testCreateVolumeFromDiskofferingInZoneAndDeleteVolume() {
// Pick some disk offering
long diskOfferingId = Iterables.get(client.getOfferingClient().listDiskOfferings(), 0).getId();
zoneId = Iterables.getFirst(client.getZoneClient().listZones(), null).getId();
//Pick some disk offering
diskOfferingId = Iterables.getFirst(client.getOfferingClient().listDiskOfferings(), null).getId();
Volume volume = null;
while (volume == null) {
try {
AsyncCreateResponse job = client.getVolumeClient().createVolumeFromDiskOfferingInZone(prefix + "-jclouds-volume",
diskOfferingId, zoneId);
assert jobComplete.apply(job.getJobId());
assertTrue(jobComplete.apply(job.getJobId()));
volume = findVolumeWithId(job.getId());
} catch (IllegalStateException e) {
//TODO volume creation failed - retry?
// TODO volume creation failed - retry?
}
}
checkVolume(volume);
//Delete the volume
// Delete the volume
client.getVolumeClient().deleteVolume(volume.getId());
}
public void testCreateVolumeFromDiskofferingInZoneAndAttachVolumeToVirtualMachineAndDetachAndDelete() {
// Pick some disk offering
long diskOfferingId = Iterables.get(client.getOfferingClient().listDiskOfferings(), 0).getId();
zoneId = Iterables.getFirst(client.getZoneClient().listZones(), null).getId();
//Pick some disk offering
diskOfferingId = Iterables.getFirst(client.getOfferingClient().listDiskOfferings(), null).getId();
Volume volume = null;
while (volume == null) {
try {
AsyncCreateResponse job = client.getVolumeClient().createVolumeFromDiskOfferingInZone(prefix + "-jclouds-volume",
diskOfferingId, zoneId);
assert jobComplete.apply(job.getJobId());
assertTrue(jobComplete.apply(job.getJobId()));
volume = findVolumeWithId(job.getId());
} catch (IllegalStateException e) {
//TODO volume creation failed - retry?
// TODO volume creation failed - retry?
}
}
checkVolume(volume);
long virtualMachineId = Iterables.getFirst(client.getVirtualMachineClient().listVirtualMachines(), null).getId();
//Attach Volume
long virtualMachineId = Iterables.get(client.getVirtualMachineClient().listVirtualMachines(), 0).getId();
// Attach Volume
Volume attachedVolume = null;
while (attachedVolume == null) {
try {
AsyncCreateResponse job = client.getVolumeClient().attachVolume(volume.getId(), virtualMachineId);
assert jobComplete.apply(job.getJobId());
assertTrue(jobComplete.apply(job.getJobId()));
attachedVolume = findVolumeWithId(volume.getId());
assert attachedVolume.getVirtualMachineId() == virtualMachineId;
assert attachedVolume.getAttached() != null;
assertEquals(virtualMachineId, attachedVolume.getVirtualMachineId());
assertNotNull(attachedVolume.getAttached());
} catch (IllegalStateException e) {
//TODO volume creation failed - retry?
// TODO volume creation failed - retry?
}
}
//Detach Volume
// Detach Volume
Volume detachedVolume = null;
while (detachedVolume == null) {
try {
AsyncCreateResponse job = client.getVolumeClient().detachVolume(volume.getId());
assert jobComplete.apply(job.getJobId());
assertTrue(jobComplete.apply(job.getJobId()));
detachedVolume = findVolumeWithId(volume.getId());
checkVolume(detachedVolume);
} catch (IllegalStateException e) {
@ -122,37 +179,33 @@ public class VolumeClientLiveTest extends BaseCloudStackClientLiveTest {
}
}
//Cleanup
// Cleanup
client.getVolumeClient().deleteVolume(volume.getId());
}
/*
TODO Uncomment this test after SnapshotClient has test coverage.
public void testCreateVolumeFromSnapshotInZoneAndDeleteVolume() {
zoneId = Iterables.getFirst(client.getZoneClient().listZones(), null).getId();
final Set<Snapshot> snapshots = client.getSnapshotClient().listSnapshots();
Set<Snapshot> snapshots = client.getSnapshotClient().listSnapshots();
assertNotNull(snapshots);
assertNotSame(0, snapshots.size() );
snapshotId = Iterables.getFirst(snapshots, null).getId();
assertFalse(snapshots.isEmpty());
long snapshotId = Iterables.get(snapshots, 0).getId();
Volume volume = null;
while (volume == null) {
try {
AsyncCreateResponse job = client.getVolumeClient().createVolumeFromSnapshotInZone(prefix + "-jclouds-volume",
snapshotId, zoneId);
assert jobComplete.apply(job.getJobId());
assertTrue(jobComplete.apply(job.getJobId()));
volume = findVolumeWithId(job.getId());
} catch (IllegalStateException e) {
//TODO volume creation failed - retry?
// TODO volume creation failed - retry?
}
}
checkVolume(volume);
//Delete the volume
// Delete the volume
client.getVolumeClient().deleteVolume(volume.getId());
}
*/
private void checkVolume(final Volume volume) {
assertNotNull(volume.getId());
@ -162,13 +215,10 @@ public class VolumeClientLiveTest extends BaseCloudStackClientLiveTest {
private Volume findVolumeWithId(final long id) {
return find(client.getVolumeClient().listVolumes(), new Predicate<Volume>() {
@Override
public boolean apply(Volume arg0) {
return arg0.getId() == id;
}
});
}
}

View File

@ -18,12 +18,16 @@
*/
package org.jclouds.cloudstack.functions;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.find;
import static com.google.common.collect.Iterables.getOnlyElement;
import static org.testng.Assert.assertEquals;
import java.util.NoSuchElementException;
import java.util.Set;
import org.jclouds.cloudstack.compute.config.CloudStackComputeServiceContextModule.GetIPForwardingRuleByVirtualMachine;
import com.google.common.base.Predicate;
import org.jclouds.cloudstack.compute.config.CloudStackComputeServiceContextModule.GetIPForwardingRulesByVirtualMachine;
import org.jclouds.cloudstack.domain.IPForwardingRule;
import org.jclouds.cloudstack.domain.Network;
import org.jclouds.cloudstack.domain.PublicIPAddress;
@ -41,6 +45,8 @@ import org.testng.annotations.Test;
import com.google.common.cache.CacheBuilder;
import javax.annotation.Nullable;
/**
* Tests behavior of {@code StaticNATVirtualMachineInNetwork}
*
@ -75,9 +81,15 @@ public class StaticNATVirtualMachineInNetworkLiveTest extends NATClientLiveTest
if (networksDisabled)
return;
ip = new StaticNATVirtualMachineInNetwork(client, reuseOrAssociate, jobComplete, CacheBuilder.newBuilder()
.<Long, IPForwardingRule> build(new GetIPForwardingRuleByVirtualMachine(client)), network).apply(vm);
.<Long, Set<IPForwardingRule>>build(new GetIPForwardingRulesByVirtualMachine(client)), network).apply(vm);
rule = client.getNATClient().getIPForwardingRuleForIPAddress(ip.getId());
rule = getOnlyElement(filter(client.getNATClient().getIPForwardingRulesForIPAddress(ip.getId()),
new Predicate<IPForwardingRule>() {
@Override
public boolean apply(@Nullable IPForwardingRule rule) {
return rule != null && rule.getStartPort() == 22;
}
}));
assertEquals(rule.getIPAddressId(), ip.getId());
assertEquals(rule.getVirtualMachineId(), vm.getId());
assertEquals(rule.getStartPort(), 22);

View File

@ -0,0 +1,134 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.tmrk.enterprisecloud.domain;
import javax.xml.bind.annotation.XmlElement;
/**
* <xs:complexType name="ConfigurationOptionRange">
* @author Jason King
*/
public class ConfigurationOptionRange {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
public Builder toBuilder() {
return new Builder().fromConfigurationOptionRange(this);
}
public static class Builder {
private int minimum;
private int maximum;
private int stepFactor;
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.ConfigurationOptionRange#getMinimum
*/
public Builder minimum(int minimum) {
this.minimum = minimum;
return this;
}
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.ConfigurationOptionRange#getMaximum
*/
public Builder maximum(int maximum) {
this.maximum = maximum;
return this;
}
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.ConfigurationOptionRange#getStepFactor
*/
public Builder stepFactor(int stepFactor) {
this.stepFactor = stepFactor;
return this;
}
public ConfigurationOptionRange build() {
return new ConfigurationOptionRange(minimum, maximum,stepFactor);
}
public Builder fromConfigurationOptionRange(ConfigurationOptionRange in) {
return minimum(in.getMinimum()).maximum(in.getMaximum()).stepFactor(in.getStepFactor());
}
}
@XmlElement(name = "Minimum")
private int minimum;
@XmlElement(name = "Maximum")
private int maximum;
@XmlElement(name = "StepFactor")
private int stepFactor;
private ConfigurationOptionRange(int minimum, int maximum, int stepFactor) {
this.minimum = minimum;
this.maximum = maximum;
this.stepFactor = stepFactor;
}
private ConfigurationOptionRange() {
//For JAXB
}
public int getMinimum() {
return minimum;
}
public int getMaximum() {
return maximum;
}
public int getStepFactor() {
return stepFactor;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ConfigurationOptionRange that = (ConfigurationOptionRange) o;
if (maximum != that.maximum) return false;
if (minimum != that.minimum) return false;
if (stepFactor != that.stepFactor) return false;
return true;
}
@Override
public int hashCode() {
int result = minimum;
result = 31 * result + maximum;
result = 31 * result + stepFactor;
return result;
}
@Override
public String toString() {
return "[minimum="+ minimum +", maximum="+ maximum +", stepFactor="+stepFactor+"]";
}
}

View File

@ -0,0 +1,167 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.tmrk.enterprisecloud.domain;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlEnum;
import javax.xml.bind.annotation.XmlEnumValue;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* <xs:complexType name="CustomizationOption">
* @author Jason King
*/
public class CustomizationOption {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
public Builder toBuilder() {
return new Builder().fromConfigurationOptionRange(this);
}
public static class Builder {
private CustomizationType type;
private boolean canPowerOn;
private boolean passwordRequired;
private boolean sshKeyRequired;
/**
* @see CustomizationOption#getType
*/
public Builder type(CustomizationType type) {
this.type = type;
return this;
}
/**
* @see CustomizationOption#canPowerOn
*/
public Builder canPowerOn(boolean canPowerOn) {
this.canPowerOn = canPowerOn;
return this;
}
/**
* @see CustomizationOption#isPasswordRequired()
*/
public Builder passwordRequired(boolean passwordRequired) {
this.passwordRequired = passwordRequired;
return this;
}
/**
* @see CustomizationOption#isSshKeyRequired()
*/
public Builder sshKeyRequired(boolean sshKeyRequired) {
this.sshKeyRequired = sshKeyRequired;
return this;
}
public CustomizationOption build() {
return new CustomizationOption(type, canPowerOn, passwordRequired,sshKeyRequired);
}
public Builder fromConfigurationOptionRange(CustomizationOption in) {
return type(in.getType()).canPowerOn(in.canPowerOn()).passwordRequired(in.isPasswordRequired()).sshKeyRequired(in.isSshKeyRequired());
}
}
@XmlElement(name = "Type")
private CustomizationType type;
@XmlElement(name = "CanPowerOn")
private boolean canPowerOn;
@XmlElement(name = "PasswordRequired")
private boolean passwordRequired;
@XmlElement(name = "SshKeyRequired")
private boolean sshKeyRequired;
private CustomizationOption(CustomizationType type, boolean canPowerOn, boolean passwordRequired, boolean sshKeyRequired) {
this.type = checkNotNull(type,"type");
this.canPowerOn = canPowerOn;
this.passwordRequired = passwordRequired;
this.sshKeyRequired = sshKeyRequired;
}
private CustomizationOption() {
//For JAXB
}
public CustomizationType getType() {
return type;
}
public boolean canPowerOn() {
return canPowerOn;
}
public boolean isPasswordRequired() {
return passwordRequired;
}
public boolean isSshKeyRequired() {
return sshKeyRequired;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CustomizationOption that = (CustomizationOption) o;
if (canPowerOn != that.canPowerOn) return false;
if (passwordRequired != that.passwordRequired) return false;
if (sshKeyRequired != that.sshKeyRequired) return false;
if (type != that.type) return false;
return true;
}
@Override
public int hashCode() {
int result = type.hashCode();
result = 31 * result + (canPowerOn ? 1 : 0);
result = 31 * result + (passwordRequired ? 1 : 0);
result = 31 * result + (sshKeyRequired ? 1 : 0);
return result;
}
@Override
public String toString() {
return "[type="+type+", canPowerOn="+ canPowerOn +", passwordRequired="+ passwordRequired +", sshKeyRequired="+sshKeyRequired+"]";
}
@XmlEnum
public enum CustomizationType {
@XmlEnumValue("Linux")
LINUX,
@XmlEnumValue("Windows")
WINDOWS;
}
}

View File

@ -0,0 +1,140 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.tmrk.enterprisecloud.domain;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
import javax.xml.bind.annotation.XmlElement;
/**
* <xs:complexType name="ResourceCapacityRange">
* @author Jason King
*/
public class ResourceCapacityRange {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
public Builder toBuilder() {
return new Builder().fromResourceCapacityRange(this);
}
public static class Builder {
private ResourceCapacity minimumSize;
private ResourceCapacity maximumSize;
private ResourceCapacity stepFactor;
/**
* @see ResourceCapacityRange#getMinimumSize
*/
public Builder minimumSize(ResourceCapacity minimumSize) {
this.minimumSize = minimumSize;
return this;
}
/**
* @see ResourceCapacityRange#getMaximumSize
*/
public Builder maximumSize(ResourceCapacity maximumSize) {
this.maximumSize = maximumSize;
return this;
}
/**
* @see ResourceCapacityRange#getStepFactor
*/
public Builder stepFactor(ResourceCapacity stepFactor) {
this.stepFactor = stepFactor;
return this;
}
public ResourceCapacityRange build() {
return new ResourceCapacityRange(minimumSize,maximumSize,stepFactor);
}
public Builder fromResourceCapacityRange(ResourceCapacityRange in) {
return minimumSize(in.getMinimumSize()).maximumSize(in.getMaximumSize()).stepFactor(in.getStepFactor());
}
}
@XmlElement(name = "MinimumSize", required = false)
private ResourceCapacity minimumSize;
@XmlElement(name = "MaximumSize", required = false)
private ResourceCapacity maximumSize;
@XmlElement(name = "StepFactor", required = false)
private ResourceCapacity stepFactor;
private ResourceCapacityRange(@Nullable ResourceCapacity minimumSize, @Nullable ResourceCapacity maximumSize, @Nullable ResourceCapacity stepFactor) {
this.minimumSize = minimumSize;
this.maximumSize = maximumSize;
this.stepFactor = stepFactor;
}
private ResourceCapacityRange() {
//For JAXB
}
public ResourceCapacity getMinimumSize() {
return minimumSize;
}
public ResourceCapacity getMaximumSize() {
return maximumSize;
}
public ResourceCapacity getStepFactor() {
return stepFactor;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ResourceCapacityRange that = (ResourceCapacityRange) o;
if (maximumSize != null ? !maximumSize.equals(that.maximumSize) : that.maximumSize != null)
return false;
if (minimumSize != null ? !minimumSize.equals(that.minimumSize) : that.minimumSize != null)
return false;
if (stepFactor != null ? !stepFactor.equals(that.stepFactor) : that.stepFactor != null)
return false;
return true;
}
@Override
public int hashCode() {
int result = minimumSize != null ? minimumSize.hashCode() : 0;
result = 31 * result + (maximumSize != null ? maximumSize.hashCode() : 0);
result = 31 * result + (stepFactor != null ? stepFactor.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "[minimumSize="+ minimumSize +", maximumSize="+maximumSize+", stepFactor="+stepFactor+"]";
}
}

View File

@ -1,84 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.tmrk.enterprisecloud.domain;
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
/**
* @author Jason King
*/
public class Size extends ResourceCapacity<Size> {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
/**
* {@inheritDoc}
*/
@Override
public Builder toBuilder() {
return new Builder().fromSize(this);
}
public static class Builder extends ResourceCapacity.Builder<Size> {
@Override
public Size build() {
return new Size(value,unit);
}
public Builder fromSize(Size in) {
return fromResource(in);
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromResource(ResourceCapacity<Size> in) {
return Builder.class.cast(super.fromResource(in));
}
/**
* {@inheritDoc}
*/
@Override
public Builder value(double value) {
return Builder.class.cast(super.value(value));
}
/**
* {@inheritDoc}
*/
@Override
public Builder unit(String unit) {
return Builder.class.cast(super.unit(unit));
}
}
public Size(double value, String unit) {
super(value, unit);
}
protected Size() {
//For JAXB
}
}

View File

@ -0,0 +1,156 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.tmrk.enterprisecloud.domain.hardware;
import javax.xml.bind.annotation.XmlElement;
/**
* <xs:complexType name="DiskConfigurationOption">
* @author Jason King
*/
public class DiskConfigurationOption {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
public Builder toBuilder() {
return new Builder().fromConfigurationOptionRange(this);
}
public static class Builder {
private int minimum;
private int maximum;
private DiskConfigurationOptionRange systemDisk;
private DiskConfigurationOptionRange dataDisk;
/**
* @see DiskConfigurationOption#getMinimum()
*/
public Builder minimum(int minimum) {
this.minimum = minimum;
return this;
}
/**
* @see DiskConfigurationOption#getMaximum()
*/
public Builder maximum(int maximum) {
this.maximum = maximum;
return this;
}
/**
* @see DiskConfigurationOption#getSystemDisk()
*/
public Builder systemDisk(DiskConfigurationOptionRange systemDisk) {
this.systemDisk = systemDisk;
return this;
}
/**
* @see DiskConfigurationOption#getDataDisk()
*/
public Builder dataDisk(DiskConfigurationOptionRange dataDisk) {
this.dataDisk = dataDisk;
return this;
}
public DiskConfigurationOption build() {
return new DiskConfigurationOption(minimum, maximum, systemDisk, dataDisk);
}
public Builder fromConfigurationOptionRange(DiskConfigurationOption in) {
return minimum(in.getMinimum()).maximum(in.getMaximum()).systemDisk(in.getSystemDisk()).dataDisk(in.getDataDisk());
}
}
@XmlElement(name = "Minimum")
private int minimum;
@XmlElement(name = "Maximum")
private int maximum;
@XmlElement(name = "SystemDisk")
private DiskConfigurationOptionRange systemDisk;
@XmlElement(name = "DataDisk")
private DiskConfigurationOptionRange dataDisk;
private DiskConfigurationOption(int minimum, int maximum, DiskConfigurationOptionRange systemDisk, DiskConfigurationOptionRange dataDisk) {
this.minimum = minimum;
this.maximum = maximum;
this.systemDisk = systemDisk;
this.dataDisk = dataDisk;
}
private DiskConfigurationOption() {
//For JAXB
}
public int getMinimum() {
return minimum;
}
public int getMaximum() {
return maximum;
}
public DiskConfigurationOptionRange getSystemDisk() {
return systemDisk;
}
public DiskConfigurationOptionRange getDataDisk() {
return dataDisk;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
DiskConfigurationOption that = (DiskConfigurationOption) o;
if (maximum != that.maximum) return false;
if (minimum != that.minimum) return false;
if (dataDisk != null ? !dataDisk.equals(that.dataDisk) : that.dataDisk != null)
return false;
if (systemDisk != null ? !systemDisk.equals(that.systemDisk) : that.systemDisk != null)
return false;
return true;
}
@Override
public int hashCode() {
int result = minimum;
result = 31 * result + maximum;
result = 31 * result + (systemDisk != null ? systemDisk.hashCode() : 0);
result = 31 * result + (dataDisk != null ? dataDisk.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "[minimum="+minimum+", maximum="+ maximum +", systemDisk="+ systemDisk +", dataDisk="+dataDisk+"]";
}
}

View File

@ -0,0 +1,122 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.tmrk.enterprisecloud.domain.hardware;
import org.jclouds.tmrk.enterprisecloud.domain.ResourceCapacityRange;
import javax.xml.bind.annotation.XmlElement;
/**
* <xs:complexType name="DiskConfigurationOptionRange">
* @author Jason King
*/
public class DiskConfigurationOptionRange {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
public Builder toBuilder() {
return new Builder().fromConfigurationOptionRange(this);
}
public static class Builder {
private ResourceCapacityRange resourceCapacityRange;
private double monthlyCost;
/**
* @see DiskConfigurationOptionRange#getResourceCapacityRange
*/
public Builder resourceCapacityRange(ResourceCapacityRange resourceCapacityRange) {
this.resourceCapacityRange = resourceCapacityRange;
return this;
}
/**
* @see DiskConfigurationOptionRange#getMonthlyCost()
*/
public Builder monthlyCost(double monthlyCost) {
this.monthlyCost = monthlyCost;
return this;
}
public DiskConfigurationOptionRange build() {
return new DiskConfigurationOptionRange(resourceCapacityRange, monthlyCost);
}
public Builder fromConfigurationOptionRange(DiskConfigurationOptionRange in) {
return resourceCapacityRange(in.getResourceCapacityRange()).monthlyCost(in.getMonthlyCost());
}
}
@XmlElement(name = "ResourceCapacityRange")
private ResourceCapacityRange resourceCapacityRange;
@XmlElement(name = "MonthlyCost")
private double monthlyCost;
private DiskConfigurationOptionRange(ResourceCapacityRange resourceCapacityRange, double monthlyCost) {
this.resourceCapacityRange = resourceCapacityRange;
this.monthlyCost = monthlyCost;
}
private DiskConfigurationOptionRange() {
//For JAXB
}
public ResourceCapacityRange getResourceCapacityRange() {
return resourceCapacityRange;
}
public double getMonthlyCost() {
return monthlyCost;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
DiskConfigurationOptionRange that = (DiskConfigurationOptionRange) o;
if (Double.compare(that.monthlyCost, monthlyCost) != 0) return false;
if (resourceCapacityRange != null ? !resourceCapacityRange.equals(that.resourceCapacityRange) : that.resourceCapacityRange != null)
return false;
return true;
}
@Override
public int hashCode() {
int result;
long temp;
result = resourceCapacityRange != null ? resourceCapacityRange.hashCode() : 0;
temp = monthlyCost != +0.0d ? Double.doubleToLongBits(monthlyCost) : 0L;
result = 31 * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public String toString() {
return "[resourceCapacityRange="+resourceCapacityRange+", monthlyCost="+monthlyCost+"]";
}
}

View File

@ -81,11 +81,6 @@ public class Disks {
this.disks = Sets.newLinkedHashSet(disks);
}
public void setVirtualDisk(VirtualDisk disk) {
checkNotNull(disk,"disk");
this.disks.add(disk);
}
public Set<VirtualDisk> getVirtualDisks() {
return Collections.unmodifiableSet(disks);
}

View File

@ -24,10 +24,12 @@ import org.jclouds.javax.annotation.Nullable;
import org.jclouds.tmrk.enterprisecloud.domain.Action;
import org.jclouds.tmrk.enterprisecloud.domain.Actions;
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
import org.jclouds.tmrk.enterprisecloud.domain.network.Nics;
import org.jclouds.tmrk.enterprisecloud.domain.network.VirtualNic;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.net.URI;
import java.util.Collections;
import java.util.Map;
@ -39,6 +41,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
* <xs:complexType name="HardwareConfiguration">
* @author Jason King
*/
@XmlRootElement(name = "HardwareConfiguration")
public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
@SuppressWarnings("unchecked")
@ -59,7 +62,7 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
// TODO Links
private Set<Action> actions = Sets.newLinkedHashSet();
private int processorCount;
private Memory memory;
private ResourceCapacity memory;
private Set<VirtualDisk> virtualDisks = Sets.newLinkedHashSet();
private Set<VirtualNic> virtualNics = Sets.newLinkedHashSet();
@ -82,7 +85,7 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
/**
* @see HardwareConfiguration#getMemory
*/
public Builder memory(Memory memory) {
public Builder memory(ResourceCapacity memory) {
this.memory = memory;
return this;
}
@ -157,7 +160,7 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
private int processorCount;
@XmlElement(name = "Memory", required = false)
private Memory memory;
private ResourceCapacity memory;
@XmlElement(name = "Disks", required = false)
private Disks virtualDisks = Disks.builder().build();
@ -165,7 +168,7 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
@XmlElement(name = "Nics", required = false)
private Nics virtualNics = Nics.builder().build();
public HardwareConfiguration(Set<Action> actions, int processorCount, @Nullable Memory memory, Set<VirtualDisk> virtualDisks, Set<VirtualNic> virtualNics) {
public HardwareConfiguration(Set<Action> actions, int processorCount, @Nullable ResourceCapacity memory, Set<VirtualDisk> virtualDisks, Set<VirtualNic> virtualNics) {
this.actions = Actions.builder().actions(checkNotNull(actions, "actions")).build();
this.virtualDisks = Disks.builder().disks(checkNotNull(virtualDisks,"virtualDisks")).build();
this.virtualNics = Nics.builder().nics(checkNotNull(virtualNics, "virtualNics")).build();
@ -185,7 +188,7 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
return processorCount;
}
public Memory getMemory() {
public ResourceCapacity getMemory() {
return memory;
}

View File

@ -1,84 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.tmrk.enterprisecloud.domain.hardware;
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
/**
* @author Jason King
*/
public class Memory extends ResourceCapacity<Memory> {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
/**
* {@inheritDoc}
*/
@Override
public Builder toBuilder() {
return new Builder().fromMemory(this);
}
public static class Builder extends ResourceCapacity.Builder<Memory> {
@Override
public Memory build() {
return new Memory(value,unit);
}
public Builder fromMemory(Memory in) {
return fromResource(in);
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromResource(ResourceCapacity<Memory> in) {
return Builder.class.cast(super.fromResource(in));
}
/**
* {@inheritDoc}
*/
@Override
public Builder value(double value) {
return Builder.class.cast(super.value(value));
}
/**
* {@inheritDoc}
*/
@Override
public Builder unit(String unit) {
return Builder.class.cast(super.unit(unit));
}
}
public Memory(double value, String unit) {
super(value, unit);
}
protected Memory() {
//For JAXB
}
}

View File

@ -19,7 +19,7 @@
package org.jclouds.tmrk.enterprisecloud.domain.hardware;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.tmrk.enterprisecloud.domain.Size;
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
import javax.xml.bind.annotation.XmlElement;
@ -44,7 +44,7 @@ public class VirtualDisk {
public static class Builder {
private String name;
private Size size;
private ResourceCapacity size;
private int index;
/**
@ -58,7 +58,7 @@ public class VirtualDisk {
/**
* @see VirtualDisk#getSize
*/
public Builder size(Size size) {
public Builder size(ResourceCapacity size) {
this.size = size;
return this;
}
@ -86,12 +86,12 @@ public class VirtualDisk {
private String name;
@XmlElement(name = "Size", required = false)
private Size size;
private ResourceCapacity size;
@XmlElement(name = "Index", required = false)
private int index;
public VirtualDisk(@Nullable String name, @Nullable Size size, int index) {
public VirtualDisk(@Nullable String name, @Nullable ResourceCapacity size, int index) {
this.name = name;
this.size = size;
this.index = index;
@ -105,7 +105,7 @@ public class VirtualDisk {
return name;
}
public Size getSize() {
public ResourceCapacity getSize() {
return size;
}

View File

@ -25,42 +25,42 @@ import javax.xml.bind.annotation.XmlElement;
/**
* @author Jason King
*/
public class ResourceCapacity<T extends ResourceCapacity<T>> {
public class ResourceCapacity {
public static <T extends ResourceCapacity<T>> Builder<T> builder() {
return new Builder<T>();
public static Builder builder() {
return new Builder();
}
public Builder<T> toBuilder() {
return new Builder<T>().fromResource(this);
public Builder toBuilder() {
return new Builder().fromResource(this);
}
public static class Builder<T extends ResourceCapacity<T>> {
public static class Builder {
protected double value; //mandatory
protected String unit; //optional
/**
* @see ResourceCapacity#getValue
* @see org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity#getValue
*/
public Builder<T> value(double value) {
public Builder value(double value) {
this.value = value;
return this;
}
/**
* @see ResourceCapacity#getUnit
* @see org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity#getUnit
*/
public Builder<T> unit(String unit) {
public Builder unit(String unit) {
this.unit = unit;
return this;
}
public ResourceCapacity<T> build() {
return new ResourceCapacity<T>(value, unit);
public ResourceCapacity build() {
return new ResourceCapacity(value, unit);
}
public Builder<T> fromResource(ResourceCapacity<T> in) {
public Builder fromResource(ResourceCapacity in) {
return value(in.getValue()).unit(in.getUnit());
}
}
@ -117,10 +117,6 @@ public class ResourceCapacity<T extends ResourceCapacity<T>> {
@Override
public String toString() {
return String.format("[%s]",string());
}
protected String string() {
return "value="+value+", unit="+unit;
return "[value="+value+", unit="+unit+"]";
}
}

View File

@ -0,0 +1,301 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.tmrk.enterprisecloud.domain.template;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.tmrk.enterprisecloud.domain.ConfigurationOptionRange;
import org.jclouds.tmrk.enterprisecloud.domain.CustomizationOption;
import org.jclouds.tmrk.enterprisecloud.domain.Links;
import org.jclouds.tmrk.enterprisecloud.domain.ResourceCapacityRange;
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseNamedResource;
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
import org.jclouds.tmrk.enterprisecloud.domain.software.OperatingSystem;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.net.URI;
/**
* <xs:complexType name="Template">
* @author Jason King
*
*/
@XmlRootElement(name = "Template")
public class Template extends BaseNamedResource<Template> {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
/**
* {@inheritDoc}
*/
@Override
public Builder toBuilder() {
return new Builder().fromTask(this);
}
public static class Builder extends BaseNamedResource.Builder<Template> {
//TODO There are additional fields
protected Links links;
protected OperatingSystem operatingSystem;
protected String description;
//protected ComputeMatrix computeMatrix;
protected ConfigurationOptionRange processor;
protected ResourceCapacityRange memory;
protected TemplateStorage storage;
protected int networkAdapters;
protected CustomizationOption customization;
//protected DeviceLicensedSoftware licensedSoftware;
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.template.Template#getLinks
*/
public Builder links(Links links) {
this.links = links;
return this;
}
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.template.Template#getOperatingSystem
*/
public Builder operatingSystem(OperatingSystem operatingSystem) {
this.operatingSystem = operatingSystem;
return this;
}
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.template.Template#getDescription
*/
public Builder description(String description) {
this.description = description;
return this;
}
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.template.Template#getProcessor
*/
public Builder processor(ConfigurationOptionRange processor) {
this.processor = processor;
return this;
}
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.template.Template#getMemory
*/
public Builder memory(ResourceCapacityRange memory) {
this.memory = memory;
return this;
}
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.template.Template#getStorage
*/
public Builder storage(TemplateStorage storage) {
this.storage = storage;
return this;
}
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.template.Template#getNetworkAdapters
*/
public Builder networkAdapters(int networkAdapters) {
this.networkAdapters = networkAdapters;
return this;
}
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.template.Template#getCustomization
*/
public Builder customization(CustomizationOption customization) {
this.customization = customization;
return this;
}
@Override
public Template build() {
return new Template(href, type, name, links, operatingSystem, description, processor, memory, storage, networkAdapters, customization);
}
public Builder fromTask(Template in) {
return fromResource(in).description(in.getDescription());
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromResource(BaseResource<Template> in) {
return Builder.class.cast(super.fromResource(in));
}
/**
* {@inheritDoc}
*/
@Override
public Builder name(String name) {
return Builder.class.cast(super.type(name));
}
/**
* {@inheritDoc}
*/
@Override
public Builder type(String type) {
return Builder.class.cast(super.type(type));
}
/**
* {@inheritDoc}
*/
@Override
public Builder href(URI href) {
return Builder.class.cast(super.href(href));
}
}
@XmlElement(name = "Links", required = false)
protected Links links;
@XmlElement(name = "OperatingSystem", required = false)
protected OperatingSystem operatingSystem;
@XmlElement(name = "Description", required = false)
protected String description;
//protected ComputeMatrix computeMatrix;
@XmlElement(name = "Processor", required = false)
protected ConfigurationOptionRange processor;
@XmlElement(name = "Memory", required = false)
protected ResourceCapacityRange memory;
@XmlElement(name = "Storage", required = false)
protected TemplateStorage storage;
@XmlElement(name = "NetworkAdapters", required = false)
protected int networkAdapters;
@XmlElement(name = "Customization", required = false)
protected CustomizationOption customization;
//protected DeviceLicensedSoftware licensedSoftware;
private Template(URI href, String type, String name, @Nullable Links links, @Nullable OperatingSystem operatingSystem, @Nullable String description,
@Nullable ConfigurationOptionRange processor, @Nullable ResourceCapacityRange memory,
@Nullable TemplateStorage storage, @Nullable int networkAdapters, @Nullable CustomizationOption customization) {
super(href, type, name);
this.links = links;
this.operatingSystem = operatingSystem;
this.description = description;
this.processor = processor;
this.memory = memory;
this.storage = storage;
this.networkAdapters = networkAdapters;
this.customization = customization;
}
private Template() {
//For JAXB
}
public Links getLinks() {
return links;
}
public String getDescription() {
return description;
}
public ConfigurationOptionRange getProcessor() {
return processor;
}
public ResourceCapacityRange getMemory() {
return memory;
}
public TemplateStorage getStorage() {
return storage;
}
public int getNetworkAdapters() {
return networkAdapters;
}
public CustomizationOption getCustomization() {
return customization;
}
public OperatingSystem getOperatingSystem() {
return operatingSystem;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
Template template = (Template) o;
if (networkAdapters != template.networkAdapters) return false;
if (customization != null ? !customization.equals(template.customization) : template.customization != null)
return false;
if (description != null ? !description.equals(template.description) : template.description != null)
return false;
if (links != null ? !links.equals(template.links) : template.links != null)
return false;
if (memory != null ? !memory.equals(template.memory) : template.memory != null)
return false;
if (operatingSystem != null ? !operatingSystem.equals(template.operatingSystem) : template.operatingSystem != null)
return false;
if (processor != null ? !processor.equals(template.processor) : template.processor != null)
return false;
if (storage != null ? !storage.equals(template.storage) : template.storage != null)
return false;
return true;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (links != null ? links.hashCode() : 0);
result = 31 * result + (operatingSystem != null ? operatingSystem.hashCode() : 0);
result = 31 * result + (description != null ? description.hashCode() : 0);
result = 31 * result + (processor != null ? processor.hashCode() : 0);
result = 31 * result + (memory != null ? memory.hashCode() : 0);
result = 31 * result + (storage != null ? storage.hashCode() : 0);
result = 31 * result + networkAdapters;
result = 31 * result + (customization != null ? customization.hashCode() : 0);
return result;
}
@Override
public String string() {
return super.string()+", links="+ links+", operatingSystem="+ operatingSystem+
", description="+ description+", processor="+ processor+
", memory="+ memory+", storage="+ storage+
", networkAdapters="+ networkAdapters+", customization="+ customization;
}
}

View File

@ -0,0 +1,122 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.tmrk.enterprisecloud.domain.template;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
import javax.xml.bind.annotation.XmlElement;
/**
* <xs:complexType name="TemplateStorage">
* @author Jason King
*/
public class TemplateStorage {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
public Builder toBuilder() {
return new Builder().fromTemplateStorage(this);
}
public static class Builder {
private ResourceCapacity size;
private double hourlyCost;
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.template.TemplateStorage#getSize
*/
public Builder size(ResourceCapacity size) {
this.size = size;
return this;
}
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.template.TemplateStorage#getHourlyCost
*/
public Builder hourlyCost(double hourlyCost) {
this.hourlyCost = hourlyCost;
return this;
}
public TemplateStorage build() {
return new TemplateStorage(size, hourlyCost);
}
public Builder fromTemplateStorage(TemplateStorage in) {
return size(in.getSize()).hourlyCost(in.getHourlyCost());
}
}
@XmlElement(name = "Size", required = false)
private ResourceCapacity size;
@XmlElement(name = "HourlyCost", required = false)
private double hourlyCost;
private TemplateStorage(@Nullable ResourceCapacity size, double hourlyCost) {
this.size = size;
this.hourlyCost = hourlyCost;
}
private TemplateStorage() {
//For JAXB
}
public ResourceCapacity getSize() {
return size;
}
public double getHourlyCost() {
return hourlyCost;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TemplateStorage that = (TemplateStorage) o;
if (Double.compare(that.hourlyCost, hourlyCost) != 0) return false;
if (size != null ? !size.equals(that.size) : that.size != null)
return false;
return true;
}
@Override
public int hashCode() {
int result;
long temp;
result = size != null ? size.hashCode() : 0;
temp = hourlyCost != +0.0d ? Double.doubleToLongBits(hourlyCost) : 0L;
result = 31 * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public String toString() {
return "[size="+ size +", hourlyCost="+ hourlyCost +"]";
}
}

View File

@ -0,0 +1,130 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.tmrk.enterprisecloud.domain.template;
import org.jclouds.tmrk.enterprisecloud.domain.Link;
import org.jclouds.tmrk.enterprisecloud.domain.Links;
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.net.URI;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* <xs:complexType name="Templates">
* @author Jason King
*
*/
@XmlRootElement(name = "Templates")
public class Templates extends BaseResource<Templates> {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
/**
* {@inheritDoc}
*/
@Override
public Builder toBuilder() {
return new Builder().fromTemplates(this);
}
public static class Builder extends BaseResource.Builder<Templates> {
private Links links = Links.builder().build();
/**
* @see Templates#getLinks
*/
public Builder links(Set<Link> links) {
this.links = Links.builder().links(checkNotNull(links,"links")).build();
return this;
}
@Override
public Templates build() {
return new Templates(href, type, links);
}
public Builder fromTemplates(Templates in) {
return fromResource(in).links(in.getLinks());
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromResource(BaseResource<Templates> in) {
return Builder.class.cast(super.fromResource(in));
}
/**
* {@inheritDoc}
*/
@Override
public Builder type(String type) {
return Builder.class.cast(super.type(type));
}
/**
* {@inheritDoc}
*/
@Override
public Builder href(URI href) {
return Builder.class.cast(super.href(href));
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromAttributes(Map<String, String> attributes) {
return Builder.class.cast(super.fromAttributes(attributes));
}
}
@XmlElement(name = "Links", required = true)
private Links links = Links.builder().build();
public Templates(URI href, String type, Links links ) {
super(href, type);
this.links = checkNotNull(links, "links");
}
protected Templates() {
//For JAXB
}
public Set<Link> getLinks() {
return Collections.unmodifiableSet(links.getLinks());
}
@Override
public String string() {
return super.string()+", links="+links;
}
}

View File

@ -0,0 +1,245 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.tmrk.enterprisecloud.domain.vm;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.tmrk.enterprisecloud.domain.*;
import org.jclouds.tmrk.enterprisecloud.domain.hardware.DiskConfigurationOption;
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.net.URI;
/**
* <xs:complexType name="VirtualMachineConfigurationOptions">
* @author Jason King
*
*/
@XmlRootElement(name = "VirtualMachineConfigurationOptions")
public class VirtualMachineConfigurationOptions extends BaseResource<VirtualMachineConfigurationOptions> {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
/**
* {@inheritDoc}
*/
@Override
public Builder toBuilder() {
return new Builder().fromVirtualMachineConfigurationOptions(this);
}
public static class Builder extends BaseResource.Builder<VirtualMachineConfigurationOptions> {
protected ConfigurationOptionRange processor;
protected ResourceCapacityRange memory;
protected DiskConfigurationOption disk;
protected ConfigurationOptionRange networkAdapter;
protected CustomizationOption customization;
//TODO ComputeMatrix field
/**
* @see VirtualMachineConfigurationOptions#getProcessor
*/
public Builder processor(ConfigurationOptionRange processor) {
this.processor = processor;
return this;
}
/**
* @see VirtualMachineConfigurationOptions#getMemory
*/
public Builder memory(ResourceCapacityRange memory) {
this.memory = memory;
return this;
}
/**
* @see VirtualMachineConfigurationOptions#getDisk
*/
public Builder disk(DiskConfigurationOption disk) {
this.disk = disk;
return this;
}
/**
* @see VirtualMachineConfigurationOptions#getNetworkAdapter
*/
public Builder networkAdapter(ConfigurationOptionRange networkAdapter) {
this.networkAdapter = networkAdapter;
return this;
}
/**
* @see VirtualMachineConfigurationOptions#getCustomization
*/
public Builder customization(CustomizationOption customization) {
this.customization = customization;
return this;
}
@Override
public VirtualMachineConfigurationOptions build() {
return new VirtualMachineConfigurationOptions(href, type, processor, memory, disk, networkAdapter, customization);
}
public Builder fromVirtualMachineConfigurationOptions(VirtualMachineConfigurationOptions in) {
return fromResource(in).processor(in.getProcessor())
.memory(in.getMemory())
.disk(in.getDisk())
.networkAdapter(in.getNetworkAdapter())
.customization(in.getCustomization());
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromResource(BaseResource<VirtualMachineConfigurationOptions> in) {
return Builder.class.cast(super.fromResource(in));
}
/**
* {@inheritDoc}
*/
@Override
public Builder type(String type) {
return Builder.class.cast(super.type(type));
}
/**
* {@inheritDoc}
*/
@Override
public Builder href(URI href) {
return Builder.class.cast(super.href(href));
}
}
@XmlElement(name = "Processor", required = false)
private ConfigurationOptionRange processor;
@XmlElement(name = "Memory", required = false)
private ResourceCapacityRange memory;
@XmlElement(name = "Disk", required = false)
private DiskConfigurationOption disk;
@XmlElement(name = "NetworkAdapter", required = false)
private ConfigurationOptionRange networkAdapter;
@XmlElement(name = "Customization", required = false)
private CustomizationOption customization;
private VirtualMachineConfigurationOptions(URI href, String type, @Nullable ConfigurationOptionRange processor, @Nullable ResourceCapacityRange memory,
@Nullable DiskConfigurationOption disk, @Nullable ConfigurationOptionRange networkAdapter, @Nullable CustomizationOption customization) {
super(href, type);
this.processor = processor;
this.memory = memory;
this.disk = disk;
this.networkAdapter = networkAdapter;
this.customization = customization;
}
private VirtualMachineConfigurationOptions() {
//For JAXB
}
/**
*
* @return processor configuration option range
*/
public ConfigurationOptionRange getProcessor() {
return processor;
}
/**
*
* @return memory capacity configuration range
*/
public ResourceCapacityRange getMemory() {
return memory;
}
/**
*
* @return disk configuration option
*/
public DiskConfigurationOption getDisk() {
return disk;
}
/**
*
* @return network adapter configuration range
*/
public ConfigurationOptionRange getNetworkAdapter() {
return networkAdapter;
}
/**
*
* @return customization option
*/
public CustomizationOption getCustomization() {
return customization;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
VirtualMachineConfigurationOptions that = (VirtualMachineConfigurationOptions) o;
if (customization != null ? !customization.equals(that.customization) : that.customization != null)
return false;
if (disk != null ? !disk.equals(that.disk) : that.disk != null)
return false;
if (memory != null ? !memory.equals(that.memory) : that.memory != null)
return false;
if (networkAdapter != null ? !networkAdapter.equals(that.networkAdapter) : that.networkAdapter != null)
return false;
if (processor != null ? !processor.equals(that.processor) : that.processor != null)
return false;
return true;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (processor != null ? processor.hashCode() : 0);
result = 31 * result + (memory != null ? memory.hashCode() : 0);
result = 31 * result + (disk != null ? disk.hashCode() : 0);
result = 31 * result + (networkAdapter != null ? networkAdapter.hashCode() : 0);
result = 31 * result + (customization != null ? customization.hashCode() : 0);
return result;
}
@Override
public String string() {
return super.string()+", memory="+memory+", disk="+disk+", processor="+processor+", networkAdapter="+networkAdapter+", customization="+customization;
}
}

View File

@ -62,4 +62,13 @@ public interface TaskAsyncClient {
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Task> getTask(@EndpointParam URI taskId);
/**
* @see TaskClient#getTasksByVirtualMachine
*/
@GET
@Consumes("application/vnd.tmrk.cloud.task; type=collection")
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Tasks> getTasksByVirtualMachine(@EndpointParam URI uri);
}

View File

@ -52,6 +52,14 @@ public interface TaskClient {
*
* @return the task or null if not found
*/
Task getTask(URI taskId);
Task getTask(URI taskUri);
/**
* The Get Tasks by Virtual Machine call returns information regarding tasks
* for a specified virtual machine in an environment.
* @param uri The uri corresponding to the tasks. e.g. /cloudapi/ecloud/tasks/virtualmachines/{id}
* @return Tasks
*/
Tasks getTasksByVirtualMachine(URI uri);
}

View File

@ -0,0 +1,63 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.tmrk.enterprisecloud.features;
import com.google.common.util.concurrent.ListenableFuture;
import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.rest.annotations.*;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.tmrk.enterprisecloud.domain.template.Template;
import org.jclouds.tmrk.enterprisecloud.domain.template.Templates;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import java.net.URI;
/**
* Provides asynchronous access to Templates(s) via their REST API.
* <p/>
*
* @see org.jclouds.tmrk.enterprisecloud.features.TemplateClient
* @see <a href=
* "http://support.theenterprisecloud.com/kb/default.asp?id=984&Lang=1&SID="
* />
* @author Jason King
*/
@RequestFilters(BasicAuthentication.class)
@Headers(keys = "x-tmrk-version", values = "{jclouds.api-version}")
public interface TemplateAsyncClient {
/**
* @see org.jclouds.tmrk.enterprisecloud.features.TemplateClient#getTemplates
*/
@GET
@Consumes("application/vnd.tmrk.cloud.template; type=collection")
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Templates> getTemplates(@EndpointParam URI uri);
/**
* @see org.jclouds.tmrk.enterprisecloud.features.TemplateClient#getTemplate
*/
@GET
@Consumes("application/vnd.tmrk.cloud.template")
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Template> getTemplate(@EndpointParam URI uri);
}

View File

@ -0,0 +1,57 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.tmrk.enterprisecloud.features;
import org.jclouds.concurrent.Timeout;
import org.jclouds.tmrk.enterprisecloud.domain.template.Template;
import org.jclouds.tmrk.enterprisecloud.domain.template.Templates;
import java.net.URI;
import java.util.concurrent.TimeUnit;
/**
* Provides synchronous access to Template(s).
* <p/>
*
* @see org.jclouds.tmrk.enterprisecloud.features.TemplateAsyncClient
* @see <a href=
* "http://support.theenterprisecloud.com/kb/default.asp?id=984&Lang=1&SID="
* />
* @author Jason King
*/
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
public interface TemplateClient {
/**
* The Get Templates call returns information regarding templates defined in a compute pool.
* Note that Templates are not a simple wrapper around template objects.
* Once the desired template is located getTemplate must be called to retrieve all the attached information
* @param uri compute pool identifier
* @return the templates
*/
Templates getTemplates(URI uri);
/**
* The Get Templates by ID call returns information regarding a specified template defined in a compute pool
* @param uri the uri of the template
* @return the template
*/
Template getTemplate(URI uri);
}

View File

@ -22,12 +22,15 @@ import com.google.common.util.concurrent.ListenableFuture;
import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.rest.annotations.*;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.tmrk.enterprisecloud.domain.Task;
import org.jclouds.tmrk.enterprisecloud.domain.hardware.HardwareConfiguration;
import org.jclouds.tmrk.enterprisecloud.domain.network.AssignedIpAddresses;
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachine;
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachineConfigurationOptions;
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachines;
import org.jclouds.tmrk.enterprisecloud.functions.ReturnEmptyVirtualMachinesOnNotFoundOr404;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.*;
import java.net.URI;
/**
@ -50,7 +53,7 @@ public interface VirtualMachineAsyncClient {
@GET
@Consumes("application/vnd.tmrk.cloud.virtualMachine; type=collection")
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@ExceptionParser(ReturnEmptyVirtualMachinesOnNotFoundOr404.class)
ListenableFuture<VirtualMachines> getVirtualMachines(@EndpointParam URI uri);
/**
@ -71,4 +74,90 @@ public interface VirtualMachineAsyncClient {
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<AssignedIpAddresses> getAssignedIpAddresses(@EndpointParam URI uri);
/**
* @see VirtualMachineClient#getConfigurationOptions
*/
@GET
@Consumes("application/vnd.tmrk.cloud.virtualMachineConfigurationOptions")
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<VirtualMachineConfigurationOptions> getConfigurationOptions(@EndpointParam URI uri);
/**
* @see VirtualMachineClient#getHardwareConfiguration
*/
@GET
@Consumes("application/vnd.tmrk.cloud.virtualMachineHardware")
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<HardwareConfiguration> getHardwareConfiguration(@EndpointParam URI uri);
/**
* @see VirtualMachineClient#powerOn
*/
@POST
@Path("/action/powerOn")
@Consumes("application/vnd.tmrk.cloud.task")
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Task> powerOn(@EndpointParam URI uri);
/**
* @see VirtualMachineClient#powerOff
*/
@POST
@Path("/action/powerOff")
@Consumes("application/vnd.tmrk.cloud.task")
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Task> powerOff(@EndpointParam URI uri);
/**
* @see VirtualMachineClient#reboot
*/
@POST
@Path("/action/reboot")
@Consumes("application/vnd.tmrk.cloud.task")
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Task> reboot(@EndpointParam URI uri);
/**
* @see VirtualMachineClient#shutdown
*/
@POST
@Path("/action/shutdown")
@Consumes("application/vnd.tmrk.cloud.task")
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Task> shutdown(@EndpointParam URI uri);
/**
* @see VirtualMachineClient#mountTools
*/
@POST
@Path("/tools/action/mount")
@Consumes("application/vnd.tmrk.cloud.task")
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Task> mountTools(@EndpointParam URI uri);
/**
* @see VirtualMachineClient#unmountTools
*/
@POST
@Path("/tools/action/unmount")
@Consumes("application/vnd.tmrk.cloud.task")
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Task> unmountTools(@EndpointParam URI uri);
/**
* @see VirtualMachineClient#remove
*/
@DELETE
@Consumes("application/vnd.tmrk.cloud.task")
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Task> remove(@EndpointParam URI uri);
}

View File

@ -19,8 +19,11 @@
package org.jclouds.tmrk.enterprisecloud.features;
import org.jclouds.concurrent.Timeout;
import org.jclouds.tmrk.enterprisecloud.domain.Task;
import org.jclouds.tmrk.enterprisecloud.domain.hardware.HardwareConfiguration;
import org.jclouds.tmrk.enterprisecloud.domain.network.AssignedIpAddresses;
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachine;
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachineConfigurationOptions;
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachines;
import java.net.URI;
@ -62,4 +65,86 @@ public interface VirtualMachineClient {
*/
AssignedIpAddresses getAssignedIpAddresses(URI uri);
/**
* The Get Virtual Machines Configuration Options call returns information
* regarding the configuration options of a specified virtual machine in a compute pool.
* @param uri the uri for the configuration options. e.g. /cloudapi/ecloud/virtualmachines/{id}/configurationoptions
* @return the configuration options
*/
VirtualMachineConfigurationOptions getConfigurationOptions(URI uri);
/**
* The Get Virtual Machines Hardware Configuration call returns information
* regarding the hardware configuration of a specified virtual machine in a compute pool.
* @param uri the uri for the hardware configuration e.g. /cloudapi/ecloud/virtualmachines/{id}/hardwareconfiguration
* @return
*/
HardwareConfiguration getHardwareConfiguration(URI uri);
/**
* The Action Virtual Machines Power On call powers on a specified virtual machine.
* If successful, the call returns the task that powered on the virtual machine.
* Note: To power on requires a PoweredOn value of false.
* @param uri the uri of the virtual machine
* @return Task
*/
Task powerOn(URI uri);
/**
* The Action Virtual Machines Power Off call powers off a specified virtual machine.
* Power off simply terminates the virtual machine whereas
* shutdown requests the virtual machine to end all processes and turn itself off
* when all processes complete.
* If successful, the call returns the task that powered off the virtual machine.
* Note: To power off requires a PoweredOn value of true.
* @param uri the uri of the virtual machine
* @return Task
*/
Task powerOff(URI uri);
/**
* The Action Virtual Machines Power Reboot call reboots a specified virtual machine.
* If successful, the call returns the task that rebooted the virtual machine.
* Note: To reboot requires a ToolsStatus value of Current or OutOfDate and a PoweredOn value of true.
* @param uri the uri of the virtual machine
* @return Task
*/
Task reboot(URI uri);
/**
* The Action Virtual Machines Power Shutdown call shuts down a specified virtual machine.
* Shutdown requests the virtual machine to end all processes and turn itself off when all processes complete whereas power off simply terminates the virtual machine.
* If successful, the call returns the task that shut down the virtual machine.
* Note: To shutdown requires a ToolsStatus value of Current or OutOfDate and a PoweredOn value of true.
* @param uri the uri of the virtual machine
* @return Task
*/
Task shutdown(URI uri);
/**
* The Action Virtual Machines Tools Mount call mounts the virtual volume
* for VMware Tools on a specified virtual machine.
* If successful, the call returns the task that mounted the tools.
* Note: To mount VMware Tools requires a PoweredOn value of true.
* @param uri the uri of the virtual machine
* @return Task
*/
Task mountTools(URI uri);
/**
* The Action Virtual Machines Tools Unmount call unmounts the virtual volume for VMware Tools
* on a specified virtual machine.
* If successful, the call returns the task that unmounted the tools.
* Note: To unmount VMware Tools requires a PoweredOn value of true.
* @param uri the uri of the virtual machine
* @return Task
*/
Task unmountTools(URI uri);
/**
* * The Action Virtual Machines Remove call removes a specified virtual machine from the compute pool.
* If successful, the call returns the task that removed the virtual machine.
* Note: To remove a virtual machine requires a Status value of Deployed and a PoweredOn value of false.
*/
Task remove(URI uri);
}

View File

@ -0,0 +1,57 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.tmrk.enterprisecloud.functions;
import com.google.common.base.Function;
import com.google.common.base.Throwables;
import com.google.common.collect.Iterables;
import org.jclouds.http.functions.ReturnTrueOn404;
import org.jclouds.rest.ResourceNotFoundException;
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachines;
import javax.inject.Inject;
import javax.inject.Singleton;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.util.Throwables2.propagateOrNull;
/**
*
* @author Jason King
*/
@Singleton
public class ReturnEmptyVirtualMachinesOnNotFoundOr404 implements Function<Exception, Object> {
private final ReturnTrueOn404 rto404;
@Inject
ReturnEmptyVirtualMachinesOnNotFoundOr404(ReturnTrueOn404 rto404) {
this.rto404 = checkNotNull(rto404, "rto404");
}
public Object apply(Exception from) {
Iterable<ResourceNotFoundException> throwables = Iterables.filter(Throwables.getCausalChain(from),
ResourceNotFoundException.class);
if (Iterables.size(throwables) >= 1) {
return VirtualMachines.builder().build();
} else if (rto404.apply(from)) {
return VirtualMachines.builder().build();
}
return VirtualMachines.class.cast(propagateOrNull(from));
}
}

View File

@ -18,7 +18,7 @@
*/
package org.jclouds.tmrk.enterprisecloud.domain.hardware;
import org.jclouds.tmrk.enterprisecloud.domain.Size;
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@ -39,13 +39,13 @@ public class DisksTest {
@BeforeMethod()
public void setUp() throws URISyntaxException {
disk = VirtualDisk.builder().index(0).name("test disk").size(Size.builder().value(1).unit("GB").build()).build();
disk = VirtualDisk.builder().index(0).name("test disk").size(ResourceCapacity.builder().value(1).unit("GB").build()).build();
disks = Disks.builder().addDisk(disk).build();
}
@Test
public void testAddDisk() throws URISyntaxException {
VirtualDisk disk2 = VirtualDisk.builder().index(1).name("test disk 1").size(Size.builder().value(1).unit("GB").build()).build();
VirtualDisk disk2 = VirtualDisk.builder().index(1).name("test disk 1").size(ResourceCapacity.builder().value(1).unit("GB").build()).build();
Disks twoDisks = disks.toBuilder().addDisk(disk2).build();
Set<VirtualDisk> virtualDisks = twoDisks.getVirtualDisks();

View File

@ -52,12 +52,11 @@ public class TaskAsyncClientTest extends BaseTerremarkEnterpriseCloudAsyncClient
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
checkFilters(httpRequest);
}
public void testGetTask() throws SecurityException, NoSuchMethodException, IOException {
Method method = TaskAsyncClient.class.getMethod("getTask", URI.class);
HttpRequest httpRequest = processor.createRequest(method, URI.create("https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/tasks/1"));
HttpRequest httpRequest = processor.createRequest(method, URI.create("/cloudapi/ecloud/tasks/1"));
assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/tasks/1 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/vnd.tmrk.cloud.task\nx-tmrk-version: 2011-07-01\n");
@ -67,7 +66,20 @@ public class TaskAsyncClientTest extends BaseTerremarkEnterpriseCloudAsyncClient
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpRequest);
}
public void testGetTasksByVirtualMachine() throws SecurityException, NoSuchMethodException, IOException {
Method method = TaskAsyncClient.class.getMethod("getTasksByVirtualMachine", URI.class);
HttpRequest httpRequest = processor.createRequest(method, URI.create("/cloudapi/ecloud/tasks/virtualmachines/5504"));
assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/tasks/virtualmachines/5504 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/vnd.tmrk.cloud.task; type=collection\nx-tmrk-version: 2011-07-01\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseXMLWithJAXB.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpRequest);
}
@Override

View File

@ -43,18 +43,26 @@ public class TaskClientLiveTest extends BaseTerremarkEnterpriseCloudClientLiveTe
private TaskClient client;
@Test
public void testGetTasks() throws Exception {
// TODO: don't hard-code id
// TODO: docs say don't parse the href, yet no xml includes "identifier",
// I suspect we may need to change to URI args as opposed to long
Tasks response = client.getTasksInEnvironment(new URI("/cloudapi/ecloud/tasks/environments/77"));
assert null != response;
assertTasks(response);
}
assertTrue(response.getTasks().size() >= 0);
for (Task task : response.getTasks()) {
public void testGetTasksByVirtualMachine() throws Exception {
// TODO: don't hard-code id
Tasks response = client.getTasksByVirtualMachine(URI.create("/cloudapi/ecloud/tasks/virtualmachines/5504"));
assertTasks(response);
}
private void assertTasks(final Tasks tasks) {
assert null != tasks;
assertTrue(tasks.getTasks().size() >= 0);
for (Task task : tasks.getTasks()) {
assertEquals(client.getTask(task.getHref()), task);
assert task.getStatus() != Task.Status.UNRECOGNIZED : response;
assert task.getStatus() != Task.Status.UNRECOGNIZED : tasks;
}
}
}

View File

@ -0,0 +1,76 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.tmrk.enterprisecloud.features;
import com.google.inject.TypeLiteral;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ParseXMLWithJAXB;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URI;
import java.net.URISyntaxException;
/**
* Tests annotation parsing of {@code TemplateAsyncClient}
*
* @author Jason King
*/
@Test(groups = "unit", testName = "TemplateAsyncClientTest")
public class TemplateAsyncClientTest extends BaseTerremarkEnterpriseCloudAsyncClientTest<TemplateAsyncClient> {
public void testGetTemplates() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
Method method = TemplateAsyncClient.class.getMethod("getTemplates", URI.class);
HttpRequest httpRequest = processor.createRequest(method, new URI("/cloudapi/ecloud/templates/computepools/89"));
assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/templates/computepools/89 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest,
"Accept: application/vnd.tmrk.cloud.template; type=collection\nx-tmrk-version: 2011-07-01\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseXMLWithJAXB.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpRequest);
}
public void testGetTemplate() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
Method method = TemplateAsyncClient.class.getMethod("getTemplate", URI.class);
HttpRequest httpRequest = processor.createRequest(method, new URI("/cloudapi/ecloud/templates/6/computepools/89"));
assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/templates/6/computepools/89 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest,
"Accept: application/vnd.tmrk.cloud.template\nx-tmrk-version: 2011-07-01\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseXMLWithJAXB.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpRequest);
}
@Override
protected TypeLiteral<RestAnnotationProcessor<TemplateAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<TemplateAsyncClient>>() {
};
}
}

View File

@ -23,6 +23,7 @@ import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ParseXMLWithJAXB;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.tmrk.enterprisecloud.functions.ReturnEmptyVirtualMachinesOnNotFoundOr404;
import org.testng.annotations.Test;
import java.io.IOException;
@ -31,7 +32,7 @@ import java.net.URI;
import java.net.URISyntaxException;
/**
* Tests annotation parsing of {@code TaskAsyncClient}
* Tests annotation parsing of {@code VirtualMachineAsyncClient}
*
* @author Adrian Cole
*/
@ -61,7 +62,7 @@ public class VirtualMachineAsyncClientTest extends BaseTerremarkEnterpriseCloudA
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseXMLWithJAXB.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
assertExceptionParserClassEquals(method, ReturnEmptyVirtualMachinesOnNotFoundOr404.class);
checkFilters(httpRequest);
}
@ -80,6 +81,132 @@ public class VirtualMachineAsyncClientTest extends BaseTerremarkEnterpriseCloudA
checkFilters(httpRequest);
}
public void testGetConfigurationOptions() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
Method method = VirtualMachineAsyncClient.class.getMethod("getConfigurationOptions", URI.class);
HttpRequest httpRequest = processor.createRequest(method,new URI("/cloudapi/ecloud/virtualmachines/5504/configurationoptions"));
assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/virtualmachines/5504/configurationoptions HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/vnd.tmrk.cloud.virtualMachineConfigurationOptions\nx-tmrk-version: 2011-07-01\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseXMLWithJAXB.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpRequest);
}
public void testGetHardwareConfiguration() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
Method method = VirtualMachineAsyncClient.class.getMethod("getHardwareConfiguration", URI.class);
HttpRequest httpRequest = processor.createRequest(method,new URI("/cloudapi/ecloud/virtualmachines/5504/hardwareconfiguration"));
assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/virtualmachines/5504/hardwareconfiguration HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/vnd.tmrk.cloud.virtualMachineHardware\nx-tmrk-version: 2011-07-01\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseXMLWithJAXB.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpRequest);
}
public void testPowerOn() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
Method method = VirtualMachineAsyncClient.class.getMethod("powerOn", URI.class);
HttpRequest httpRequest = processor.createRequest(method,new URI("/cloudapi/ecloud/virtualmachines/5504"));
assertRequestLineEquals(httpRequest, "POST https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/virtualmachines/5504/action/powerOn HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/vnd.tmrk.cloud.task\nx-tmrk-version: 2011-07-01\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseXMLWithJAXB.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpRequest);
}
public void testPowerOff() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
Method method = VirtualMachineAsyncClient.class.getMethod("powerOff", URI.class);
HttpRequest httpRequest = processor.createRequest(method,new URI("/cloudapi/ecloud/virtualmachines/5504"));
assertRequestLineEquals(httpRequest, "POST https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/virtualmachines/5504/action/powerOff HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/vnd.tmrk.cloud.task\nx-tmrk-version: 2011-07-01\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseXMLWithJAXB.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpRequest);
}
public void testReboot() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
Method method = VirtualMachineAsyncClient.class.getMethod("reboot", URI.class);
HttpRequest httpRequest = processor.createRequest(method,new URI("/cloudapi/ecloud/virtualmachines/5504"));
assertRequestLineEquals(httpRequest, "POST https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/virtualmachines/5504/action/reboot HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/vnd.tmrk.cloud.task\nx-tmrk-version: 2011-07-01\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseXMLWithJAXB.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpRequest);
}
public void testShutdown() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
Method method = VirtualMachineAsyncClient.class.getMethod("shutdown", URI.class);
HttpRequest httpRequest = processor.createRequest(method,new URI("/cloudapi/ecloud/virtualmachines/5504"));
assertRequestLineEquals(httpRequest, "POST https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/virtualmachines/5504/action/shutdown HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/vnd.tmrk.cloud.task\nx-tmrk-version: 2011-07-01\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseXMLWithJAXB.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpRequest);
}
public void testMountTools() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
Method method = VirtualMachineAsyncClient.class.getMethod("mountTools", URI.class);
HttpRequest httpRequest = processor.createRequest(method,new URI("/cloudapi/ecloud/virtualmachines/5504"));
assertRequestLineEquals(httpRequest, "POST https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/virtualmachines/5504/tools/action/mount HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/vnd.tmrk.cloud.task\nx-tmrk-version: 2011-07-01\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseXMLWithJAXB.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpRequest);
}
public void testUnmountTools() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
Method method = VirtualMachineAsyncClient.class.getMethod("unmountTools", URI.class);
HttpRequest httpRequest = processor.createRequest(method,new URI("/cloudapi/ecloud/virtualmachines/5504"));
assertRequestLineEquals(httpRequest, "POST https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/virtualmachines/5504/tools/action/unmount HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/vnd.tmrk.cloud.task\nx-tmrk-version: 2011-07-01\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseXMLWithJAXB.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpRequest);
}
public void testRemove() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
Method method = VirtualMachineAsyncClient.class.getMethod("remove", URI.class);
HttpRequest httpRequest = processor.createRequest(method,new URI("/cloudapi/ecloud/virtualmachines/5504"));
assertRequestLineEquals(httpRequest, "DELETE https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/virtualmachines/5504 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/vnd.tmrk.cloud.task\nx-tmrk-version: 2011-07-01\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseXMLWithJAXB.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpRequest);
}
@Override
protected TypeLiteral<RestAnnotationProcessor<VirtualMachineAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<VirtualMachineAsyncClient>>() {

View File

@ -0,0 +1,199 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.tmrk.enterprisecloud.features;
import com.google.common.base.Predicate;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.tmrk.enterprisecloud.domain.Task;
import org.jclouds.tmrk.enterprisecloud.domain.software.ToolsStatus;
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachine;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import java.net.URI;
import static org.testng.Assert.*;
/**
* Tests behavior of {@code VirtualMachineClient} actions
* @author Jason King
*/
@Test(groups = "live", testName = "VirtualMachineClientActionsLiveTest")
public class VirtualMachineClientActionsLiveTest extends BaseTerremarkEnterpriseCloudClientLiveTest {
@BeforeGroups(groups = { "live" })
public void setupClient() {
super.setupClient();
client = context.getApi().getVirtualMachineClient();
}
//TODO: Need a create call to make this not dependent on existing vm
private static final String vmURI = "/cloudapi/ecloud/virtualmachines/5504";
private VirtualMachineClient client;
private VirtualMachine vm;
public void testPowerOn() throws Exception {
vm = client.getVirtualMachine(new URI(vmURI));
assertFalse(vm.isPoweredOn());
RetryablePredicate retryablePredicate = new RetryablePredicate(taskFinished(), 1000*60);
if (!retryablePredicate.apply(client.powerOn(vm.getHref()))) {
fail("Did not manage to finish powerOn task");
}
vm = client.getVirtualMachine(vm.getHref());
assertTrue(vm.isPoweredOn());
}
@Test(dependsOnMethods = "testPowerOn")
public void testMountTools() {
if (!mountTools(vm.getHref())) {
fail("Did not manage to finish mount tools task");
}
}
@Test(dependsOnMethods = "testMountTools")
public void testUnmountTools() {
RetryablePredicate retryablePredicate = new RetryablePredicate(taskFinished(), 1000*60);
if (!retryablePredicate.apply(client.unmountTools(vm.getHref()))) {
fail("Did not manage finish unmount tools task");
}
//ToolsStatus remains in 'OutOfDate' after un-mounting.
//There is no way to tell, other than to try un-mounting again.
}
@Test(dependsOnMethods = "testUnmountTools")
public void testShutdown() {
//Seems to work as ToolsStatus remains in OutOfDate state
RetryablePredicate retryablePredicate = new RetryablePredicate(taskFinished(), 1000*60);
if (!retryablePredicate.apply(client.shutdown(vm.getHref()))) {
fail("Did not manage to finish shutdown task");
}
// Takes a while to powerOff
retryablePredicate = new RetryablePredicate(poweredOff(), 1000*60);
if (!retryablePredicate.apply(vm.getHref())) {
fail("Did not manage to powerOff after shutdown");
}
vm = client.getVirtualMachine(vm.getHref());
assertFalse(vm.isPoweredOn());
}
@Test(dependsOnMethods = "testShutdown")
public void testReboot() {
RetryablePredicate retryablePredicate = new RetryablePredicate(taskFinished(), 1000*60);
if (!retryablePredicate.apply(client.powerOn(vm.getHref()))) {
fail("Did not manage to finish powerOn task");
}
if (!mountTools(vm.getHref())) {
fail("Did not manage to mount tools");
}
retryablePredicate = new RetryablePredicate(taskFinished(), 1000*60);
if (!retryablePredicate.apply(client.reboot(vm.getHref()))) {
fail("Did not manage to finish reboot task");
}
vm = client.getVirtualMachine(vm.getHref());
assertTrue(vm.isPoweredOn());
}
@Test(dependsOnMethods = "testReboot")
public void testPowerOff() {
RetryablePredicate retryablePredicate = new RetryablePredicate(taskFinished(), 1000*60);
if (!retryablePredicate.apply(client.powerOff(vm.getHref()))) {
fail("Did not manage to finish powerOff task");
}
vm = client.getVirtualMachine(vm.getHref());
assertFalse(vm.isPoweredOn());
}
/* TODO: Not ready to delete the 5504 VM until I can create one.
@Test(dependsOnMethods = "testPowerOff")
public void testRemove() throws URISyntaxException {
// Don't want to delete quite yet!
RetryablePredicate retryablePredicate = new RetryablePredicate(taskFinished(), 1000*60);
if (!retryablePredicate.apply(client.remove(vm.getHref()))) {
fail("Did not manage to finish remove task");
}
assertNull(client.getVirtualMachine(vm.getHref()));
}
*/
private boolean mountTools(URI uri) {
// Wait for task to finish AND tools to get into currentOrOutOfDate state
return new RetryablePredicate(taskFinished(), 1000*60).apply(client.mountTools(uri)) &&
new RetryablePredicate(toolsCurrentOrOutOfDate(), 1000*60).apply(uri);
}
// Probably generally useful
private Predicate taskFinished() {
return new Predicate<Task>() {
@Override
public boolean apply(Task task) {
TaskClient taskClient = context.getApi().getTaskClient();
task = taskClient.getTask(task.getHref());
switch(task.getStatus()) {
case QUEUED:
case RUNNING:
return false;
case COMPLETE:
case SUCCESS:
return true;
default:
throw new RuntimeException("Task Failed:"+task.getHref()+", Status:"+task.getStatus());
}
}
};
}
// Probably generally useful
private Predicate toolsCurrentOrOutOfDate() {
return new Predicate<URI>() {
@Override
public boolean apply(URI uri) {
VirtualMachine virtualMachine = client.getVirtualMachine(uri);
ToolsStatus toolsStatus = virtualMachine.getToolsStatus();
switch(toolsStatus) {
case NOT_INSTALLED:
case NOT_RUNNING:
return false;
case CURRENT:
case OUT_OF_DATE:
return true;
default:
throw new RuntimeException("Unable to determine toolsStatus for:"+uri+", ToolsStatus:"+toolsStatus);
}
}
};
}
private Predicate poweredOff() {
return new Predicate<URI>() {
@Override
public boolean apply(URI uri) {
VirtualMachine virtualMachine = client.getVirtualMachine(uri);
return !virtualMachine.isPoweredOn();
}
};
}
}

View File

@ -19,9 +19,11 @@
package org.jclouds.tmrk.enterprisecloud.features;
import com.google.common.collect.Iterables;
import org.jclouds.tmrk.enterprisecloud.domain.hardware.HardwareConfiguration;
import org.jclouds.tmrk.enterprisecloud.domain.network.AssignedIpAddresses;
import org.jclouds.tmrk.enterprisecloud.domain.network.DeviceNetwork;
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachine;
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachineConfigurationOptions;
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachines;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
@ -29,12 +31,11 @@ import org.testng.annotations.Test;
import java.net.URI;
import java.util.Set;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.*;
/**
* Tests behavior of {@code VirtualMachineClient}
*
* TODO: don't hard-code uri's it should be possible to determine them but that means chaining the tests potentially.
* @author Jason King
*/
@Test(groups = "live", testName = "VirtualMachineClientLiveTest")
@ -47,31 +48,57 @@ public class VirtualMachineClientLiveTest extends BaseTerremarkEnterpriseCloudCl
private VirtualMachineClient client;
@Test
public void testGetVirtualMachines() throws Exception {
// TODO: don't hard-code uri
VirtualMachines virtualMachines = client.getVirtualMachines(new URI("/cloudapi/ecloud/virtualMachines/computePools/89"));
for( VirtualMachine vm : virtualMachines.getVirtualMachines()) {
VirtualMachine virtualMachine = client.getVirtualMachine(vm.getHref());
assert null != virtualMachine;
assertNotNull(virtualMachine);
assertEquals(virtualMachine.getStatus(),VirtualMachine.VirtualMachineStatus.DEPLOYED);
}
}
@Test
public void testGetVirtualMachinesWhenMissing() throws Exception {
VirtualMachines result = client.getVirtualMachines(new URI("/cloudapi/ecloud/virtualMachines/computePools/-1"));
assertEquals(result, VirtualMachines.builder().build());
}
public void testGetVirtualMachine() throws Exception {
// TODO: don't hard-code uri
VirtualMachine virtualMachine = client.getVirtualMachine(new URI("/cloudapi/ecloud/virtualMachines/5504"));
assert null != virtualMachine;
assertNotNull(virtualMachine,"virtualMachine should not be null");
assertEquals(virtualMachine.getStatus(), VirtualMachine.VirtualMachineStatus.DEPLOYED);
}
@Test
public void testGetVirtualMachineWhenMissing() throws Exception {
VirtualMachine virtualMachine = client.getVirtualMachine(new URI("/cloudapi/ecloud/virtualMachines/-1"));
assertNull(virtualMachine);
}
public void testGetAssignedIpAddresses() throws Exception {
AssignedIpAddresses assignedIpAddresses = client.getAssignedIpAddresses(new URI("/cloudapi/ecloud/virtualMachines/5504/assignedips"));
assert null != assignedIpAddresses;
assertNotNull(assignedIpAddresses);
DeviceNetwork network = Iterables.getOnlyElement(assignedIpAddresses.getNetworks().getDeviceNetworks());
Set<String> ipAddresses = network.getIpAddresses().getIpAddresses();
assertTrue(ipAddresses.size()>0, "vm has no assigned ip addresses");
}
public void testGetAssignedIpAddressesWhenMissing() throws Exception {
AssignedIpAddresses assignedIpAddresses = client.getAssignedIpAddresses(new URI("/cloudapi/ecloud/virtualMachines/-1/assignedips"));
assertNull(assignedIpAddresses);
}
public void testGetConfigurationOptions() throws Exception {
VirtualMachineConfigurationOptions configurationOptions = client.getConfigurationOptions(new URI("/cloudapi/ecloud/virtualmachines/5504/configurationoptions"));
assertNotNull(configurationOptions);
}
public void testGetHardwareConfiguration() throws Exception {
HardwareConfiguration hardwareConfiguration = client.getHardwareConfiguration(new URI("/cloudapi/ecloud/virtualmachines/5504/hardwareconfiguration"));
assertNotNull(hardwareConfiguration);
}
public void testGetHardwareConfigurationWhenMissing() throws Exception {
HardwareConfiguration result = client.getHardwareConfiguration(new URI("/cloudapi/ecloud/virtualmachines/-1/hardwareconfiguration"));
assertNull(result);
}
}

View File

@ -0,0 +1,63 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.tmrk.enterprisecloud.functions;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.HttpResponseException;
import org.jclouds.http.functions.ReturnTrueOn404;
import org.jclouds.rest.ResourceNotFoundException;
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachines;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
/**
*
* @author Jason King
*/
@Test(groups = "unit", testName = "ReturnEmptyVirtualMachinesOnNotFoundOr404Test")
public class ReturnEmptyVirtualMachinesOnNotFoundOr404Test {
private ReturnEmptyVirtualMachinesOnNotFoundOr404 function;
private VirtualMachines expected;
@BeforeMethod
public void setUp() {
function = new ReturnEmptyVirtualMachinesOnNotFoundOr404(new ReturnTrueOn404());
expected = VirtualMachines.builder().build();
}
public void testOn404() {
assertEquals(function.apply(new HttpResponseException("response exception", null, new HttpResponse(404, "404 message", null))), expected);
}
public void testOnNotFound() {
assertEquals(function.apply(new ResourceNotFoundException()),expected);
}
public void testOnNotFoundChained() {
assertEquals(function.apply(new RuntimeException(new ResourceNotFoundException())),expected);
}
@Test(expectedExceptions = HttpResponseException.class)
public void testOn500() {
function.apply(new HttpResponseException("response exception", null, new HttpResponse(500, "500 message", null)));
}
}

View File

@ -0,0 +1,142 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.tmrk.enterprisecloud.xml;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet;
import com.google.inject.AbstractModule;
import com.google.inject.Module;
import com.google.inject.Provides;
import org.jclouds.crypto.Crypto;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseXMLWithJAXB;
import org.jclouds.logging.config.NullLoggingModule;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.BaseRestClientTest;
import org.jclouds.rest.RestContextSpec;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.tmrk.enterprisecloud.domain.hardware.HardwareConfiguration;
import org.jclouds.tmrk.enterprisecloud.domain.hardware.VirtualDisk;
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
import org.jclouds.tmrk.enterprisecloud.domain.network.NetworkReference;
import org.jclouds.tmrk.enterprisecloud.domain.network.VirtualNic;
import org.jclouds.tmrk.enterprisecloud.features.VirtualMachineAsyncClient;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import javax.inject.Named;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.Set;
import static org.jclouds.io.Payloads.newInputStreamPayload;
import static org.jclouds.rest.RestContextFactory.contextSpec;
import static org.jclouds.rest.RestContextFactory.createContextBuilder;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNotNull;
/**
* Tests behavior of JAXB parsing for VirtualMachines
* @author Jason King
*
*/
public class HardwareConfigurationJAXBParsingTest extends BaseRestClientTest {
@BeforeClass
void setupFactory() {
RestContextSpec<String, Integer> contextSpec = contextSpec("test", "http://localhost:9999", "1", "", "userfoo",
"credentialFoo", String.class, Integer.class,
ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule(), new AbstractModule() {
@Override
protected void configure() {}
@SuppressWarnings("unused")
@Provides
@Named("exception")
Set<String> exception() {
throw new AuthorizationException();
}
}));
injector = createContextBuilder(contextSpec).buildInjector();
parserFactory = injector.getInstance(ParseSax.Factory.class);
crypto = injector.getInstance(Crypto.class);
}
@Test(groups = "unit", testName = "HardwareConfigurationJAXBParsingTest")
public void testParse() throws Exception {
Method method = VirtualMachineAsyncClient.class.getMethod("getHardwareConfiguration", URI.class);
HttpRequest request = factory(VirtualMachineAsyncClient.class).createRequest(method,new URI("/1"));
assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class);
Function<HttpResponse, HardwareConfiguration> parser = (Function<HttpResponse, HardwareConfiguration>) RestAnnotationProcessor
.createResponseParser(parserFactory, injector, method, request);
InputStream is = getClass().getResourceAsStream("/hardwareConfiguration.xml");
HardwareConfiguration hardwareConfiguration = parser.apply(new HttpResponse(200, "ok", newInputStreamPayload(is)));
assertHardwareConfiguration(hardwareConfiguration);
}
private void assertHardwareConfiguration(HardwareConfiguration hardwareConfiguration) throws Exception {
assertEquals(1,hardwareConfiguration.getActions().size());
assertEquals(1,hardwareConfiguration.getProcessorCount());
ResourceCapacity memory = ResourceCapacity.builder().value(384).unit("MB").build();
assertEquals(memory,hardwareConfiguration.getMemory());
assertDisks(hardwareConfiguration.getVirtualDisks());
assertNics(hardwareConfiguration.getVirtualNics());
}
private void assertDisks(Set<VirtualDisk> disks) {
VirtualDisk disk = VirtualDisk.builder().index(0).name("Hard Disk 1")
.size(ResourceCapacity.builder().value(10).unit("GB").build())
.build();
assertEquals(ImmutableSet.of(disk), disks);
}
private void assertNics(Set<VirtualNic> nics) throws Exception {
assertEquals(1, nics.size());
NetworkReference network = NetworkReference.builder()
.href(new URI("/cloudapi/ecloud/networks/3936"))
.name("10.146.204.64/28")
.type("application/vnd.tmrk.cloud.network")
.networkType(NetworkReference.NetworkType.INTERNAL)
.build();
VirtualNic nic = VirtualNic.builder()
.macAddress("00:50:56:b8:00:58")
.name("Network adapter 1")
.network(network)
.unitNumber(7)
.build();
assertEquals(nic,nics.iterator().next());
}
}

View File

@ -0,0 +1,162 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.tmrk.enterprisecloud.xml;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.inject.AbstractModule;
import com.google.inject.Module;
import com.google.inject.Provides;
import org.jclouds.crypto.Crypto;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseXMLWithJAXB;
import org.jclouds.logging.config.NullLoggingModule;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.BaseRestClientTest;
import org.jclouds.rest.RestContextSpec;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.tmrk.enterprisecloud.domain.ConfigurationOptionRange;
import org.jclouds.tmrk.enterprisecloud.domain.CustomizationOption;
import org.jclouds.tmrk.enterprisecloud.domain.Link;
import org.jclouds.tmrk.enterprisecloud.domain.ResourceCapacityRange;
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
import org.jclouds.tmrk.enterprisecloud.domain.software.OperatingSystem;
import org.jclouds.tmrk.enterprisecloud.domain.template.Template;
import org.jclouds.tmrk.enterprisecloud.domain.template.TemplateStorage;
import org.jclouds.tmrk.enterprisecloud.features.TemplateAsyncClient;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import javax.inject.Named;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Set;
import static org.jclouds.io.Payloads.newInputStreamPayload;
import static org.jclouds.rest.RestContextFactory.contextSpec;
import static org.jclouds.rest.RestContextFactory.createContextBuilder;
import static org.testng.Assert.assertEquals;
/**
* Tests behavior of JAXB parsing for Templates
*
* @author Jason King
*/
@Test(groups = "unit", testName = "TemplateJAXBParsingTest")
public class TemplateJAXBParsingTest extends BaseRestClientTest {
@BeforeClass
void setupFactory() {
RestContextSpec<String, Integer> contextSpec = contextSpec("test", "http://localhost:9999", "1", "", "userfoo",
"credentialFoo", String.class, Integer.class,
ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule(), new AbstractModule() {
@Override
protected void configure() {}
@SuppressWarnings("unused")
@Provides
@Named("exception")
Set<String> exception() {
throw new AuthorizationException();
}
}));
injector = createContextBuilder(contextSpec).buildInjector();
parserFactory = injector.getInstance(ParseSax.Factory.class);
crypto = injector.getInstance(Crypto.class);
}
public void testParseTemplate() throws Exception {
Method method = TemplateAsyncClient.class.getMethod("getTemplate", URI.class);
HttpRequest request = factory(TemplateAsyncClient.class).createRequest(method,new URI("/1"));
assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class);
Function<HttpResponse, Template> parser = (Function<HttpResponse, Template>) RestAnnotationProcessor
.createResponseParser(parserFactory, injector, method, request);
InputStream is = getClass().getResourceAsStream("/template.xml");
Template template = parser.apply(new HttpResponse(200, "ok", newInputStreamPayload(is)));
assertLinks(template.getLinks().getLinks());
assertOperatingSystem(template.getOperatingSystem());
assertEquals(template.getDescription(),"");
assertProcessor(template.getProcessor());
assertMemory(template.getMemory());
assertStorage(template.getStorage());
assertEquals(template.getNetworkAdapters(),1);
assertCustomization(template.getCustomization());
}
private void assertLinks(Set<Link> links) {
assertEquals(links.size(),1);
Link link = Iterables.getOnlyElement(links);
assertEquals(link.getName(),"Default Compute Pool");
}
private void assertOperatingSystem(OperatingSystem os) throws URISyntaxException {
OperatingSystem expected = OperatingSystem.builder()
.href(new URI("/cloudapi/ecloud/operatingsystems/rhel5_64guest/computepools/89"))
.name("Red Hat Enterprise Linux 5 (64-bit)")
.type("application/vnd.tmrk.cloud.operatingSystem")
.build();
assertEquals(os,expected);
}
private void assertProcessor(ConfigurationOptionRange configuration) {
ConfigurationOptionRange expected = ConfigurationOptionRange.builder()
.minimum(1).maximum(8).stepFactor(1).build();
assertEquals(configuration, expected);
}
private void assertMemory(ResourceCapacityRange memory) {
ResourceCapacity min = ResourceCapacity.builder().value(256).unit("MB").build();
ResourceCapacity max = ResourceCapacity.builder().value(261120).unit("MB").build();
ResourceCapacity step = ResourceCapacity.builder().value(4).unit("MB").build();
ResourceCapacityRange expected = ResourceCapacityRange.builder()
.minimumSize(min).maximumSize(max).stepFactor(step).build();
assertEquals(memory, expected);
}
private void assertStorage(TemplateStorage storage) {
ResourceCapacity size = ResourceCapacity.builder().value(10).unit("GB").build();
TemplateStorage expected = TemplateStorage.builder().size(size).build();
assertEquals(storage, expected);
}
private void assertCustomization(CustomizationOption customization) {
CustomizationOption expected = CustomizationOption.builder()
.canPowerOn(false)
.passwordRequired(false)
.sshKeyRequired(true)
.type(CustomizationOption.CustomizationType.LINUX)
.build();
assertEquals(customization, expected);
}
}

View File

@ -0,0 +1,154 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.tmrk.enterprisecloud.xml;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet;
import com.google.inject.AbstractModule;
import com.google.inject.Module;
import com.google.inject.Provides;
import org.jclouds.crypto.Crypto;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseXMLWithJAXB;
import org.jclouds.logging.config.NullLoggingModule;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.BaseRestClientTest;
import org.jclouds.rest.RestContextSpec;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.tmrk.enterprisecloud.domain.*;
import org.jclouds.tmrk.enterprisecloud.domain.hardware.DiskConfigurationOption;
import org.jclouds.tmrk.enterprisecloud.domain.hardware.DiskConfigurationOptionRange;
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachineConfigurationOptions;
import org.jclouds.tmrk.enterprisecloud.features.VirtualMachineAsyncClient;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import javax.inject.Named;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.Set;
import static org.jclouds.io.Payloads.newInputStreamPayload;
import static org.jclouds.rest.RestContextFactory.contextSpec;
import static org.jclouds.rest.RestContextFactory.createContextBuilder;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
/**
* Tests behavior of JAXB parsing for VirtualMachineConfigurationOptions
*
* @author Jason King
*/
@Test(groups = "unit", testName = "VirtualMachineConfigurationOptionsJAXBParsingTest")
public class VirtualMachineConfigurationOptionsJAXBParsingTest extends BaseRestClientTest {
@BeforeClass
void setupFactory() {
RestContextSpec<String, Integer> contextSpec = contextSpec("test", "http://localhost:9999", "1", "", "userfoo",
"credentialFoo", String.class, Integer.class,
ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule(), new AbstractModule() {
@Override
protected void configure() {}
@SuppressWarnings("unused")
@Provides
@Named("exception")
Set<String> exception() {
throw new AuthorizationException();
}
}));
injector = createContextBuilder(contextSpec).buildInjector();
parserFactory = injector.getInstance(ParseSax.Factory.class);
crypto = injector.getInstance(Crypto.class);
}
@Test
public void testParseVirtualMachineWithJAXB() throws Exception {
Method method = VirtualMachineAsyncClient.class.getMethod("getConfigurationOptions", URI.class);
HttpRequest request = factory(VirtualMachineAsyncClient.class).createRequest(method,new URI("/1"));
assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class);
Function<HttpResponse, VirtualMachineConfigurationOptions> parser = (Function<HttpResponse, VirtualMachineConfigurationOptions>) RestAnnotationProcessor
.createResponseParser(parserFactory, injector, method, request);
InputStream is = getClass().getResourceAsStream("/virtualMachineConfigurationOptions.xml");
VirtualMachineConfigurationOptions configurationOptions = parser.apply(new HttpResponse(200, "ok", newInputStreamPayload(is)));
assertProcessorOptions(configurationOptions.getProcessor());
assertMemoryOptions(configurationOptions.getMemory());
assertDiskConfigurationOption(configurationOptions.getDisk());
assertNetworkAdapterOptions(configurationOptions.getNetworkAdapter());
assertCustomizationOption(configurationOptions.getCustomization());
}
private void assertProcessorOptions(ConfigurationOptionRange processor) {
assertEquals(processor.getMinimum(),1);
assertEquals(processor.getMaximum(),8);
assertEquals(processor.getStepFactor(),1);
}
private void assertMemoryOptions(ResourceCapacityRange memory) {
assertEquals(memory.getMinimumSize(), ResourceCapacity.builder().value(256).unit("MB").build());
assertEquals(memory.getMaximumSize(), ResourceCapacity.builder().value(261120).unit("MB").build());
assertEquals(memory.getStepFactor(), ResourceCapacity.builder().value(4).unit("MB").build());
}
private void assertNetworkAdapterOptions(ConfigurationOptionRange networkAdapter) {
assertEquals(networkAdapter.getMinimum(),1);
assertEquals(networkAdapter.getMaximum(),4);
assertEquals(networkAdapter.getStepFactor(),1);
}
private void assertCustomizationOption(CustomizationOption customization) {
assertEquals(customization.getType(), CustomizationOption.CustomizationType.LINUX);
assertFalse(customization.canPowerOn());
assertFalse(customization.isPasswordRequired());
assertTrue(customization.isSshKeyRequired());
}
private void assertDiskConfigurationOption(DiskConfigurationOption diskConfigurationOption) {
assertEquals(diskConfigurationOption.getMinimum(),1);
assertEquals(diskConfigurationOption.getMaximum(), 15);
ResourceCapacityRange systemDiskRange = ResourceCapacityRange.builder()
.minimumSize(ResourceCapacity.builder().value(1).unit("GB").build())
.maximumSize(ResourceCapacity.builder().value(512).unit("GB").build())
.stepFactor(ResourceCapacity.builder().value(1).unit("GB").build())
.build();
assertEquals(diskConfigurationOption.getSystemDisk(), DiskConfigurationOptionRange.builder().resourceCapacityRange(systemDiskRange).monthlyCost(0).build());
ResourceCapacityRange dataDiskRange = ResourceCapacityRange.builder()
.minimumSize(ResourceCapacity.builder().value(1).unit("GB").build())
.maximumSize(ResourceCapacity.builder().value(512).unit("GB").build())
.stepFactor(ResourceCapacity.builder().value(2).unit("GB").build())
.build();
assertEquals(diskConfigurationOption.getDataDisk(), DiskConfigurationOptionRange.builder().resourceCapacityRange(dataDiskRange).monthlyCost(0).build());
}
}

View File

@ -35,18 +35,18 @@ import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.BaseRestClientTest;
import org.jclouds.rest.RestContextSpec;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.tmrk.enterprisecloud.domain.*;
import org.jclouds.tmrk.enterprisecloud.domain.Layout;
import org.jclouds.tmrk.enterprisecloud.domain.hardware.HardwareConfiguration;
import org.jclouds.tmrk.enterprisecloud.domain.hardware.Memory;
import org.jclouds.tmrk.enterprisecloud.domain.hardware.VirtualDisk;
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
import org.jclouds.tmrk.enterprisecloud.domain.network.AssignedIpAddresses;
import org.jclouds.tmrk.enterprisecloud.domain.network.DeviceNetwork;
import org.jclouds.tmrk.enterprisecloud.domain.network.NetworkReference;
import org.jclouds.tmrk.enterprisecloud.domain.network.VirtualNic;
import org.jclouds.tmrk.enterprisecloud.domain.software.OperatingSystem;
import org.jclouds.tmrk.enterprisecloud.domain.software.ToolsStatus;
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachine.VirtualMachineStatus;
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachine;
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachine.VirtualMachineStatus;
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachineIpAddresses;
import org.jclouds.tmrk.enterprisecloud.features.VirtualMachineAsyncClient;
import org.testng.Assert;
@ -151,7 +151,7 @@ public class VirtualMachineJAXBParsingTest extends BaseRestClientTest {
private void assertHardwareConfiguration(HardwareConfiguration hardwareConfiguration) throws Exception {
assertEquals(1,hardwareConfiguration.getActions().size());
assertEquals(1,hardwareConfiguration.getProcessorCount());
Memory memory = Memory.builder().value(384).unit("MB").build();
ResourceCapacity memory = ResourceCapacity.builder().value(384).unit("MB").build();
assertEquals(memory,hardwareConfiguration.getMemory());
assertDisks(hardwareConfiguration.getVirtualDisks());
assertNics(hardwareConfiguration.getVirtualNics());
@ -159,7 +159,7 @@ public class VirtualMachineJAXBParsingTest extends BaseRestClientTest {
private void assertDisks(Set<VirtualDisk> disks) {
VirtualDisk disk = VirtualDisk.builder().index(0).name("Hard Disk 1")
.size(Size.builder().value(10).unit("GB").build())
.size(ResourceCapacity.builder().value(10).unit("GB").build())
.build();
assertEquals(ImmutableSet.of(disk), disks);

View File

@ -0,0 +1,37 @@
<HardwareConfiguration
href="/cloudapi/ecloud/virtualmachines/5504/hardwareconfiguration"
type="application/vnd.tmrk.cloud.virtualMachineHardware"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Actions>
<Action href="/cloudapi/ecloud/virtualmachines/5504/hardwareconfiguration"
name="edit"
type="application/vnd.tmrk.cloud.virtualMachineHardware"/>
</Actions>
<ProcessorCount>1</ProcessorCount>
<Memory>
<Unit>MB</Unit>
<Value>384</Value>
</Memory>
<Disks>
<Disk>
<Index>0</Index>
<Size>
<Unit>GB</Unit>
<Value>10</Value>
</Size>
<Name>Hard Disk 1</Name>
</Disk>
</Disks>
<Nics>
<Nic>
<UnitNumber>7</UnitNumber>
<Name>Network adapter 1</Name>
<MacAddress>00:50:56:b8:00:58</MacAddress>
<Network href="/cloudapi/ecloud/networks/3936"
name="10.146.204.64/28"
type="application/vnd.tmrk.cloud.network">
<NetworkType>Internal</NetworkType>
</Network>
</Nic>
</Nics>
</HardwareConfiguration>

View File

@ -0,0 +1,46 @@
<Template href="/cloudapi/ecloud/templates/6/computepools/89"
name="CentOS 5.5 x64" type="application/vnd.tmrk.cloud.template"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Links>
<Link href="/cloudapi/ecloud/computepools/89"
name="Default Compute Pool"
type="application/vnd.tmrk.cloud.computePool" rel="up"/>
</Links>
<OperatingSystem
href="/cloudapi/ecloud/operatingsystems/rhel5_64guest/computepools/89"
name="Red Hat Enterprise Linux 5 (64-bit)"
type="application/vnd.tmrk.cloud.operatingSystem"/>
<Description/>
<Processor>
<Minimum>1</Minimum>
<Maximum>8</Maximum>
<StepFactor>1</StepFactor>
</Processor>
<Memory>
<MinimumSize>
<Unit>MB</Unit>
<Value>256</Value>
</MinimumSize>
<MaximumSize>
<Unit>MB</Unit>
<Value>261120</Value>
</MaximumSize>
<StepFactor>
<Unit>MB</Unit>
<Value>4</Value>
</StepFactor>
</Memory>
<Storage>
<Size>
<Unit>GB</Unit>
<Value>10</Value>
</Size>
</Storage>
<NetworkAdapters>1</NetworkAdapters>
<Customization>
<Type>Linux</Type>
<CanPowerOn>false</CanPowerOn>
<PasswordRequired>false</PasswordRequired>
<SshKeyRequired>true</SshKeyRequired>
</Customization>
</Template>

View File

@ -0,0 +1,55 @@
<Templates href="/cloudapi/ecloud/templates/computepools/89"
type="application/vnd.tmrk.cloud.template; type=collection"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Links>
<Link href="/cloudapi/ecloud/computepools/89"
name="Default Compute Pool"
type="application/vnd.tmrk.cloud.computePool" rel="up"/>
</Links>
<Families>
<Family>
<Name>Standard Templates</Name>
<Categories>
<Category>
<Name>OS Only</Name>
<OperatingSystems>
<OperatingSystem>
<Name>Windows</Name>
<Templates>
<Template
href="/cloudapi/ecloud/templates/2/computepools/89"
name="Windows Server 2003 R2 Standard x86 SP2"
type="application/vnd.tmrk.cloud.template"/>
<Template
href="/cloudapi/ecloud/templates/10/computepools/89"
name="Windows Server 2008 Standard SP2 x86"
type="application/vnd.tmrk.cloud.template"/>
<Template
href="/cloudapi/ecloud/templates/1/computepools/89"
name="Windows Server 2008 R2 Standard x64 RTM"
type="application/vnd.tmrk.cloud.template"/>
<Template
href="/cloudapi/ecloud/templates/9/computepools/89"
name="Windows Server 2008 Standard SP2 x64"
type="application/vnd.tmrk.cloud.template"/>
</Templates>
</OperatingSystem>
<OperatingSystem>
<Name>Linux</Name>
<Templates>
<Template
href="/cloudapi/ecloud/templates/5/computepools/89"
name="CentOS 5.5 x32"
type="application/vnd.tmrk.cloud.template"/>
<Template
href="/cloudapi/ecloud/templates/6/computepools/89"
name="CentOS 5.5 x64"
type="application/vnd.tmrk.cloud.template"/>
</Templates>
</OperatingSystem>
</OperatingSystems>
</Category>
</Categories>
</Family>
</Families>
</Templates>

View File

@ -0,0 +1,73 @@
<VirtualMachineConfigurationOptions
href="/cloudapi/ecloud/virtualmachines/5504/configurationoptions"
type="application/vnd.tmrk.cloud.virtualMachineConfigurationOptions"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Processor>
<Minimum>1</Minimum>
<Maximum>8</Maximum>
<StepFactor>1</StepFactor>
</Processor>
<Memory>
<MinimumSize>
<Unit>MB</Unit>
<Value>256</Value>
</MinimumSize>
<MaximumSize>
<Unit>MB</Unit>
<Value>261120</Value>
</MaximumSize>
<StepFactor>
<Unit>MB</Unit>
<Value>4</Value>
</StepFactor>
</Memory>
<Disk>
<Minimum>1</Minimum>
<Maximum>15</Maximum>
<SystemDisk>
<ResourceCapacityRange>
<MinimumSize>
<Unit>GB</Unit>
<Value>1</Value>
</MinimumSize>
<MaximumSize>
<Unit>GB</Unit>
<Value>512</Value>
</MaximumSize>
<StepFactor>
<Unit>GB</Unit>
<Value>1</Value>
</StepFactor>
</ResourceCapacityRange>
<MonthlyCost>0</MonthlyCost>
</SystemDisk>
<DataDisk>
<ResourceCapacityRange>
<MinimumSize>
<Unit>GB</Unit>
<Value>1</Value>
</MinimumSize>
<MaximumSize>
<Unit>GB</Unit>
<Value>512</Value>
</MaximumSize>
<StepFactor>
<Unit>GB</Unit>
<Value>2</Value>
</StepFactor>
</ResourceCapacityRange>
<MonthlyCost>0</MonthlyCost>
</DataDisk>
</Disk>
<NetworkAdapter>
<Minimum>1</Minimum>
<Maximum>4</Maximum>
<StepFactor>1</StepFactor>
</NetworkAdapter>
<Customization>
<Type>Linux</Type>
<CanPowerOn>false</CanPowerOn>
<PasswordRequired>false</PasswordRequired>
<SshKeyRequired>true</SshKeyRequired>
</Customization>
</VirtualMachineConfigurationOptions>