From 6548fe12122f1bd369d0f0d75e20e68a148327ce Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Mon, 9 May 2011 15:54:04 -0700 Subject: [PATCH 01/38] fixed rackspace loadbalancers where DELETE requires Accept */* --- .../domain/LoadBalancer.java | 4 +-- .../domain/LoadBalancerRequest.java | 2 +- .../domain/internal/BaseLoadBalancer.java | 22 ++++++------- .../features/LoadBalancerAsyncClient.java | 1 + .../features/LoadBalancerAsyncClientTest.java | 2 +- .../features/LoadBalancerClientLiveTest.java | 31 +++++++++++-------- 6 files changed, 33 insertions(+), 29 deletions(-) diff --git a/providers/cloudloadbalancers-us/src/main/java/org/jclouds/cloudloadbalancers/domain/LoadBalancer.java b/providers/cloudloadbalancers-us/src/main/java/org/jclouds/cloudloadbalancers/domain/LoadBalancer.java index e8321bf339..757ecc092a 100644 --- a/providers/cloudloadbalancers-us/src/main/java/org/jclouds/cloudloadbalancers/domain/LoadBalancer.java +++ b/providers/cloudloadbalancers-us/src/main/java/org/jclouds/cloudloadbalancers/domain/LoadBalancer.java @@ -141,7 +141,7 @@ public class LoadBalancer extends BaseLoadBalancer { } @Override - public Builder port(int port) { + public Builder port(Integer port) { return Builder.class.cast(super.port(port)); } @@ -218,7 +218,7 @@ public class LoadBalancer extends BaseLoadBalancer { private final Date updated; private final boolean connectionLoggingEnabled; - public LoadBalancer(String region, int id, String name, String protocol, int port, String algorithm, Status status, + public LoadBalancer(String region, int id, String name, String protocol, Integer port, String algorithm, Status status, Iterable virtualIPs, Iterable nodes, String sessionPersistenceType, String clusterName, Date created, Date updated, boolean connectionLoggingEnabled) { super(name, protocol, port, algorithm, nodes); diff --git a/providers/cloudloadbalancers-us/src/main/java/org/jclouds/cloudloadbalancers/domain/LoadBalancerRequest.java b/providers/cloudloadbalancers-us/src/main/java/org/jclouds/cloudloadbalancers/domain/LoadBalancerRequest.java index f69e4a54df..9d7bbec8a5 100644 --- a/providers/cloudloadbalancers-us/src/main/java/org/jclouds/cloudloadbalancers/domain/LoadBalancerRequest.java +++ b/providers/cloudloadbalancers-us/src/main/java/org/jclouds/cloudloadbalancers/domain/LoadBalancerRequest.java @@ -105,7 +105,7 @@ public class LoadBalancerRequest extends BaseLoadBalancer, T extends BaseLoadBalancer< public static class Builder, T extends BaseLoadBalancer> { protected String name; protected String protocol; - protected int port = -1; + protected Integer port; protected String algorithm; protected Set nodes = Sets.newLinkedHashSet(); @@ -64,7 +63,7 @@ public class BaseLoadBalancer, T extends BaseLoadBalancer< return this; } - public Builder port(int port) { + public Builder port(Integer port) { this.port = port; return this; } @@ -103,17 +102,16 @@ public class BaseLoadBalancer, T extends BaseLoadBalancer< protected String name; protected String protocol; - protected int port; + protected Integer port; protected String algorithm; // so tests will come out consistently protected SortedSet nodes = ImmutableSortedSet.of(); - public BaseLoadBalancer(String name, String protocol, int port, String algorithm, Iterable nodes) { + public BaseLoadBalancer(String name, String protocol, Integer port, String algorithm, Iterable nodes) { this.name = checkNotNull(name, "name"); - this.protocol = checkNotNull(protocol, "protocol"); - checkArgument(port != -1, "port must be specified"); - this.port = port; - this.algorithm = algorithm; + this.protocol = protocol;// null on deleted LB + this.port = port;// null on deleted LB + this.algorithm = algorithm;// null on deleted LB this.nodes = ImmutableSortedSet.copyOf(checkNotNull(nodes, "nodes")); } @@ -130,7 +128,7 @@ public class BaseLoadBalancer, T extends BaseLoadBalancer< return protocol; } - public int getPort() { + public Integer getPort() { return port; } @@ -144,8 +142,8 @@ public class BaseLoadBalancer, T extends BaseLoadBalancer< @Override public int hashCode() { - final int prime = 31; - int result = 1; + final Integer prime = 31; + Integer result = 1; result = prime * result + ((name == null) ? 0 : name.hashCode()); return result; } diff --git a/providers/cloudloadbalancers-us/src/main/java/org/jclouds/cloudloadbalancers/features/LoadBalancerAsyncClient.java b/providers/cloudloadbalancers-us/src/main/java/org/jclouds/cloudloadbalancers/features/LoadBalancerAsyncClient.java index c62319c891..ee50ea4b04 100644 --- a/providers/cloudloadbalancers-us/src/main/java/org/jclouds/cloudloadbalancers/features/LoadBalancerAsyncClient.java +++ b/providers/cloudloadbalancers-us/src/main/java/org/jclouds/cloudloadbalancers/features/LoadBalancerAsyncClient.java @@ -106,6 +106,7 @@ public interface LoadBalancerAsyncClient { @DELETE @ExceptionParser(ReturnVoidOnNotFoundOr404.class) @Path("/loadbalancers/{id}") + @Consumes("*/*") ListenableFuture removeLoadBalancer(@PathParam("id") int id); } diff --git a/providers/cloudloadbalancers-us/src/test/java/org/jclouds/cloudloadbalancers/features/LoadBalancerAsyncClientTest.java b/providers/cloudloadbalancers-us/src/test/java/org/jclouds/cloudloadbalancers/features/LoadBalancerAsyncClientTest.java index cefc0bebce..16692d3763 100644 --- a/providers/cloudloadbalancers-us/src/test/java/org/jclouds/cloudloadbalancers/features/LoadBalancerAsyncClientTest.java +++ b/providers/cloudloadbalancers-us/src/test/java/org/jclouds/cloudloadbalancers/features/LoadBalancerAsyncClientTest.java @@ -147,7 +147,7 @@ public class LoadBalancerAsyncClientTest extends BaseCloudLoadBalancersAsyncClie assertRequestLineEquals(httpRequest, "DELETE https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/1234/loadbalancers/5 HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, ""); + assertNonPayloadHeadersEqual(httpRequest, "Accept: */*\n"); assertPayloadEquals(httpRequest, null, null, false); assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); diff --git a/providers/cloudloadbalancers-us/src/test/java/org/jclouds/cloudloadbalancers/features/LoadBalancerClientLiveTest.java b/providers/cloudloadbalancers-us/src/test/java/org/jclouds/cloudloadbalancers/features/LoadBalancerClientLiveTest.java index a6199de47f..9eddff9a5d 100644 --- a/providers/cloudloadbalancers-us/src/test/java/org/jclouds/cloudloadbalancers/features/LoadBalancerClientLiveTest.java +++ b/providers/cloudloadbalancers-us/src/test/java/org/jclouds/cloudloadbalancers/features/LoadBalancerClientLiveTest.java @@ -44,7 +44,6 @@ import com.google.common.collect.Sets; public class LoadBalancerClientLiveTest extends BaseCloudLoadBalancersClientLiveTest { private Set lbs = Sets.newLinkedHashSet(); - // ticket 130960 getting 500 errors deleting load balancers @AfterGroups(groups = "live") protected void tearDown() { for (LoadBalancer lb : lbs) { @@ -60,6 +59,8 @@ public class LoadBalancerClientLiveTest extends BaseCloudLoadBalancersClientLive assert null != response; assertTrue(response.size() >= 0); for (LoadBalancer lb : response) { + if (lb.getStatus() == LoadBalancer.Status.DELETED) + continue; assert lb.getRegion() != null : lb; assert lb.getName() != null : lb; assert lb.getId() != -1 : lb; @@ -73,17 +74,21 @@ public class LoadBalancerClientLiveTest extends BaseCloudLoadBalancersClientLive assert lb.getNodes().size() == 0 : lb; LoadBalancer getDetails = client.getLoadBalancerClient(region).getLoadBalancer(lb.getId()); - assertEquals(getDetails.getRegion(), lb.getRegion()); - assertEquals(getDetails.getName(), lb.getName()); - assertEquals(getDetails.getId(), lb.getId()); - assertEquals(getDetails.getProtocol(), lb.getProtocol()); - assertEquals(getDetails.getPort(), lb.getPort()); - assertEquals(getDetails.getStatus(), lb.getStatus()); - assertEquals(getDetails.getCreated(), lb.getCreated()); - assertEquals(getDetails.getUpdated(), lb.getUpdated()); - assertEquals(getDetails.getVirtualIPs(), lb.getVirtualIPs()); - // node info not available during list; - assert getDetails.getNodes().size() > 0 : lb; + try { + assertEquals(getDetails.getRegion(), lb.getRegion()); + assertEquals(getDetails.getName(), lb.getName()); + assertEquals(getDetails.getId(), lb.getId()); + assertEquals(getDetails.getProtocol(), lb.getProtocol()); + assertEquals(getDetails.getPort(), lb.getPort()); + assertEquals(getDetails.getStatus(), lb.getStatus()); + assertEquals(getDetails.getCreated(), lb.getCreated()); + assertEquals(getDetails.getUpdated(), lb.getUpdated()); + assertEquals(getDetails.getVirtualIPs(), lb.getVirtualIPs()); + // node info not available during list; + assert getDetails.getNodes().size() > 0 : lb; + } catch (AssertionError e) { + throw new AssertionError(String.format("%s\n%s - %s", e.getMessage(),getDetails, lb)); + } } } } @@ -122,7 +127,7 @@ public class LoadBalancerClientLiveTest extends BaseCloudLoadBalancersClientLive assertEquals(lb.getRegion(), region); assertEquals(lb.getName(), name); assertEquals(lb.getProtocol(), "HTTP"); - assertEquals(lb.getPort(), 80); + assertEquals(lb.getPort(), new Integer(80)); assertEquals(Iterables.get(lb.getVirtualIPs(), 0).getType(), Type.PUBLIC); } From de463ffb8ed2d3a196bb5af387b436de418ec2ca Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Mon, 9 May 2011 22:00:10 -0700 Subject: [PATCH 02/38] updated tests in cloudstack and added network create/destroy --- .../features/AddressAsyncClient.java | 4 +- .../cloudstack/features/AddressClient.java | 2 +- .../features/NetworkAsyncClient.java | 21 ++ .../cloudstack/features/NetworkClient.java | 28 +++ .../features/VirtualMachineAsyncClient.java | 6 +- .../features/VirtualMachineClient.java | 7 +- .../ReuseOrAssociateNewPublicIPAddress.java | 2 +- .../options/CreateNetworkOptions.java | 202 +++++++++++++++ .../cloudstack/predicates/ZonePredicates.java | 71 ++++++ .../features/AddressAsyncClientTest.java | 4 +- .../features/AddressClientLiveTest.java | 2 +- .../features/NetworkAsyncClientTest.java | 68 +++++- .../features/NetworkClientLiveTest.java | 105 ++++++-- .../features/SecurityGroupClientLiveTest.java | 4 - .../VirtualMachineAsyncClientTest.java | 8 +- .../VirtualMachineClientLiveTest.java | 2 +- ...euseOrAssociateNewPublicIPAddressTest.java | 4 +- .../options/CreateNetworkOptionsTest.java | 136 +++++++++++ .../cloudstack/parse/BaseItemParserTest.java | 28 --- .../cloudstack/parse/BaseParserTest.java | 79 ------ .../cloudstack/parse/BaseSetParserTest.java | 52 ---- .../parse/ListAccountsResponseTest.java | 20 +- .../parse/ListCapabilitiesResponseTest.java | 1 + .../parse/ListDiskOfferingsResponseTest.java | 1 + .../parse/ListHypervisorsResponseTest.java | 6 +- .../ListNetworkOfferingsResponseTest.java | 1 + .../parse/ListNetworksResponseTest.java | 1 + .../parse/ListOSCategoriesResponseTest.java | 14 +- .../parse/ListOSTypesResponseTest.java | 230 ++++++++++++++++++ .../ListPortForwardingRulesResponseTest.java | 1 + .../ListPublicIPAddressesResponseTest.java | 1 + .../parse/ListSecurityGroupsResponseTest.java | 1 + .../ListServiceOfferingsResponseTest.java | 1 + .../parse/ListTemplatesResponseTest.java | 1 + .../ListVirtualMachinesResponseTest.java | 1 + .../parse/ListZonesResponseTest.java | 1 + .../test/resources/listostypesresponse.json | 1 + 37 files changed, 898 insertions(+), 219 deletions(-) create mode 100644 sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/CreateNetworkOptions.java create mode 100644 sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/predicates/ZonePredicates.java create mode 100644 sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/CreateNetworkOptionsTest.java delete mode 100644 sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/BaseItemParserTest.java delete mode 100644 sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/BaseParserTest.java delete mode 100644 sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/BaseSetParserTest.java create mode 100644 sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListOSTypesResponseTest.java create mode 100644 sandbox-apis/cloudstack/src/test/resources/listostypesresponse.json diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/AddressAsyncClient.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/AddressAsyncClient.java index 306d2f5c55..df659af9a1 100644 --- a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/AddressAsyncClient.java +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/AddressAsyncClient.java @@ -73,13 +73,13 @@ public interface AddressAsyncClient { ListenableFuture getPublicIPAddress(@QueryParam("id") long id); /** - * @see AddressClient#associateIPAddress + * @see AddressClient#associateIPAddressInZone */ @GET @QueryParams(keys = "command", values = "associateIpAddress") @Unwrap @Consumes(MediaType.APPLICATION_JSON) - ListenableFuture associateIPAddress(@QueryParam("zoneid") long zoneId, + ListenableFuture associateIPAddressInZone(@QueryParam("zoneid") long zoneId, AssociateIPAddressOptions... options); /** diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/AddressClient.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/AddressClient.java index 91dfdccce8..7f58caeb18 100644 --- a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/AddressClient.java +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/AddressClient.java @@ -62,7 +62,7 @@ public interface AddressClient { * the ID of the availability zone you want to acquire an public IP address from * @return IPAddress */ - AsyncCreateResponse associateIPAddress(long zoneId, AssociateIPAddressOptions... options); + AsyncCreateResponse associateIPAddressInZone(long zoneId, AssociateIPAddressOptions... options); /** * Disassociates an ip address from the account. diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/NetworkAsyncClient.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/NetworkAsyncClient.java index 22bf0b7281..02222189ad 100644 --- a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/NetworkAsyncClient.java +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/NetworkAsyncClient.java @@ -25,8 +25,10 @@ import javax.ws.rs.GET; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; +import org.jclouds.cloudstack.domain.AsyncCreateResponse; import org.jclouds.cloudstack.domain.Network; import org.jclouds.cloudstack.filters.QuerySigner; +import org.jclouds.cloudstack.options.CreateNetworkOptions; import org.jclouds.cloudstack.options.ListNetworksOptions; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.QueryParams; @@ -34,6 +36,7 @@ import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.Unwrap; import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; import com.google.common.util.concurrent.ListenableFuture; @@ -69,4 +72,22 @@ public interface NetworkAsyncClient { @ExceptionParser(ReturnNullOnNotFoundOr404.class) ListenableFuture getNetwork(@QueryParam("id") long id); + /** + * @see NetworkClient#createNetworkInZone + */ + @GET + @QueryParams(keys = "command", values = "createNetwork") + @Unwrap + @Consumes(MediaType.APPLICATION_JSON) + ListenableFuture createNetworkInZone(@QueryParam("zoneid") long zoneId, + @QueryParam("networkofferingid") long networkOfferingId, @QueryParam("name") String name, + @QueryParam("displaytext") String displayText, CreateNetworkOptions... options); + + /** + * @see NetworkClient#deleteNetwork + */ + @GET + @QueryParams(keys = "command", values = "deleteNetwork") + @ExceptionParser(ReturnVoidOnNotFoundOr404.class) + ListenableFuture deleteNetwork(@QueryParam("id") long id); } diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/NetworkClient.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/NetworkClient.java index 8c9cf1441d..e766362f7e 100644 --- a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/NetworkClient.java +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/NetworkClient.java @@ -21,7 +21,9 @@ package org.jclouds.cloudstack.features; import java.util.Set; import java.util.concurrent.TimeUnit; +import org.jclouds.cloudstack.domain.AsyncCreateResponse; import org.jclouds.cloudstack.domain.Network; +import org.jclouds.cloudstack.options.CreateNetworkOptions; import org.jclouds.cloudstack.options.ListNetworksOptions; import org.jclouds.concurrent.Timeout; @@ -53,4 +55,30 @@ public interface NetworkClient { */ Network getNetwork(long id); + /** + * Creates a network + * + * @param zoneId + * the Zone ID for the Vlan ip range + * @param networkOfferingId + * the network offering id + * @param name + * the name of the network + * @param displayText + * the display text of the network + * @param options + * optional parameters + * @return task in progress + */ + AsyncCreateResponse createNetworkInZone(long zoneId, long networkOfferingId, String name, String displayText, + CreateNetworkOptions... options); + + + /** + * Deletes a network + * + * @param id + * the ID of the network + */ + void deleteNetwork(long id); } diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VirtualMachineAsyncClient.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VirtualMachineAsyncClient.java index 6de988d67b..dd48109d36 100644 --- a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VirtualMachineAsyncClient.java +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VirtualMachineAsyncClient.java @@ -72,14 +72,14 @@ public interface VirtualMachineAsyncClient { ListenableFuture getVirtualMachine(@QueryParam("id") long id); /** - * @see VirtualMachineClient#deployVirtualMachine + * @see VirtualMachineClient#deployVirtualMachineInZone */ @GET @QueryParams(keys = "command", values = "deployVirtualMachine") @Unwrap @Consumes(MediaType.APPLICATION_JSON) - ListenableFuture deployVirtualMachine(@QueryParam("serviceofferingid") long serviceOfferingId, - @QueryParam("templateid") long templateId, @QueryParam("zoneid") long zoneId, + ListenableFuture deployVirtualMachineInZone( @QueryParam("zoneid") long zoneId, @QueryParam("serviceofferingid") long serviceOfferingId, + @QueryParam("templateid") long templateId, DeployVirtualMachineOptions... options); /** diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VirtualMachineClient.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VirtualMachineClient.java index 8882ff2236..1389309807 100644 --- a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VirtualMachineClient.java +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VirtualMachineClient.java @@ -59,15 +59,16 @@ public interface VirtualMachineClient { * Creates and automatically starts a virtual machine based on a service offering, disk offering, * and template. * + * @param zoneId + * availability zone for the virtual machine * @param serviceOfferingId * the ID of the service offering for the virtual machine * @param templateId * the ID of the template for the virtual machine - * @param zoneId - * availability zone for the virtual machine + * * @return virtual machine */ - AsyncCreateResponse deployVirtualMachine(long serviceOfferingId, long templateId, long zoneId, + AsyncCreateResponse deployVirtualMachineInZone(long zoneId, long serviceOfferingId, long templateId, DeployVirtualMachineOptions... options); /** diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/functions/ReuseOrAssociateNewPublicIPAddress.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/functions/ReuseOrAssociateNewPublicIPAddress.java index 091c4c46c3..3777a47913 100644 --- a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/functions/ReuseOrAssociateNewPublicIPAddress.java +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/functions/ReuseOrAssociateNewPublicIPAddress.java @@ -82,7 +82,7 @@ public class ReuseOrAssociateNewPublicIPAddress implements Function jobComplete) { - AsyncCreateResponse job = client.getAddressClient().associateIPAddress(network.getZoneId(), + AsyncCreateResponse job = client.getAddressClient().associateIPAddressInZone(network.getZoneId(), networkId(network.getId())); checkState(jobComplete.apply(job.getJobId()), "job %d failed to complete", job.getJobId()); PublicIPAddress ip = client.getAsyncJobClient(). getAsyncJob(job.getJobId()).getResult(); diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/CreateNetworkOptions.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/CreateNetworkOptions.java new file mode 100644 index 0000000000..1897a0cf04 --- /dev/null +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/CreateNetworkOptions.java @@ -0,0 +1,202 @@ +/** + * + * Copyright (C) 2011 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed 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.options; + +import com.google.common.collect.ImmutableSet; + +/** + * Options used to control what networks information is returned + * + * @see + * @author Adrian Cole + */ +public class CreateNetworkOptions extends AccountInDomainOptions { + + public static final CreateNetworkOptions NONE = new CreateNetworkOptions(); + + /** + * @param isDefault + * true if network is default, false otherwise + */ + public CreateNetworkOptions isDefault(boolean isDefault) { + this.queryParameters.replaceValues("isdefault", ImmutableSet.of(isDefault + "")); + return this; + } + + /** + * @param isShared + * true if network is shared, false otherwise + */ + public CreateNetworkOptions isShared(boolean isShared) { + this.queryParameters.replaceValues("isshared", ImmutableSet.of(isShared + "")); + return this; + } + + /** + * @param startIP + * the beginning IP address in the VLAN IP range + */ + public CreateNetworkOptions startIP(String startIP) { + this.queryParameters.replaceValues("startip", ImmutableSet.of(startIP)); + return this; + } + + /** + * @param endIP + * the ending IP address in the VLAN IP range + */ + public CreateNetworkOptions endIP(String endIP) { + this.queryParameters.replaceValues("endip", ImmutableSet.of(endIP)); + return this; + } + + /** + * @param gateway + * the gateway of the VLAN IP range + */ + public CreateNetworkOptions gateway(String gateway) { + this.queryParameters.replaceValues("gateway", ImmutableSet.of(gateway)); + return this; + } + + /** + * @param netmask + * the netmask of the VLAN IP range + */ + public CreateNetworkOptions netmask(String netmask) { + this.queryParameters.replaceValues("netmask", ImmutableSet.of(netmask)); + return this; + } + + /** + * @param networkDomain + * network domain + */ + public CreateNetworkOptions networkDomain(String networkDomain) { + this.queryParameters.replaceValues("networkdomain", ImmutableSet.of(networkDomain)); + return this; + } + + /** + * @param vlan + * the ID or VID of the VLAN. Default is an "untagged" VLAN. + */ + public CreateNetworkOptions vlan(String vlan) { + this.queryParameters.replaceValues("vlan", ImmutableSet.of(vlan)); + return this; + } + + public static class Builder { + /** + * @see CreateNetworkOptions#isDefault + */ + public static CreateNetworkOptions isDefault(boolean isDefault) { + CreateNetworkOptions options = new CreateNetworkOptions(); + return options.isDefault(isDefault); + } + + /** + * @see CreateNetworkOptions#isShared + */ + public static CreateNetworkOptions isShared(boolean isShared) { + CreateNetworkOptions options = new CreateNetworkOptions(); + return options.isShared(isShared); + } + + /** + * @see CreateNetworkOptions#startIP(String) + */ + public static CreateNetworkOptions startIP(String startIP) { + CreateNetworkOptions options = new CreateNetworkOptions(); + return options.startIP(startIP); + } + + /** + * @see CreateNetworkOptions#endIP(String) + */ + public static CreateNetworkOptions endIP(String endIP) { + CreateNetworkOptions options = new CreateNetworkOptions(); + return options.endIP(endIP); + } + + /** + * @see CreateNetworkOptions#gateway(String) + */ + public static CreateNetworkOptions gateway(String gateway) { + CreateNetworkOptions options = new CreateNetworkOptions(); + return options.gateway(gateway); + } + + /** + * @see CreateNetworkOptions#netmask(String) + */ + public static CreateNetworkOptions netmask(String netmask) { + CreateNetworkOptions options = new CreateNetworkOptions(); + return options.netmask(netmask); + } + + /** + * @see CreateNetworkOptions#networkDomain(String) + */ + public static CreateNetworkOptions networkDomain(String networkDomain) { + CreateNetworkOptions options = new CreateNetworkOptions(); + return options.networkDomain(networkDomain); + } + + /** + * @see CreateNetworkOptions#vlan(String) + */ + public static CreateNetworkOptions vlan(String vlan) { + CreateNetworkOptions options = new CreateNetworkOptions(); + return options.vlan(vlan); + } + + /** + * @see CreateNetworkOptions#accountInDomain + */ + public static CreateNetworkOptions accountInDomain(String account, long domain) { + CreateNetworkOptions options = new CreateNetworkOptions(); + return options.accountInDomain(account, domain); + } + + /** + * @see CreateNetworkOptions#domainId + */ + public static CreateNetworkOptions domainId(long domainId) { + CreateNetworkOptions options = new CreateNetworkOptions(); + return options.domainId(domainId); + } + } + + /** + * {@inheritDoc} + */ + @Override + public CreateNetworkOptions accountInDomain(String account, long domain) { + return CreateNetworkOptions.class.cast(super.accountInDomain(account, domain)); + } + + /** + * {@inheritDoc} + */ + @Override + public CreateNetworkOptions domainId(long domainId) { + return CreateNetworkOptions.class.cast(super.domainId(domainId)); + } +} diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/predicates/ZonePredicates.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/predicates/ZonePredicates.java new file mode 100644 index 0000000000..5638c5e4d5 --- /dev/null +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/predicates/ZonePredicates.java @@ -0,0 +1,71 @@ +/** + * + * Copyright (C) 2011 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed 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.predicates; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.jclouds.cloudstack.domain.NetworkType; +import org.jclouds.cloudstack.domain.Zone; + +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; + +/** + * + * @author Adrian Cole + */ +public class ZonePredicates { + + public static class SupportsNetworkType implements Predicate { + private final org.jclouds.cloudstack.domain.NetworkType type; + + public SupportsNetworkType(org.jclouds.cloudstack.domain.NetworkType type) { + this.type = checkNotNull(type, "type"); + } + + @Override + public boolean apply(Zone input) { + return type.equals(checkNotNull(input, "zone").getNetworkType()); + } + + @Override + public String toString() { + return "supportsNetworkType(" + type + ")"; + } + } + + static Predicate supportsAdvancedNetworks = new SupportsNetworkType( + org.jclouds.cloudstack.domain.NetworkType.ADVANCED); + + /** + * + * @return true, if the zone supports {@link NetworkType.ADVANCED} + */ + public static Predicate supportsAdvancedNetworks() { + return supportsAdvancedNetworks; + } + + /** + * + * @return always returns true. + */ + public static Predicate any() { + return Predicates.alwaysTrue(); + } +} diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AddressAsyncClientTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AddressAsyncClientTest.java index 4129a18482..88e90f03f1 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AddressAsyncClientTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AddressAsyncClientTest.java @@ -100,8 +100,8 @@ public class AddressAsyncClientTest extends BaseCloudStackAsyncClientTest getAsyncJob(job.getJobId()).getResult(); diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NetworkAsyncClientTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NetworkAsyncClientTest.java index 4f312b094e..ab19d66c40 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NetworkAsyncClientTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NetworkAsyncClientTest.java @@ -22,12 +22,17 @@ import java.io.IOException; import java.lang.reflect.Method; import org.jclouds.cloudstack.domain.NetworkType; +import org.jclouds.cloudstack.options.CreateNetworkOptions; import org.jclouds.cloudstack.options.ListNetworksOptions; import org.jclouds.http.HttpRequest; +import org.jclouds.http.functions.ReleasePayloadAndReturn; +import org.jclouds.http.functions.UnwrapOnlyJsonValue; import org.jclouds.http.functions.UnwrapOnlyNestedJsonValue; import org.jclouds.http.functions.UnwrapOnlyNestedJsonValueInSet; +import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; 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; @@ -46,7 +51,7 @@ public class NetworkAsyncClientTest extends BaseCloudStackAsyncClientTest> createTypeLiteral() { return new TypeLiteral>() { diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NetworkClientLiveTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NetworkClientLiveTest.java index 02294df405..ad183cca5f 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NetworkClientLiveTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NetworkClientLiveTest.java @@ -18,16 +18,25 @@ */ package org.jclouds.cloudstack.features; +import static com.google.common.collect.Iterables.find; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; +import java.util.NoSuchElementException; import java.util.Set; +import org.jclouds.cloudstack.domain.AsyncCreateResponse; import org.jclouds.cloudstack.domain.GuestIPType; import org.jclouds.cloudstack.domain.Network; +import org.jclouds.cloudstack.domain.NetworkOffering; +import org.jclouds.cloudstack.domain.Zone; import org.jclouds.cloudstack.options.ListNetworksOptions; +import org.jclouds.cloudstack.predicates.ZonePredicates; +import org.testng.annotations.AfterGroups; +import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; +import com.google.common.base.Predicate; import com.google.common.collect.Iterables; /** @@ -38,36 +47,88 @@ import com.google.common.collect.Iterables; @Test(groups = "live", singleThreaded = true, testName = "NetworkClientLiveTest") public class NetworkClientLiveTest extends BaseCloudStackClientLiveTest { + private boolean networksSupported; + + private Zone zone; + private NetworkOffering offering; + + private Network network; + + @BeforeGroups(groups = "live") + public void setupClient() { + super.setupClient(); + + try { + zone = find(client.getZoneClient().listZones(), ZonePredicates.supportsAdvancedNetworks()); + offering = Iterables.find(client.getOfferingClient().listNetworkOfferings(),new Predicate(){ + + @Override + public boolean apply(NetworkOffering arg0) { + return "Optional".equals(arg0.getAvailability()); + } + + }); + networksSupported = true; + } catch (NoSuchElementException e) { + } + } + + public void testCreateNetworks() throws Exception { + if (!networksSupported) + return; + AsyncCreateResponse job = client.getNetworkClient().createNetworkInZone(zone.getId(), offering.getId(), prefix, + prefix); + assert jobComplete.apply(job.getJobId()) : job; + network = client.getNetworkClient().getNetwork(job.getId()); + checkNetwork(network); + } + + @AfterGroups(groups = "live") + protected void tearDown() { + if (network != null) { + client.getNetworkClient().deleteNetwork(network.getId()); + } + super.tearDown(); + } + public void testListNetworks() throws Exception { + if (!networksSupported) + return; Set response = client.getNetworkClient().listNetworks(); assert null != response; long networkCount = response.size(); assertTrue(networkCount >= 0); for (Network network : response) { Network newDetails = Iterables.getOnlyElement(client.getNetworkClient().listNetworks( - ListNetworksOptions.Builder.id(network.getId()))); + ListNetworksOptions.Builder.id(network.getId()))); assertEquals(network, newDetails); assertEquals(network, client.getNetworkClient().getNetwork(network.getId())); - assert network.getId() > 0 : network; - assert network.getName() != null : network; - assert network.getDNS().size() != 0 : network; - assert network.getGuestIPType() != null && network.getGuestIPType() != GuestIPType.UNRECOGNIZED : network; - assert network.getAccount() != null : network; - assert network.getBroadcastDomainType() != null : network; - assert network.getDisplayText() != null : network; - assert network.getNetworkDomain() != null : network; - assert network.getNetworkOfferingAvailability() != null : network; - assert network.getNetworkOfferingDisplayText() != null : network; - assert network.getNetworkOfferingId() > 0 : network; - assert network.getNetworkOfferingName() != null : network; - assert network.getRelated() > 0 : network; - assert network.getServices().size() != 0 : network; - assert network.getState() != null : network; - assert network.getTrafficType() != null : network; - assert network.getZoneId() > 0 : network; - assert network.getDomain() != null : network; - assert network.getDomainId() > 0 : network; - switch (network.getGuestIPType()) { + checkNetwork(network); + + } + } + + private void checkNetwork(Network network) { + assert network.getId() > 0 : network; + assert network.getName() != null : network; + assert network.getDNS().size() != 0 : network; + assert network.getGuestIPType() != null && network.getGuestIPType() != GuestIPType.UNRECOGNIZED : network; + assert network.getAccount() != null : network; + assert network.getBroadcastDomainType() != null : network; + assert network.getDisplayText() != null : network; + assert network.getNetworkDomain() != null : network; + assert network.getNetworkOfferingAvailability() != null : network; + assert network.getNetworkOfferingDisplayText() != null : network; + assert network.getNetworkOfferingId() > 0 : network; + assert network.getNetworkOfferingName() != null : network; + assert network.getRelated() > 0 : network; + assert network.getServices().size() != 0 : network; + assert network.getState() != null : network; + assert network.getTrafficType() != null : network; + assert network.getZoneId() > 0 : network; + assert network.getDomain() != null : network; + assert network.getDomainId() > 0 : network; + switch (network.getGuestIPType()) { case VIRTUAL: assert network.getNetmask() == null : network; assert network.getGateway() == null : network; @@ -83,8 +144,6 @@ public class NetworkClientLiveTest extends BaseCloudStackClientLiveTest { assert network.getStartIP() != null : network; assert network.getEndIP() != null : network; break; - } - } } } diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/SecurityGroupClientLiveTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/SecurityGroupClientLiveTest.java index c75571f997..9ff540d7bd 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/SecurityGroupClientLiveTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/SecurityGroupClientLiveTest.java @@ -31,7 +31,6 @@ import org.jclouds.cloudstack.domain.VirtualMachine; import org.jclouds.cloudstack.domain.Zone; import org.jclouds.cloudstack.options.AccountInDomainOptions; import org.jclouds.cloudstack.options.ListSecurityGroupsOptions; -import org.jclouds.cloudstack.options.ListVirtualMachinesOptions; import org.jclouds.net.IPSocket; import org.jclouds.util.Strings2; import org.testng.annotations.AfterGroups; @@ -170,9 +169,6 @@ public class SecurityGroupClientLiveTest extends BaseCloudStackClientLiveTest { public void testCreateVMInSecurityGroup() throws Exception { if (!securityGroupsSupported) return; - for (VirtualMachine vm : client.getVirtualMachineClient().listVirtualMachines( - ListVirtualMachinesOptions.Builder.zoneId(zone.getId()))) { - } vm = VirtualMachineClientLiveTest.createVirtualMachineWithSecurityGroupInZone(zone.getId(), group.getId(), client, jobComplete, virtualMachineRunning); if (vm.getPassword() != null) diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/VirtualMachineAsyncClientTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/VirtualMachineAsyncClientTest.java index 3ae7068003..1263c8a1e9 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/VirtualMachineAsyncClientTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/VirtualMachineAsyncClientTest.java @@ -98,14 +98,14 @@ public class VirtualMachineAsyncClientTest extends BaseCloudStackAsyncClientTest } - public void testDeployVirtualMachine() throws SecurityException, NoSuchMethodException, IOException { - Method method = VirtualMachineAsyncClient.class.getMethod("deployVirtualMachine", long.class, long.class, + public void testDeployVirtualMachineInZone() throws SecurityException, NoSuchMethodException, IOException { + Method method = VirtualMachineAsyncClient.class.getMethod("deployVirtualMachineInZone", long.class, long.class, long.class, DeployVirtualMachineOptions[].class); - HttpRequest httpRequest = processor.createRequest(method, 4, 5, 6); + HttpRequest httpRequest = processor.createRequest(method, 6, 4, 5); assertRequestLineEquals( httpRequest, - "GET http://localhost:8080/client/api?response=json&command=deployVirtualMachine&serviceofferingid=4&zoneid=6&templateid=5 HTTP/1.1"); + "GET http://localhost:8080/client/api?response=json&command=deployVirtualMachine&zoneid=6&templateid=5&serviceofferingid=4 HTTP/1.1"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); assertPayloadEquals(httpRequest, null, null, false); diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/VirtualMachineClientLiveTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/VirtualMachineClientLiveTest.java index 7958071edb..3e571c4cd8 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/VirtualMachineClientLiveTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/VirtualMachineClientLiveTest.java @@ -135,7 +135,7 @@ public class VirtualMachineClientLiveTest extends BaseCloudStackClientLiveTest { System.out.printf("serviceOfferingId %d, templateId %d, zoneId %d, options %s%n", serviceOfferingId, templateId, zoneId, options); - AsyncCreateResponse job = client.getVirtualMachineClient().deployVirtualMachine(serviceOfferingId, templateId, + AsyncCreateResponse job = client.getVirtualMachineClient().deployVirtualMachineInZone(serviceOfferingId, templateId, zoneId, options); assert jobComplete.apply(job.getJobId()); AsyncJob jobWithResult = client.getAsyncJobClient(). getAsyncJob(job.getJobId()); diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/functions/ReuseOrAssociateNewPublicIPAddressTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/functions/ReuseOrAssociateNewPublicIPAddressTest.java index a650a9b9e2..24ec778550 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/functions/ReuseOrAssociateNewPublicIPAddressTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/functions/ReuseOrAssociateNewPublicIPAddressTest.java @@ -92,7 +92,7 @@ public class ReuseOrAssociateNewPublicIPAddressTest { AsyncCreateResponse job = new AsyncCreateResponse(1, 2); // make sure we created the job relating to a new ip - expect(addressClient.associateIPAddress(zoneId, networkId(networkId))).andReturn(job); + expect(addressClient.associateIPAddressInZone(zoneId, networkId(networkId))).andReturn(job); AsyncJobClient jobClient = createMock(AsyncJobClient.class); expect(client.getAsyncJobClient()).andReturn(jobClient).atLeastOnce(); @@ -132,7 +132,7 @@ public class ReuseOrAssociateNewPublicIPAddressTest { AsyncCreateResponse job = new AsyncCreateResponse(1, 2); // make sure we created the job relating to a new ip - expect(addressClient.associateIPAddress(zoneId, networkId(networkId))).andReturn(job); + expect(addressClient.associateIPAddressInZone(zoneId, networkId(networkId))).andReturn(job); // the alwaysfalse predicate above should blow up with IllegalStateException diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/CreateNetworkOptionsTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/CreateNetworkOptionsTest.java new file mode 100644 index 0000000000..6b2adc6cd8 --- /dev/null +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/CreateNetworkOptionsTest.java @@ -0,0 +1,136 @@ +/** + * + * Copyright (C) 2011 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed 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.options; + +import static org.jclouds.cloudstack.options.CreateNetworkOptions.Builder.accountInDomain; +import static org.jclouds.cloudstack.options.CreateNetworkOptions.Builder.endIP; +import static org.jclouds.cloudstack.options.CreateNetworkOptions.Builder.gateway; +import static org.jclouds.cloudstack.options.CreateNetworkOptions.Builder.isDefault; +import static org.jclouds.cloudstack.options.CreateNetworkOptions.Builder.isShared; +import static org.jclouds.cloudstack.options.CreateNetworkOptions.Builder.netmask; +import static org.jclouds.cloudstack.options.CreateNetworkOptions.Builder.networkDomain; +import static org.jclouds.cloudstack.options.CreateNetworkOptions.Builder.startIP; +import static org.jclouds.cloudstack.options.CreateNetworkOptions.Builder.vlan; +import static org.testng.Assert.assertEquals; + +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableList; + +/** + * Tests behavior of {@code CreateNetworkOptions} + * + * @author Adrian Cole + */ +@Test(groups = "unit") +public class CreateNetworkOptionsTest { + + public void testAccountInDomainId() { + CreateNetworkOptions options = new CreateNetworkOptions().accountInDomain("adrian", 6); + assertEquals(ImmutableList.of("adrian"), options.buildQueryParameters().get("account")); + assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("domainid")); + } + + public void testAccountInDomainIdStatic() { + CreateNetworkOptions options = accountInDomain("adrian", 6); + assertEquals(ImmutableList.of("adrian"), options.buildQueryParameters().get("account")); + assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("domainid")); + } + + public void testIsDefault() { + CreateNetworkOptions options = new CreateNetworkOptions().isDefault(true); + assertEquals(ImmutableList.of("true"), options.buildQueryParameters().get("isdefault")); + } + + public void testIsDefaultStatic() { + CreateNetworkOptions options = isDefault(true); + assertEquals(ImmutableList.of("true"), options.buildQueryParameters().get("isdefault")); + } + + public void testIsShared() { + CreateNetworkOptions options = new CreateNetworkOptions().isShared(true); + assertEquals(ImmutableList.of("true"), options.buildQueryParameters().get("isshared")); + } + + public void testIsSharedStatic() { + CreateNetworkOptions options = isShared(true); + assertEquals(ImmutableList.of("true"), options.buildQueryParameters().get("isshared")); + } + + public void testStartIP() { + CreateNetworkOptions options = new CreateNetworkOptions().startIP("1.1.1.1"); + assertEquals(ImmutableList.of("1.1.1.1"), options.buildQueryParameters().get("startip")); + } + + public void testStartIPStatic() { + CreateNetworkOptions options = startIP("1.1.1.1"); + assertEquals(ImmutableList.of("1.1.1.1"), options.buildQueryParameters().get("startip")); + } + + public void testEndIP() { + CreateNetworkOptions options = new CreateNetworkOptions().endIP("1.1.1.1"); + assertEquals(ImmutableList.of("1.1.1.1"), options.buildQueryParameters().get("endip")); + } + + public void testEndIPStatic() { + CreateNetworkOptions options = endIP("1.1.1.1"); + assertEquals(ImmutableList.of("1.1.1.1"), options.buildQueryParameters().get("endip")); + } + + public void testGateway() { + CreateNetworkOptions options = new CreateNetworkOptions().gateway("1.1.1.1"); + assertEquals(ImmutableList.of("1.1.1.1"), options.buildQueryParameters().get("gateway")); + } + + public void testGatewayStatic() { + CreateNetworkOptions options = gateway("1.1.1.1"); + assertEquals(ImmutableList.of("1.1.1.1"), options.buildQueryParameters().get("gateway")); + } + + public void testNetmask() { + CreateNetworkOptions options = new CreateNetworkOptions().netmask("1.1.1.1"); + assertEquals(ImmutableList.of("1.1.1.1"), options.buildQueryParameters().get("netmask")); + } + + public void testNetmaskStatic() { + CreateNetworkOptions options = netmask("1.1.1.1"); + assertEquals(ImmutableList.of("1.1.1.1"), options.buildQueryParameters().get("netmask")); + } + + public void testNetworkDomain() { + CreateNetworkOptions options = new CreateNetworkOptions().networkDomain("network.com"); + assertEquals(ImmutableList.of("network.com"), options.buildQueryParameters().get("networkdomain")); + } + + public void testNetworkDomainStatic() { + CreateNetworkOptions options = networkDomain("network.com"); + assertEquals(ImmutableList.of("network.com"), options.buildQueryParameters().get("networkdomain")); + } + + public void testVlan() { + CreateNetworkOptions options = new CreateNetworkOptions().vlan("tag"); + assertEquals(ImmutableList.of("tag"), options.buildQueryParameters().get("vlan")); + } + + public void testVlanStatic() { + CreateNetworkOptions options = vlan("tag"); + assertEquals(ImmutableList.of("tag"), options.buildQueryParameters().get("vlan")); + } + +} diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/BaseItemParserTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/BaseItemParserTest.java deleted file mode 100644 index 29cd7855b5..0000000000 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/BaseItemParserTest.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * - * Copyright (C) 2011 Cloud Conscious, LLC. - * - * ==================================================================== - * Licensed 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.parse; - - -/** - * - * @author Adrian Cole - */ -public abstract class BaseItemParserTest extends BaseParserTest { - -} diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/BaseParserTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/BaseParserTest.java deleted file mode 100644 index bbcf7c8dff..0000000000 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/BaseParserTest.java +++ /dev/null @@ -1,79 +0,0 @@ -/** - * - * Copyright (C) 2011 Cloud Conscious, LLC. - * - * ==================================================================== - * Licensed 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.parse; - -import static org.testng.Assert.assertEquals; - -import org.jclouds.cloudstack.config.CloudStackParserModule; -import org.jclouds.http.HttpResponse; -import org.jclouds.http.functions.UnwrapOnlyNestedJsonValue; -import org.jclouds.io.Payloads; -import org.jclouds.json.config.GsonModule; -import org.testng.annotations.Test; - -import com.google.common.base.Function; -import com.google.inject.Guice; -import com.google.inject.Injector; -import com.google.inject.Key; -import com.google.inject.TypeLiteral; -import com.google.inject.util.Types; - -/** - * - * @author Adrian Cole - */ -public abstract class BaseParserTest { - - Injector i = Guice.createInjector(new GsonModule() { - - @Override - protected void configure() { - bind(DateAdapter.class).to(Iso8601DateAdapter.class); - super.configure(); - } - - }, new CloudStackParserModule()); - - @Test - public void test() { - - T expects = expected(); - - Function parser = getParser(); - T response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(getClass() - .getResourceAsStream(resource())))); - compare(expects, response); - } - - public void compare(T expects, T response) { - assertEquals(response.toString(), expects.toString()); - } - - @SuppressWarnings("unchecked") - protected Function getParser(){ - return (Function) i.getInstance(Key.get(TypeLiteral.get( - Types.newParameterizedType(UnwrapOnlyNestedJsonValue.class, type())).getType())); - } - - public abstract Class type(); - - public abstract String resource(); - - public abstract T expected(); -} diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/BaseSetParserTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/BaseSetParserTest.java deleted file mode 100644 index af409d635f..0000000000 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/BaseSetParserTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * - * Copyright (C) 2011 Cloud Conscious, LLC. - * - * ==================================================================== - * Licensed 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.parse; - -import static org.testng.Assert.assertEquals; - -import java.util.Set; - -import org.jclouds.http.HttpResponse; -import org.jclouds.http.functions.UnwrapOnlyNestedJsonValue; - -import com.google.common.base.Function; -import com.google.common.collect.ImmutableSortedSet; -import com.google.inject.Key; -import com.google.inject.TypeLiteral; -import com.google.inject.util.Types; - -/** - * - * @author Adrian Cole - */ -public abstract class BaseSetParserTest extends BaseParserTest, T> { - - @SuppressWarnings("unchecked") - // crazy stuff due to type erasure - protected Function> getParser() { - return (Function>) i.getInstance(Key.get(TypeLiteral.get( - Types.newParameterizedType(UnwrapOnlyNestedJsonValue.class, Types.newParameterizedType(Set.class, type()))) - .getType())); - } - - public void compare(Set expects, Set response) { - assertEquals(ImmutableSortedSet.copyOf(response).toString(), ImmutableSortedSet.copyOf(expects).toString()); - } - -} diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListAccountsResponseTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListAccountsResponseTest.java index 2f0ca69186..cf724aaaf6 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListAccountsResponseTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListAccountsResponseTest.java @@ -20,14 +20,19 @@ package org.jclouds.cloudstack.parse; import java.util.Set; +import org.jclouds.cloudstack.config.CloudStackParserModule; import org.jclouds.cloudstack.domain.Account; +import org.jclouds.cloudstack.domain.User; import org.jclouds.cloudstack.domain.Account.State; import org.jclouds.cloudstack.domain.Account.Type; -import org.jclouds.cloudstack.domain.User; import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.json.BaseSetParserTest; +import org.jclouds.json.config.GsonModule; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; +import com.google.inject.Guice; +import com.google.inject.Injector; /** * @@ -35,6 +40,19 @@ import com.google.common.collect.ImmutableSet; */ @Test(groups = "unit") public class ListAccountsResponseTest extends BaseSetParserTest { + @Override + protected Injector getInjector() { + return Guice.createInjector(new CloudStackParserModule(), new GsonModule() { + + @Override + protected void configure() { + bind(DateAdapter.class).to(Iso8601DateAdapter.class); + super.configure(); + } + + }); + + } @Override public Class type() { diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListCapabilitiesResponseTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListCapabilitiesResponseTest.java index b2b7fb3dcf..cadd85ba81 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListCapabilitiesResponseTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListCapabilitiesResponseTest.java @@ -19,6 +19,7 @@ package org.jclouds.cloudstack.parse; import org.jclouds.cloudstack.domain.Capabilities; +import org.jclouds.json.BaseItemParserTest; import org.testng.annotations.Test; /** diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListDiskOfferingsResponseTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListDiskOfferingsResponseTest.java index f62bcc01ab..abc60c8e72 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListDiskOfferingsResponseTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListDiskOfferingsResponseTest.java @@ -22,6 +22,7 @@ import java.util.Set; import org.jclouds.cloudstack.domain.DiskOffering; import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.json.BaseSetParserTest; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListHypervisorsResponseTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListHypervisorsResponseTest.java index 3780f2ebd0..4789abdc8a 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListHypervisorsResponseTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListHypervisorsResponseTest.java @@ -22,10 +22,12 @@ import java.util.Set; import org.jclouds.cloudstack.functions.ParseNamesFromHttpResponse; import org.jclouds.http.HttpResponse; +import org.jclouds.json.BaseSetParserTest; import org.testng.annotations.Test; import com.google.common.base.Function; import com.google.common.collect.ImmutableSet; +import com.google.inject.Injector; /** * @@ -50,7 +52,7 @@ public class ListHypervisorsResponseTest extends BaseSetParserTest { } @Override - protected Function> getParser() { - return i.getInstance(ParseNamesFromHttpResponse.class); + protected Function> getParser(Injector injector) { + return injector.getInstance(ParseNamesFromHttpResponse.class); } } diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListNetworkOfferingsResponseTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListNetworkOfferingsResponseTest.java index 5addaa7126..f4239adfa0 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListNetworkOfferingsResponseTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListNetworkOfferingsResponseTest.java @@ -22,6 +22,7 @@ import java.util.Set; import org.jclouds.cloudstack.domain.NetworkOffering; import org.jclouds.cloudstack.domain.TrafficType; +import org.jclouds.json.BaseSetParserTest; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListNetworksResponseTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListNetworksResponseTest.java index c3b0d70331..590de865c1 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListNetworksResponseTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListNetworksResponseTest.java @@ -25,6 +25,7 @@ import org.jclouds.cloudstack.domain.GuestIPType; import org.jclouds.cloudstack.domain.Network; import org.jclouds.cloudstack.domain.NetworkService; import org.jclouds.cloudstack.domain.TrafficType; +import org.jclouds.json.BaseSetParserTest; import org.testng.annotations.Test; import com.google.common.collect.ImmutableList; diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListOSCategoriesResponseTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListOSCategoriesResponseTest.java index 0795cefcda..8723068115 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListOSCategoriesResponseTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListOSCategoriesResponseTest.java @@ -22,10 +22,12 @@ import java.util.Map; import org.jclouds.cloudstack.functions.ParseIdToNameFromHttpResponse; import org.jclouds.http.HttpResponse; +import org.jclouds.json.BaseItemParserTest; import org.testng.annotations.Test; import com.google.common.base.Function; import com.google.common.collect.ImmutableMap; +import com.google.inject.Injector; /** * @@ -41,17 +43,17 @@ public class ListOSCategoriesResponseTest extends BaseItemParserTest expected() { - return ImmutableMap. builder().put(1l, "CentOS").put(2l, "Debian").put(3l, "Oracle") - .put(4l, "RedHat").put(5l, "SUSE").put(6l, "Windows").put(7l, "Other").put(8l, "Novel").put(9l, "Unix") - .put(10l, "Ubuntu").build(); + return ImmutableMap. builder().put(1l, "CentOS").put(2l, "Debian").put(3l, "Oracle").put(4l, + "RedHat").put(5l, "SUSE").put(6l, "Windows").put(7l, "Other").put(8l, "Novel").put(9l, "Unix").put(10l, + "Ubuntu").build(); } @Override - protected Function> getParser() { - return i.getInstance(ParseIdToNameFromHttpResponse.class); + protected Function> getParser(Injector injector) { + return injector.getInstance(ParseIdToNameFromHttpResponse.class); } - @SuppressWarnings({ "unchecked", "rawtypes" }) + @SuppressWarnings( { "unchecked", "rawtypes" }) @Override public Class> type() { return (Class) Map.class; diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListOSTypesResponseTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListOSTypesResponseTest.java new file mode 100644 index 0000000000..e78735c083 --- /dev/null +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListOSTypesResponseTest.java @@ -0,0 +1,230 @@ +/** + * + * Copyright (C) 2011 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed 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.parse; + +import java.util.Set; +import org.jclouds.cloudstack.domain.OSType; +import org.jclouds.json.BaseSetParserTest; +import org.testng.annotations.Test; +import com.google.common.collect.ImmutableSet; + +/** + * + * @author Adrian Cole + */ +@Test(groups = "unit") +public class ListOSTypesResponseTest extends BaseSetParserTest { + @Override + public Class type() { + return OSType.class; + } + + @Override + public String resource() { + return "/listostypesresponse.json"; + } + + @Override + public Set expected() { + return ImmutableSet. builder().add( + OSType.builder().id(69).OSCategoryId(7).description("Asianux 3(32-bit)").build()).add( + OSType.builder().id(70).OSCategoryId(7).description("Asianux 3(64-bit)").build()).add( + OSType.builder().id(1).OSCategoryId(1).description("CentOS 4.5 (32-bit)").build()).add( + OSType.builder().id(2).OSCategoryId(1).description("CentOS 4.6 (32-bit)").build()).add( + OSType.builder().id(3).OSCategoryId(1).description("CentOS 4.7 (32-bit)").build()).add( + OSType.builder().id(4).OSCategoryId(1).description("CentOS 4.8 (32-bit)").build()).add( + OSType.builder().id(5).OSCategoryId(1).description("CentOS 5.0 (32-bit)").build()).add( + OSType.builder().id(6).OSCategoryId(1).description("CentOS 5.0 (64-bit)").build()).add( + OSType.builder().id(7).OSCategoryId(1).description("CentOS 5.1 (32-bit)").build()).add( + OSType.builder().id(8).OSCategoryId(1).description("CentOS 5.1 (64-bit)").build()).add( + OSType.builder().id(9).OSCategoryId(1).description("CentOS 5.2 (32-bit)").build()).add( + OSType.builder().id(10).OSCategoryId(1).description("CentOS 5.2 (64-bit)").build()).add( + OSType.builder().id(11).OSCategoryId(1).description("CentOS 5.3 (32-bit)").build()).add( + OSType.builder().id(12).OSCategoryId(1).description("CentOS 5.3 (64-bit)").build()).add( + OSType.builder().id(13).OSCategoryId(1).description("CentOS 5.4 (32-bit)").build()).add( + OSType.builder().id(14).OSCategoryId(1).description("CentOS 5.4 (64-bit)").build()).add( + OSType.builder().id(111).OSCategoryId(1).description("CentOS 5.5 (32-bit)").build()).add( + OSType.builder().id(112).OSCategoryId(1).description("CentOS 5.5 (64-bit)").build()).add( + OSType.builder().id(73).OSCategoryId(2).description("Debian GNU/Linux 4(32-bit)").build()).add( + OSType.builder().id(74).OSCategoryId(2).description("Debian GNU/Linux 4(64-bit)").build()).add( + OSType.builder().id(72).OSCategoryId(2).description("Debian GNU/Linux 5(64-bit)").build()).add( + OSType.builder().id(15).OSCategoryId(2).description("Debian GNU/Linux 5.0 (32-bit)").build()).add( + OSType.builder().id(132).OSCategoryId(2).description("Debian GNU/Linux 6(32-bit)").build()).add( + OSType.builder().id(133).OSCategoryId(2).description("Debian GNU/Linux 6(64-bit)").build()).add( + OSType.builder().id(102).OSCategoryId(6).description("DOS").build()).add( + OSType.builder().id(118).OSCategoryId(4).description("Fedora 10").build()).add( + OSType.builder().id(117).OSCategoryId(4).description("Fedora 11").build()).add( + OSType.builder().id(116).OSCategoryId(4).description("Fedora 12").build()).add( + OSType.builder().id(115).OSCategoryId(4).description("Fedora 13").build()).add( + OSType.builder().id(120).OSCategoryId(4).description("Fedora 8").build()).add( + OSType.builder().id(119).OSCategoryId(4).description("Fedora 9").build()).add( + OSType.builder().id(83).OSCategoryId(9).description("FreeBSD (32-bit)").build()).add( + OSType.builder().id(84).OSCategoryId(9).description("FreeBSD (64-bit)").build()).add( + OSType.builder().id(92).OSCategoryId(6).description("Microsoft Small Bussiness Server 2003").build()) + .add(OSType.builder().id(78).OSCategoryId(8).description("Novell Netware 5.1").build()).add( + OSType.builder().id(77).OSCategoryId(8).description("Novell Netware 6.x").build()).add( + OSType.builder().id(68).OSCategoryId(7).description("Open Enterprise Server").build()).add( + OSType.builder().id(16).OSCategoryId(3).description("Oracle Enterprise Linux 5.0 (32-bit)") + .build()).add( + OSType.builder().id(17).OSCategoryId(3).description("Oracle Enterprise Linux 5.0 (64-bit)") + .build()).add( + OSType.builder().id(18).OSCategoryId(3).description("Oracle Enterprise Linux 5.1 (32-bit)") + .build()).add( + OSType.builder().id(19).OSCategoryId(3).description("Oracle Enterprise Linux 5.1 (64-bit)") + .build()).add( + OSType.builder().id(20).OSCategoryId(3).description("Oracle Enterprise Linux 5.2 (32-bit)") + .build()).add( + OSType.builder().id(21).OSCategoryId(3).description("Oracle Enterprise Linux 5.2 (64-bit)") + .build()).add( + OSType.builder().id(22).OSCategoryId(3).description("Oracle Enterprise Linux 5.3 (32-bit)") + .build()).add( + OSType.builder().id(23).OSCategoryId(3).description("Oracle Enterprise Linux 5.3 (64-bit)") + .build()).add( + OSType.builder().id(24).OSCategoryId(3).description("Oracle Enterprise Linux 5.4 (32-bit)") + .build()).add( + OSType.builder().id(25).OSCategoryId(3).description("Oracle Enterprise Linux 5.4 (64-bit)") + .build()).add( + OSType.builder().id(134).OSCategoryId(3).description("Oracle Enterprise Linux 5.5 (32-bit)") + .build()).add( + OSType.builder().id(135).OSCategoryId(3).description("Oracle Enterprise Linux 5.5 (64-bit)") + .build()).add(OSType.builder().id(104).OSCategoryId(7).description("OS/2").build()) + .add(OSType.builder().id(60).OSCategoryId(7).description("Other (32-bit)").build()).add( + OSType.builder().id(103).OSCategoryId(7).description("Other (64-bit)").build()).add( + OSType.builder().id(75).OSCategoryId(7).description("Other 2.6x Linux (32-bit)").build()).add( + OSType.builder().id(76).OSCategoryId(7).description("Other 2.6x Linux (64-bit)").build()).add( + OSType.builder().id(98).OSCategoryId(7).description("Other Linux (32-bit)").build()).add( + OSType.builder().id(99).OSCategoryId(7).description("Other Linux (64-bit)").build()).add( + OSType.builder().id(59).OSCategoryId(10).description("Other Ubuntu (32-bit)").build()).add( + OSType.builder().id(100).OSCategoryId(10).description("Other Ubuntu (64-bit)").build()).add( + OSType.builder().id(131).OSCategoryId(10).description("Red Hat Enterprise Linux 2").build()) + .add(OSType.builder().id(66).OSCategoryId(4).description("Red Hat Enterprise Linux 3(32-bit)").build()) + .add(OSType.builder().id(67).OSCategoryId(4).description("Red Hat Enterprise Linux 3(64-bit)").build()) + .add(OSType.builder().id(106).OSCategoryId(4).description("Red Hat Enterprise Linux 4(64-bit)").build()) + .add( + OSType.builder().id(26).OSCategoryId(4).description("Red Hat Enterprise Linux 4.5 (32-bit)") + .build()).add( + OSType.builder().id(27).OSCategoryId(4).description("Red Hat Enterprise Linux 4.6 (32-bit)") + .build()).add( + OSType.builder().id(28).OSCategoryId(4).description("Red Hat Enterprise Linux 4.7 (32-bit)") + .build()).add( + OSType.builder().id(29).OSCategoryId(4).description("Red Hat Enterprise Linux 4.8 (32-bit)") + .build()).add( + OSType.builder().id(30).OSCategoryId(4).description("Red Hat Enterprise Linux 5.0 (32-bit)") + .build()).add( + OSType.builder().id(31).OSCategoryId(4).description("Red Hat Enterprise Linux 5.0 (64-bit)") + .build()).add( + OSType.builder().id(32).OSCategoryId(4).description("Red Hat Enterprise Linux 5.1 (32-bit)") + .build()).add( + OSType.builder().id(33).OSCategoryId(4).description("Red Hat Enterprise Linux 5.1 (64-bit)") + .build()).add( + OSType.builder().id(34).OSCategoryId(4).description("Red Hat Enterprise Linux 5.2 (32-bit)") + .build()).add( + OSType.builder().id(35).OSCategoryId(4).description("Red Hat Enterprise Linux 5.2 (64-bit)") + .build()).add( + OSType.builder().id(36).OSCategoryId(4).description("Red Hat Enterprise Linux 5.3 (32-bit)") + .build()).add( + OSType.builder().id(37).OSCategoryId(4).description("Red Hat Enterprise Linux 5.3 (64-bit)") + .build()).add( + OSType.builder().id(38).OSCategoryId(4).description("Red Hat Enterprise Linux 5.4 (32-bit)") + .build()).add( + OSType.builder().id(39).OSCategoryId(4).description("Red Hat Enterprise Linux 5.4 (64-bit)") + .build()).add( + OSType.builder().id(113).OSCategoryId(4).description("Red Hat Enterprise Linux 5.5 (32-bit)") + .build()).add( + OSType.builder().id(114).OSCategoryId(4).description("Red Hat Enterprise Linux 5.5 (64-bit)") + .build()).add( + OSType.builder().id(136).OSCategoryId(4).description("Red Hat Enterprise Linux 6.0 (32-bit)") + .build()).add( + OSType.builder().id(137).OSCategoryId(4).description("Red Hat Enterprise Linux 6.0 (64-bit)") + .build()).add( + OSType.builder().id(85).OSCategoryId(9).description("SCO OpenServer 5").build()).add( + OSType.builder().id(86).OSCategoryId(9).description("SCO UnixWare 7").build()).add( + OSType.builder().id(79).OSCategoryId(9).description("Sun Solaris 10(32-bit)").build()).add( + OSType.builder().id(80).OSCategoryId(9).description("Sun Solaris 10(64-bit)").build()).add( + OSType.builder().id(82).OSCategoryId(9).description("Sun Solaris 8(Experimental)").build()) + .add(OSType.builder().id(81).OSCategoryId(9).description("Sun Solaris 9(Experimental)").build()).add( + OSType.builder().id(109).OSCategoryId(5).description("SUSE Linux Enterprise 10(32-bit)") + .build()).add( + OSType.builder().id(110).OSCategoryId(5).description("SUSE Linux Enterprise 10(64-bit)") + .build()).add( + OSType.builder().id(96).OSCategoryId(5).description("SUSE Linux Enterprise 8(32-bit)").build()) + .add(OSType.builder().id(97).OSCategoryId(5).description("SUSE Linux Enterprise 8(64-bit)").build()) + .add(OSType.builder().id(107).OSCategoryId(5).description("SUSE Linux Enterprise 9(32-bit)").build()) + .add(OSType.builder().id(108).OSCategoryId(5).description("SUSE Linux Enterprise 9(64-bit)").build()) + .add( + OSType.builder().id(41).OSCategoryId(5).description( + "SUSE Linux Enterprise Server 10 SP1 (32-bit)").build()).add( + OSType.builder().id(42).OSCategoryId(5).description( + "SUSE Linux Enterprise Server 10 SP1 (64-bit)").build()).add( + OSType.builder().id(43).OSCategoryId(5).description( + "SUSE Linux Enterprise Server 10 SP2 (32-bit)").build()).add( + OSType.builder().id(44).OSCategoryId(5).description( + "SUSE Linux Enterprise Server 10 SP2 (64-bit)").build()).add( + OSType.builder().id(45).OSCategoryId(5).description( + "SUSE Linux Enterprise Server 10 SP3 (64-bit)").build()).add( + OSType.builder().id(46).OSCategoryId(5).description("SUSE Linux Enterprise Server 11 (32-bit)") + .build()).add( + OSType.builder().id(47).OSCategoryId(5).description("SUSE Linux Enterprise Server 11 (64-bit)") + .build()).add( + OSType.builder().id(40).OSCategoryId(5).description( + "SUSE Linux Enterprise Server 9 SP4 (32-bit)").build()).add( + OSType.builder().id(121).OSCategoryId(10).description("Ubuntu 10.04 (32-bit)").build()).add( + OSType.builder().id(126).OSCategoryId(10).description("Ubuntu 10.04 (64-bit)").build()).add( + OSType.builder().id(125).OSCategoryId(10).description("Ubuntu 8.04 (32-bit)").build()).add( + OSType.builder().id(130).OSCategoryId(10).description("Ubuntu 8.04 (64-bit)").build()).add( + OSType.builder().id(124).OSCategoryId(10).description("Ubuntu 8.10 (32-bit)").build()).add( + OSType.builder().id(129).OSCategoryId(10).description("Ubuntu 8.10 (64-bit)").build()).add( + OSType.builder().id(123).OSCategoryId(10).description("Ubuntu 9.04 (32-bit)").build()).add( + OSType.builder().id(128).OSCategoryId(10).description("Ubuntu 9.04 (64-bit)").build()).add( + OSType.builder().id(122).OSCategoryId(10).description("Ubuntu 9.10 (32-bit)").build()).add( + OSType.builder().id(127).OSCategoryId(10).description("Ubuntu 9.10 (64-bit)").build()).add( + OSType.builder().id(95).OSCategoryId(6).description("Windows 2000 Advanced Server").build()) + .add(OSType.builder().id(105).OSCategoryId(6).description("Windows 2000 Professional").build()).add( + OSType.builder().id(61).OSCategoryId(6).description("Windows 2000 Server").build()) + .add(OSType.builder().id(55).OSCategoryId(6).description("Windows 2000 Server SP4 (32-bit)").build()) + .add(OSType.builder().id(65).OSCategoryId(6).description("Windows 3.1").build()).add( + OSType.builder().id(48).OSCategoryId(6).description("Windows 7 (32-bit)").build()).add( + OSType.builder().id(49).OSCategoryId(6).description("Windows 7 (64-bit)").build()).add( + OSType.builder().id(63).OSCategoryId(6).description("Windows 95").build()).add( + OSType.builder().id(62).OSCategoryId(6).description("Windows 98").build()).add( + OSType.builder().id(64).OSCategoryId(6).description("Windows NT 4").build()).add( + OSType.builder().id(87).OSCategoryId(6).description( + "Windows Server 2003 DataCenter Edition(32-bit)").build()).add( + OSType.builder().id(88).OSCategoryId(6).description( + "Windows Server 2003 DataCenter Edition(64-bit)").build()).add( + OSType.builder().id(50).OSCategoryId(6).description( + "Windows Server 2003 Enterprise Edition(32-bit)").build()).add( + OSType.builder().id(51).OSCategoryId(6).description( + "Windows Server 2003 Enterprise Edition(64-bit)").build()).add( + OSType.builder().id(89).OSCategoryId(6).description( + "Windows Server 2003 Standard Edition(32-bit)").build()).add( + OSType.builder().id(90).OSCategoryId(6).description( + "Windows Server 2003 Standard Edition(64-bit)").build()).add( + OSType.builder().id(91).OSCategoryId(6).description("Windows Server 2003 Web Edition").build()) + .add(OSType.builder().id(52).OSCategoryId(6).description("Windows Server 2008 (32-bit)").build()).add( + OSType.builder().id(53).OSCategoryId(6).description("Windows Server 2008 (64-bit)").build()) + .add(OSType.builder().id(54).OSCategoryId(6).description("Windows Server 2008 R2 (64-bit)").build()) + .add(OSType.builder().id(56).OSCategoryId(6).description("Windows Vista (32-bit)").build()).add( + OSType.builder().id(101).OSCategoryId(6).description("Windows Vista (64-bit)").build()).add( + OSType.builder().id(93).OSCategoryId(6).description("Windows XP (32-bit)").build()).add( + OSType.builder().id(94).OSCategoryId(6).description("Windows XP (64-bit)").build()).add( + OSType.builder().id(57).OSCategoryId(6).description("Windows XP SP2 (32-bit)").build()).add( + OSType.builder().id(58).OSCategoryId(6).description("Windows XP SP3 (32-bit)").build()).build(); + } +} \ No newline at end of file diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListPortForwardingRulesResponseTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListPortForwardingRulesResponseTest.java index b5c6b1b6c1..114213b148 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListPortForwardingRulesResponseTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListPortForwardingRulesResponseTest.java @@ -21,6 +21,7 @@ package org.jclouds.cloudstack.parse; import java.util.Set; import org.jclouds.cloudstack.domain.PortForwardingRule; +import org.jclouds.json.BaseSetParserTest; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListPublicIPAddressesResponseTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListPublicIPAddressesResponseTest.java index bdf348bb5f..298fa7efe1 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListPublicIPAddressesResponseTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListPublicIPAddressesResponseTest.java @@ -22,6 +22,7 @@ import java.util.Set; import org.jclouds.cloudstack.domain.PublicIPAddress; import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.json.BaseSetParserTest; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListSecurityGroupsResponseTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListSecurityGroupsResponseTest.java index 0420272b98..3959c2f721 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListSecurityGroupsResponseTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListSecurityGroupsResponseTest.java @@ -22,6 +22,7 @@ import java.util.Set; import org.jclouds.cloudstack.domain.IngressRule; import org.jclouds.cloudstack.domain.SecurityGroup; +import org.jclouds.json.BaseSetParserTest; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListServiceOfferingsResponseTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListServiceOfferingsResponseTest.java index a6bdd3058d..591d2028e9 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListServiceOfferingsResponseTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListServiceOfferingsResponseTest.java @@ -23,6 +23,7 @@ import java.util.Set; import org.jclouds.cloudstack.domain.ServiceOffering; import org.jclouds.cloudstack.domain.StorageType; import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.json.BaseSetParserTest; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListTemplatesResponseTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListTemplatesResponseTest.java index 1bc625613f..3811c8eb45 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListTemplatesResponseTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListTemplatesResponseTest.java @@ -24,6 +24,7 @@ import org.jclouds.cloudstack.domain.Template; import org.jclouds.cloudstack.domain.Template.Format; import org.jclouds.cloudstack.domain.Template.Type; import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.json.BaseSetParserTest; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListVirtualMachinesResponseTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListVirtualMachinesResponseTest.java index 8e4b84cef4..5b28a6dc98 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListVirtualMachinesResponseTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListVirtualMachinesResponseTest.java @@ -25,6 +25,7 @@ import org.jclouds.cloudstack.domain.NIC; import org.jclouds.cloudstack.domain.TrafficType; import org.jclouds.cloudstack.domain.VirtualMachine; import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.json.BaseSetParserTest; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListZonesResponseTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListZonesResponseTest.java index 185c981c85..f5add7092d 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListZonesResponseTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListZonesResponseTest.java @@ -22,6 +22,7 @@ import java.util.Set; import org.jclouds.cloudstack.domain.NetworkType; import org.jclouds.cloudstack.domain.Zone; +import org.jclouds.json.BaseSetParserTest; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; diff --git a/sandbox-apis/cloudstack/src/test/resources/listostypesresponse.json b/sandbox-apis/cloudstack/src/test/resources/listostypesresponse.json new file mode 100644 index 0000000000..c892e39359 --- /dev/null +++ b/sandbox-apis/cloudstack/src/test/resources/listostypesresponse.json @@ -0,0 +1 @@ +{ "listostypesresponse" : { "ostype" : [ {"id":69,"oscategoryid":7,"description":"Asianux 3(32-bit)"}, {"id":70,"oscategoryid":7,"description":"Asianux 3(64-bit)"}, {"id":1,"oscategoryid":1,"description":"CentOS 4.5 (32-bit)"}, {"id":2,"oscategoryid":1,"description":"CentOS 4.6 (32-bit)"}, {"id":3,"oscategoryid":1,"description":"CentOS 4.7 (32-bit)"}, {"id":4,"oscategoryid":1,"description":"CentOS 4.8 (32-bit)"}, {"id":5,"oscategoryid":1,"description":"CentOS 5.0 (32-bit)"}, {"id":6,"oscategoryid":1,"description":"CentOS 5.0 (64-bit)"}, {"id":7,"oscategoryid":1,"description":"CentOS 5.1 (32-bit)"}, {"id":8,"oscategoryid":1,"description":"CentOS 5.1 (64-bit)"}, {"id":9,"oscategoryid":1,"description":"CentOS 5.2 (32-bit)"}, {"id":10,"oscategoryid":1,"description":"CentOS 5.2 (64-bit)"}, {"id":11,"oscategoryid":1,"description":"CentOS 5.3 (32-bit)"}, {"id":12,"oscategoryid":1,"description":"CentOS 5.3 (64-bit)"}, {"id":13,"oscategoryid":1,"description":"CentOS 5.4 (32-bit)"}, {"id":14,"oscategoryid":1,"description":"CentOS 5.4 (64-bit)"}, {"id":111,"oscategoryid":1,"description":"CentOS 5.5 (32-bit)"}, {"id":112,"oscategoryid":1,"description":"CentOS 5.5 (64-bit)"}, {"id":73,"oscategoryid":2,"description":"Debian GNU/Linux 4(32-bit)"}, {"id":74,"oscategoryid":2,"description":"Debian GNU/Linux 4(64-bit)"}, {"id":72,"oscategoryid":2,"description":"Debian GNU/Linux 5(64-bit)"}, {"id":15,"oscategoryid":2,"description":"Debian GNU/Linux 5.0 (32-bit)"}, {"id":132,"oscategoryid":2,"description":"Debian GNU/Linux 6(32-bit)"}, {"id":133,"oscategoryid":2,"description":"Debian GNU/Linux 6(64-bit)"}, {"id":102,"oscategoryid":6,"description":"DOS"}, {"id":118,"oscategoryid":4,"description":"Fedora 10"}, {"id":117,"oscategoryid":4,"description":"Fedora 11"}, {"id":116,"oscategoryid":4,"description":"Fedora 12"}, {"id":115,"oscategoryid":4,"description":"Fedora 13"}, {"id":120,"oscategoryid":4,"description":"Fedora 8"}, {"id":119,"oscategoryid":4,"description":"Fedora 9"}, {"id":83,"oscategoryid":9,"description":"FreeBSD (32-bit)"}, {"id":84,"oscategoryid":9,"description":"FreeBSD (64-bit)"}, {"id":92,"oscategoryid":6,"description":"Microsoft Small Bussiness Server 2003"}, {"id":78,"oscategoryid":8,"description":"Novell Netware 5.1"}, {"id":77,"oscategoryid":8,"description":"Novell Netware 6.x"}, {"id":68,"oscategoryid":7,"description":"Open Enterprise Server"}, {"id":16,"oscategoryid":3,"description":"Oracle Enterprise Linux 5.0 (32-bit)"}, {"id":17,"oscategoryid":3,"description":"Oracle Enterprise Linux 5.0 (64-bit)"}, {"id":18,"oscategoryid":3,"description":"Oracle Enterprise Linux 5.1 (32-bit)"}, {"id":19,"oscategoryid":3,"description":"Oracle Enterprise Linux 5.1 (64-bit)"}, {"id":20,"oscategoryid":3,"description":"Oracle Enterprise Linux 5.2 (32-bit)"}, {"id":21,"oscategoryid":3,"description":"Oracle Enterprise Linux 5.2 (64-bit)"}, {"id":22,"oscategoryid":3,"description":"Oracle Enterprise Linux 5.3 (32-bit)"}, {"id":23,"oscategoryid":3,"description":"Oracle Enterprise Linux 5.3 (64-bit)"}, {"id":24,"oscategoryid":3,"description":"Oracle Enterprise Linux 5.4 (32-bit)"}, {"id":25,"oscategoryid":3,"description":"Oracle Enterprise Linux 5.4 (64-bit)"}, {"id":134,"oscategoryid":3,"description":"Oracle Enterprise Linux 5.5 (32-bit)"}, {"id":135,"oscategoryid":3,"description":"Oracle Enterprise Linux 5.5 (64-bit)"}, {"id":104,"oscategoryid":7,"description":"OS/2"}, {"id":60,"oscategoryid":7,"description":"Other (32-bit)"}, {"id":103,"oscategoryid":7,"description":"Other (64-bit)"}, {"id":75,"oscategoryid":7,"description":"Other 2.6x Linux (32-bit)"}, {"id":76,"oscategoryid":7,"description":"Other 2.6x Linux (64-bit)"}, {"id":98,"oscategoryid":7,"description":"Other Linux (32-bit)"}, {"id":99,"oscategoryid":7,"description":"Other Linux (64-bit)"}, {"id":59,"oscategoryid":10,"description":"Other Ubuntu (32-bit)"}, {"id":100,"oscategoryid":10,"description":"Other Ubuntu (64-bit)"}, {"id":131,"oscategoryid":10,"description":"Red Hat Enterprise Linux 2"}, {"id":66,"oscategoryid":4,"description":"Red Hat Enterprise Linux 3(32-bit)"}, {"id":67,"oscategoryid":4,"description":"Red Hat Enterprise Linux 3(64-bit)"}, {"id":106,"oscategoryid":4,"description":"Red Hat Enterprise Linux 4(64-bit)"}, {"id":26,"oscategoryid":4,"description":"Red Hat Enterprise Linux 4.5 (32-bit)"}, {"id":27,"oscategoryid":4,"description":"Red Hat Enterprise Linux 4.6 (32-bit)"}, {"id":28,"oscategoryid":4,"description":"Red Hat Enterprise Linux 4.7 (32-bit)"}, {"id":29,"oscategoryid":4,"description":"Red Hat Enterprise Linux 4.8 (32-bit)"}, {"id":30,"oscategoryid":4,"description":"Red Hat Enterprise Linux 5.0 (32-bit)"}, {"id":31,"oscategoryid":4,"description":"Red Hat Enterprise Linux 5.0 (64-bit)"}, {"id":32,"oscategoryid":4,"description":"Red Hat Enterprise Linux 5.1 (32-bit)"}, {"id":33,"oscategoryid":4,"description":"Red Hat Enterprise Linux 5.1 (64-bit)"}, {"id":34,"oscategoryid":4,"description":"Red Hat Enterprise Linux 5.2 (32-bit)"}, {"id":35,"oscategoryid":4,"description":"Red Hat Enterprise Linux 5.2 (64-bit)"}, {"id":36,"oscategoryid":4,"description":"Red Hat Enterprise Linux 5.3 (32-bit)"}, {"id":37,"oscategoryid":4,"description":"Red Hat Enterprise Linux 5.3 (64-bit)"}, {"id":38,"oscategoryid":4,"description":"Red Hat Enterprise Linux 5.4 (32-bit)"}, {"id":39,"oscategoryid":4,"description":"Red Hat Enterprise Linux 5.4 (64-bit)"}, {"id":113,"oscategoryid":4,"description":"Red Hat Enterprise Linux 5.5 (32-bit)"}, {"id":114,"oscategoryid":4,"description":"Red Hat Enterprise Linux 5.5 (64-bit)"}, {"id":136,"oscategoryid":4,"description":"Red Hat Enterprise Linux 6.0 (32-bit)"}, {"id":137,"oscategoryid":4,"description":"Red Hat Enterprise Linux 6.0 (64-bit)"}, {"id":85,"oscategoryid":9,"description":"SCO OpenServer 5"}, {"id":86,"oscategoryid":9,"description":"SCO UnixWare 7"}, {"id":79,"oscategoryid":9,"description":"Sun Solaris 10(32-bit)"}, {"id":80,"oscategoryid":9,"description":"Sun Solaris 10(64-bit)"}, {"id":82,"oscategoryid":9,"description":"Sun Solaris 8(Experimental)"}, {"id":81,"oscategoryid":9,"description":"Sun Solaris 9(Experimental)"}, {"id":109,"oscategoryid":5,"description":"SUSE Linux Enterprise 10(32-bit)"}, {"id":110,"oscategoryid":5,"description":"SUSE Linux Enterprise 10(64-bit)"}, {"id":96,"oscategoryid":5,"description":"SUSE Linux Enterprise 8(32-bit)"}, {"id":97,"oscategoryid":5,"description":"SUSE Linux Enterprise 8(64-bit)"}, {"id":107,"oscategoryid":5,"description":"SUSE Linux Enterprise 9(32-bit)"}, {"id":108,"oscategoryid":5,"description":"SUSE Linux Enterprise 9(64-bit)"}, {"id":41,"oscategoryid":5,"description":"SUSE Linux Enterprise Server 10 SP1 (32-bit)"}, {"id":42,"oscategoryid":5,"description":"SUSE Linux Enterprise Server 10 SP1 (64-bit)"}, {"id":43,"oscategoryid":5,"description":"SUSE Linux Enterprise Server 10 SP2 (32-bit)"}, {"id":44,"oscategoryid":5,"description":"SUSE Linux Enterprise Server 10 SP2 (64-bit)"}, {"id":45,"oscategoryid":5,"description":"SUSE Linux Enterprise Server 10 SP3 (64-bit)"}, {"id":46,"oscategoryid":5,"description":"SUSE Linux Enterprise Server 11 (32-bit)"}, {"id":47,"oscategoryid":5,"description":"SUSE Linux Enterprise Server 11 (64-bit)"}, {"id":40,"oscategoryid":5,"description":"SUSE Linux Enterprise Server 9 SP4 (32-bit)"}, {"id":121,"oscategoryid":10,"description":"Ubuntu 10.04 (32-bit)"}, {"id":126,"oscategoryid":10,"description":"Ubuntu 10.04 (64-bit)"}, {"id":125,"oscategoryid":10,"description":"Ubuntu 8.04 (32-bit)"}, {"id":130,"oscategoryid":10,"description":"Ubuntu 8.04 (64-bit)"}, {"id":124,"oscategoryid":10,"description":"Ubuntu 8.10 (32-bit)"}, {"id":129,"oscategoryid":10,"description":"Ubuntu 8.10 (64-bit)"}, {"id":123,"oscategoryid":10,"description":"Ubuntu 9.04 (32-bit)"}, {"id":128,"oscategoryid":10,"description":"Ubuntu 9.04 (64-bit)"}, {"id":122,"oscategoryid":10,"description":"Ubuntu 9.10 (32-bit)"}, {"id":127,"oscategoryid":10,"description":"Ubuntu 9.10 (64-bit)"}, {"id":95,"oscategoryid":6,"description":"Windows 2000 Advanced Server"}, {"id":105,"oscategoryid":6,"description":"Windows 2000 Professional"}, {"id":61,"oscategoryid":6,"description":"Windows 2000 Server"}, {"id":55,"oscategoryid":6,"description":"Windows 2000 Server SP4 (32-bit)"}, {"id":65,"oscategoryid":6,"description":"Windows 3.1"}, {"id":48,"oscategoryid":6,"description":"Windows 7 (32-bit)"}, {"id":49,"oscategoryid":6,"description":"Windows 7 (64-bit)"}, {"id":63,"oscategoryid":6,"description":"Windows 95"}, {"id":62,"oscategoryid":6,"description":"Windows 98"}, {"id":64,"oscategoryid":6,"description":"Windows NT 4"}, {"id":87,"oscategoryid":6,"description":"Windows Server 2003 DataCenter Edition(32-bit)"}, {"id":88,"oscategoryid":6,"description":"Windows Server 2003 DataCenter Edition(64-bit)"}, {"id":50,"oscategoryid":6,"description":"Windows Server 2003 Enterprise Edition(32-bit)"}, {"id":51,"oscategoryid":6,"description":"Windows Server 2003 Enterprise Edition(64-bit)"}, {"id":89,"oscategoryid":6,"description":"Windows Server 2003 Standard Edition(32-bit)"}, {"id":90,"oscategoryid":6,"description":"Windows Server 2003 Standard Edition(64-bit)"}, {"id":91,"oscategoryid":6,"description":"Windows Server 2003 Web Edition"}, {"id":52,"oscategoryid":6,"description":"Windows Server 2008 (32-bit)"}, {"id":53,"oscategoryid":6,"description":"Windows Server 2008 (64-bit)"}, {"id":54,"oscategoryid":6,"description":"Windows Server 2008 R2 (64-bit)"}, {"id":56,"oscategoryid":6,"description":"Windows Vista (32-bit)"}, {"id":101,"oscategoryid":6,"description":"Windows Vista (64-bit)"}, {"id":93,"oscategoryid":6,"description":"Windows XP (32-bit)"}, {"id":94,"oscategoryid":6,"description":"Windows XP (64-bit)"}, {"id":57,"oscategoryid":6,"description":"Windows XP SP2 (32-bit)"}, {"id":58,"oscategoryid":6,"description":"Windows XP SP3 (32-bit)"} ] } } \ No newline at end of file From 67d5d8f1e73af95ac923d319f0531c0a2e6d6054 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Mon, 9 May 2011 22:17:03 -0700 Subject: [PATCH 03/38] corrected syntax for network commands in cloudstack --- .../features/NetworkAsyncClient.java | 16 +++---- .../cloudstack/features/NetworkClient.java | 12 ++--- .../features/NetworkAsyncClientTest.java | 13 +++--- .../features/NetworkClientLiveTest.java | 44 +++++++++---------- 4 files changed, 39 insertions(+), 46 deletions(-) diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/NetworkAsyncClient.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/NetworkAsyncClient.java index 02222189ad..763f3c19ee 100644 --- a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/NetworkAsyncClient.java +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/NetworkAsyncClient.java @@ -25,7 +25,6 @@ import javax.ws.rs.GET; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; -import org.jclouds.cloudstack.domain.AsyncCreateResponse; import org.jclouds.cloudstack.domain.Network; import org.jclouds.cloudstack.filters.QuerySigner; import org.jclouds.cloudstack.options.CreateNetworkOptions; @@ -36,7 +35,6 @@ import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.Unwrap; import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; -import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; import com.google.common.util.concurrent.ListenableFuture; @@ -77,17 +75,19 @@ public interface NetworkAsyncClient { */ @GET @QueryParams(keys = "command", values = "createNetwork") - @Unwrap + @Unwrap(depth = 2) @Consumes(MediaType.APPLICATION_JSON) - ListenableFuture createNetworkInZone(@QueryParam("zoneid") long zoneId, - @QueryParam("networkofferingid") long networkOfferingId, @QueryParam("name") String name, - @QueryParam("displaytext") String displayText, CreateNetworkOptions... options); + ListenableFuture createNetworkInZone(@QueryParam("zoneid") long zoneId, + @QueryParam("networkofferingid") long networkOfferingId, @QueryParam("name") String name, + @QueryParam("displaytext") String displayText, CreateNetworkOptions... options); /** * @see NetworkClient#deleteNetwork */ @GET @QueryParams(keys = "command", values = "deleteNetwork") - @ExceptionParser(ReturnVoidOnNotFoundOr404.class) - ListenableFuture deleteNetwork(@QueryParam("id") long id); + @Unwrap(depth = 2) + @Consumes(MediaType.APPLICATION_JSON) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture deleteNetwork(@QueryParam("id") long id); } diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/NetworkClient.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/NetworkClient.java index e766362f7e..1be3093d77 100644 --- a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/NetworkClient.java +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/NetworkClient.java @@ -21,7 +21,6 @@ package org.jclouds.cloudstack.features; import java.util.Set; import java.util.concurrent.TimeUnit; -import org.jclouds.cloudstack.domain.AsyncCreateResponse; import org.jclouds.cloudstack.domain.Network; import org.jclouds.cloudstack.options.CreateNetworkOptions; import org.jclouds.cloudstack.options.ListNetworksOptions; @@ -68,17 +67,18 @@ public interface NetworkClient { * the display text of the network * @param options * optional parameters - * @return task in progress + * @return newly created network */ - AsyncCreateResponse createNetworkInZone(long zoneId, long networkOfferingId, String name, String displayText, - CreateNetworkOptions... options); - + Network createNetworkInZone(long zoneId, long networkOfferingId, String name, String displayText, + CreateNetworkOptions... options); /** * Deletes a network * * @param id * the ID of the network + * @return job id related to destroying the network, or null if resource was not + * found */ - void deleteNetwork(long id); + Long deleteNetwork(long id); } diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NetworkAsyncClientTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NetworkAsyncClientTest.java index ab19d66c40..ad19cbb479 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NetworkAsyncClientTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NetworkAsyncClientTest.java @@ -25,14 +25,11 @@ import org.jclouds.cloudstack.domain.NetworkType; import org.jclouds.cloudstack.options.CreateNetworkOptions; import org.jclouds.cloudstack.options.ListNetworksOptions; import org.jclouds.http.HttpRequest; -import org.jclouds.http.functions.ReleasePayloadAndReturn; -import org.jclouds.http.functions.UnwrapOnlyJsonValue; import org.jclouds.http.functions.UnwrapOnlyNestedJsonValue; import org.jclouds.http.functions.UnwrapOnlyNestedJsonValueInSet; import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; 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; @@ -108,7 +105,7 @@ public class NetworkAsyncClientTest extends BaseCloudStackAsyncClientTest(){ + offering = Iterables.find(client.getOfferingClient().listNetworkOfferings(), new Predicate() { @Override public boolean apply(NetworkOffering arg0) { return "Optional".equals(arg0.getAvailability()); } - + }); networksSupported = true; } catch (NoSuchElementException e) { @@ -76,17 +75,14 @@ public class NetworkClientLiveTest extends BaseCloudStackClientLiveTest { public void testCreateNetworks() throws Exception { if (!networksSupported) return; - AsyncCreateResponse job = client.getNetworkClient().createNetworkInZone(zone.getId(), offering.getId(), prefix, - prefix); - assert jobComplete.apply(job.getJobId()) : job; - network = client.getNetworkClient().getNetwork(job.getId()); + network = client.getNetworkClient().createNetworkInZone(zone.getId(), offering.getId(), prefix, prefix); checkNetwork(network); } @AfterGroups(groups = "live") protected void tearDown() { if (network != null) { - client.getNetworkClient().deleteNetwork(network.getId()); + jobComplete.apply(client.getNetworkClient().deleteNetwork(network.getId())); } super.tearDown(); } @@ -100,7 +96,7 @@ public class NetworkClientLiveTest extends BaseCloudStackClientLiveTest { assertTrue(networkCount >= 0); for (Network network : response) { Network newDetails = Iterables.getOnlyElement(client.getNetworkClient().listNetworks( - ListNetworksOptions.Builder.id(network.getId()))); + ListNetworksOptions.Builder.id(network.getId()))); assertEquals(network, newDetails); assertEquals(network, client.getNetworkClient().getNetwork(network.getId())); checkNetwork(network); @@ -129,21 +125,21 @@ public class NetworkClientLiveTest extends BaseCloudStackClientLiveTest { assert network.getDomain() != null : network; assert network.getDomainId() > 0 : network; switch (network.getGuestIPType()) { - case VIRTUAL: - assert network.getNetmask() == null : network; - assert network.getGateway() == null : network; - assert network.getVLAN() == null : network; - assert network.getStartIP() == null : network; - assert network.getEndIP() == null : network; - break; - case DIRECT: - assert network.getNetmask() != null : network; - assert network.getGateway() != null : network; - assert network.getVLAN() != null : network; - assertEquals(network.getBroadcastURI(), "vlan://" + network.getVLAN()); - assert network.getStartIP() != null : network; - assert network.getEndIP() != null : network; - break; + case VIRTUAL: + assert network.getNetmask() == null : network; + assert network.getGateway() == null : network; + assert network.getVLAN() == null : network; + assert network.getStartIP() == null : network; + assert network.getEndIP() == null : network; + break; + case DIRECT: + assert network.getNetmask() != null : network; + assert network.getGateway() != null : network; + assert network.getVLAN() != null : network; + assertEquals(network.getBroadcastURI(), "vlan://" + network.getVLAN()); + assert network.getStartIP() != null : network; + assert network.getEndIP() != null : network; + break; } } } From 14f372be3b1669787ba08b4f72f0bc120c0a9f4e Mon Sep 17 00:00:00 2001 From: Mattias Holmqvist Date: Wed, 11 May 2011 00:42:32 +0200 Subject: [PATCH 04/38] Fixing clean-stub-fixture to call destroy-node correctly --- compute/src/test/clojure/org/jclouds/compute2_test.clj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compute/src/test/clojure/org/jclouds/compute2_test.clj b/compute/src/test/clojure/org/jclouds/compute2_test.clj index d173b481ac..952ac097e3 100644 --- a/compute/src/test/clojure/org/jclouds/compute2_test.clj +++ b/compute/src/test/clojure/org/jclouds/compute2_test.clj @@ -34,16 +34,16 @@ list, Alan Dipert and MeikelBrandmeyer." (deftest os-families-test (is (some #{"centos"} (map str (os-families))))) +(def *compute* (compute-service "stub" "" "")) + (defn clean-stub-fixture "This should allow basic tests to easily be run with another service." [compute-service] (fn [f] (doseq [node (nodes compute-service)] - (destroy-node (.getId node))) + (destroy-node *compute* (.getId node))) (f))) -(def *compute* (compute-service "stub" "" "")) - (use-fixtures :each (clean-stub-fixture *compute*)) (deftest compute-service?-test From cb5f8ab0e0985ca9dad341da5a17064471c45a00 Mon Sep 17 00:00:00 2001 From: Mattias Holmqvist Date: Wed, 11 May 2011 00:48:28 +0200 Subject: [PATCH 05/38] Inlined the in-group predicate in test --- .../test/clojure/org/jclouds/compute2_test.clj | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/compute/src/test/clojure/org/jclouds/compute2_test.clj b/compute/src/test/clojure/org/jclouds/compute2_test.clj index 952ac097e3..c419caffa3 100644 --- a/compute/src/test/clojure/org/jclouds/compute2_test.clj +++ b/compute/src/test/clojure/org/jclouds/compute2_test.clj @@ -54,28 +54,26 @@ list, Alan Dipert and MeikelBrandmeyer." (is (compute-service? *compute*)) (is (compute-service? (compute-service (compute-context *compute*))))) -(defn in-group [group] #(= (.getGroup %) group)) - (deftest nodes-test (is (empty? (nodes *compute*))) (is (create-node *compute* "fred" (build-template *compute* {} ))) (is (= 1 (count (nodes *compute*)))) (is (= 1 (count (nodes-in-group *compute* "fred")))) - (is (= 1 (count (nodes-with-details-matching *compute* (in-group "fred"))))) + (is (= 1 (count (nodes-with-details-matching *compute* #(= (.getGroup %) "fred"))))) (is (= 1 (count (nodes-with-details-matching *compute* (reify com.google.common.base.Predicate (apply [this input] (= (.getGroup input) "fred"))))))) - (is (= 0 (count (nodes-with-details-matching *compute* (in-group "othergroup"))))) - (suspend-nodes-matching *compute* (in-group "fred")) - (is (suspended? (first (nodes-with-details-matching *compute* (in-group "fred"))))) - (resume-nodes-matching *compute* (in-group "fred")) + (is (= 0 (count (nodes-with-details-matching *compute* #(= (.getGroup %) "othergroup"))))) + (suspend-nodes-matching *compute* #(= (.getGroup %) "fred")) + (is (suspended? (first (nodes-with-details-matching *compute* #(= (.getGroup %) "fred"))))) + (resume-nodes-matching *compute* #(= (.getGroup %) "fred")) (is (running? (first (nodes-in-group *compute* "fred")))) - (reboot-nodes-matching *compute* (in-group "fred")) + (reboot-nodes-matching *compute* #(= (.getGroup %) "fred")) (is (running? (first (nodes-in-group *compute* "fred")))) (is (create-nodes *compute* "fred" 2 (build-template *compute* {} ))) (is (= 3 (count (nodes-in-group *compute* "fred")))) (is (= "fred" (group (first (nodes *compute*))))) - (destroy-nodes-matching *compute* (in-group "fred")) + (destroy-nodes-matching *compute* #(= (.getGroup %) "fred")) (is (terminated? (first (nodes-in-group *compute* "fred"))))) (deftest build-template-test From 6c4294ed1cdd5f127e18858124ae0386ab9f65fe Mon Sep 17 00:00:00 2001 From: Mattias Holmqvist Date: Wed, 11 May 2011 00:55:21 +0200 Subject: [PATCH 06/38] Changed the order of args for some fns in compute2.clj. ComputeService should be the first arg --- compute/src/main/clojure/org/jclouds/compute2.clj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/compute/src/main/clojure/org/jclouds/compute2.clj b/compute/src/main/clojure/org/jclouds/compute2.clj index 40eefbc56f..a53d95b865 100644 --- a/compute/src/main/clojure/org/jclouds/compute2.clj +++ b/compute/src/main/clojure/org/jclouds/compute2.clj @@ -197,7 +197,7 @@ Here's an example of creating and running a small linux node in the group webser (defn suspend-node "Suspend a node, given its id." - ([id #^ComputeService compute] + ([#^ComputeService compute id] (.suspendNode compute id))) (defn resume-nodes-matching @@ -208,7 +208,7 @@ Here's an example of creating and running a small linux node in the group webser (defn resume-node "Resume a node, given its id." - ([id #^ComputeService compute] + ([#^ComputeService compute id] (.resumeNode compute id))) (defn reboot-nodes-matching @@ -219,7 +219,7 @@ Here's an example of creating and running a small linux node in the group webser (defn reboot-node "Reboot a node, given its id." - ([id #^ComputeService compute] + ([#^ComputeService compute id] (.rebootNode compute id))) (defn destroy-nodes-matching @@ -230,7 +230,7 @@ Here's an example of creating and running a small linux node in the group webser (defn destroy-node "Destroy a node, given its id." - ([id #^ComputeService compute] + ([#^ComputeService compute id] (.destroyNode compute id))) (defmacro state-predicate [node state] From f8b4f3e23e59974b1620b1d1c8dfc12a4e9a5f19 Mon Sep 17 00:00:00 2001 From: Mattias Holmqvist Date: Wed, 11 May 2011 01:47:19 +0200 Subject: [PATCH 07/38] Fixed one more issue with clean-stub-fixture --- compute/src/test/clojure/org/jclouds/compute2_test.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compute/src/test/clojure/org/jclouds/compute2_test.clj b/compute/src/test/clojure/org/jclouds/compute2_test.clj index c419caffa3..87abc40540 100644 --- a/compute/src/test/clojure/org/jclouds/compute2_test.clj +++ b/compute/src/test/clojure/org/jclouds/compute2_test.clj @@ -41,7 +41,7 @@ list, Alan Dipert and MeikelBrandmeyer." [compute-service] (fn [f] (doseq [node (nodes compute-service)] - (destroy-node *compute* (.getId node))) + (destroy-node compute-service (.getId node))) (f))) (use-fixtures :each (clean-stub-fixture *compute*)) From 6ca5a99484b70914d06583f6e5fb41c48f0040ca Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Tue, 10 May 2011 17:16:53 -0700 Subject: [PATCH 08/38] fixed network predicates --- .../cloudstack/domain/NetworkOffering.java | 24 +++++- .../predicates/NetworkOfferingPredicates.java | 61 +++++++++++++++ .../cloudstack/predicates/ZonePredicates.java | 68 ++++++++++------ .../features/AccountClientLiveTest.java | 3 +- .../features/NetworkClientLiveTest.java | 18 ++--- .../VirtualMachineClientLiveTest.java | 78 +++++++++---------- 6 files changed, 173 insertions(+), 79 deletions(-) create mode 100644 sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/predicates/NetworkOfferingPredicates.java diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/NetworkOffering.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/NetworkOffering.java index 6f4581126a..cd70eea1a6 100644 --- a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/NetworkOffering.java +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/NetworkOffering.java @@ -50,6 +50,7 @@ public class NetworkOffering implements Comparable { private boolean isDefault; private boolean supportsVLAN; private TrafficType trafficType; + private GuestIPType guestIPType; private Set tags = ImmutableSet.of(); public Builder id(long id) { @@ -102,6 +103,11 @@ public class NetworkOffering implements Comparable { return this; } + public Builder guestIPType(GuestIPType guestIPType) { + this.guestIPType = guestIPType; + return this; + } + public Builder tags(Set tags) { this.tags = ImmutableSet.copyOf(checkNotNull(tags, "tags")); return this; @@ -109,7 +115,7 @@ public class NetworkOffering implements Comparable { public NetworkOffering build() { return new NetworkOffering(id, name, displayText, created, availability, supportsVLAN, maxConnections, - isDefault, trafficType, networkRate, tags); + isDefault, trafficType, guestIPType, networkRate, tags); } } @@ -127,13 +133,15 @@ public class NetworkOffering implements Comparable { private boolean supportsVLAN; @SerializedName("traffictype") private TrafficType trafficType; + @SerializedName("guestiptype") + private GuestIPType guestIPType; @SerializedName("networkrate") private int networkRate = -1; private String tags; public NetworkOffering(long id, String name, String displayText, @Nullable Date created, String availability, boolean supportsVLAN, @Nullable Integer maxConnections, boolean isDefault, TrafficType trafficType, - int networkRate, Set tags) { + GuestIPType guestIPType, int networkRate, Set tags) { this.id = id; this.name = name; this.displayText = displayText; @@ -143,6 +151,7 @@ public class NetworkOffering implements Comparable { this.maxConnections = maxConnections; this.isDefault = isDefault; this.trafficType = trafficType; + this.guestIPType = guestIPType; this.networkRate = networkRate; this.tags = tags.size() == 0 ? null : Joiner.on(',').join(tags); } @@ -207,7 +216,8 @@ public class NetworkOffering implements Comparable { /** * - * @return the max number of concurrent connection the network offering supports + * @return the max number of concurrent connection the network offering + * supports */ @Nullable public Integer getMaxConnections() { @@ -230,6 +240,14 @@ public class NetworkOffering implements Comparable { return trafficType; } + /** + * + * @return the guest ip type for this network offering + */ + public GuestIPType getGuestIPType() { + return guestIPType; + } + /** * * @return data transfer rate in megabits per second allowed. diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/predicates/NetworkOfferingPredicates.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/predicates/NetworkOfferingPredicates.java new file mode 100644 index 0000000000..9b9b5100f6 --- /dev/null +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/predicates/NetworkOfferingPredicates.java @@ -0,0 +1,61 @@ +/** + * + * Copyright (C) 2011 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed 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.predicates; + +import static com.google.common.base.Predicates.alwaysTrue; + +import org.jclouds.cloudstack.domain.GuestIPType; +import org.jclouds.cloudstack.domain.NetworkOffering; +import org.jclouds.cloudstack.domain.TrafficType; + +import com.google.common.base.Predicate; + +/** + * + * @author Adrian Cole + */ +public class NetworkOfferingPredicates { + + /** + * + * @return true, if the offering supports creation of GuestVirtual Networks + */ + public static Predicate supportsGuestVirtualNetworks() { + return new Predicate() { + + @Override + public boolean apply(NetworkOffering arg0) { + return arg0.getTrafficType() == TrafficType.GUEST && arg0.getGuestIPType() == GuestIPType.VIRTUAL; + } + + @Override + public String toString() { + return "supportsGuestVirtualNetworks()"; + } + }; + } + + /** + * + * @return always returns true. + */ + public static Predicate any() { + return alwaysTrue(); + } +} diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/predicates/ZonePredicates.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/predicates/ZonePredicates.java index 5638c5e4d5..90afa1c682 100644 --- a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/predicates/ZonePredicates.java +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/predicates/ZonePredicates.java @@ -19,46 +19,64 @@ package org.jclouds.cloudstack.predicates; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Predicates.alwaysTrue; +import static com.google.common.base.Predicates.and; +import static com.google.common.base.Predicates.not; import org.jclouds.cloudstack.domain.NetworkType; import org.jclouds.cloudstack.domain.Zone; import com.google.common.base.Predicate; -import com.google.common.base.Predicates; /** * * @author Adrian Cole */ public class ZonePredicates { - - public static class SupportsNetworkType implements Predicate { - private final org.jclouds.cloudstack.domain.NetworkType type; - - public SupportsNetworkType(org.jclouds.cloudstack.domain.NetworkType type) { - this.type = checkNotNull(type, "type"); - } - - @Override - public boolean apply(Zone input) { - return type.equals(checkNotNull(input, "zone").getNetworkType()); - } - - @Override - public String toString() { - return "supportsNetworkType(" + type + ")"; - } - } - - static Predicate supportsAdvancedNetworks = new SupportsNetworkType( - org.jclouds.cloudstack.domain.NetworkType.ADVANCED); - /** * * @return true, if the zone supports {@link NetworkType.ADVANCED} */ public static Predicate supportsAdvancedNetworks() { - return supportsAdvancedNetworks; + return new Predicate() { + + @Override + public boolean apply(Zone input) { + return NetworkType.ADVANCED.equals(checkNotNull(input, "zone").getNetworkType()); + } + + @Override + public String toString() { + return "supportsAvancedNetworks()"; + } + }; + } + + /** + * + * @return true, if the zone supports security groups + */ + public static Predicate supportsSecurityGroups() { + return new Predicate() { + + @Override + public boolean apply(Zone input) { + return input.isSecurityGroupsEnabled(); + } + + @Override + public String toString() { + return "supportsSecurityGroups()"; + } + }; + } + + /** + * + * @return true, if the zone supports creation of GuestVirtual Networks + */ + public static Predicate supportsGuestVirtualNetworks() { + return and(supportsAdvancedNetworks(), not(supportsSecurityGroups())); } /** @@ -66,6 +84,6 @@ public class ZonePredicates { * @return always returns true. */ public static Predicate any() { - return Predicates.alwaysTrue(); + return alwaysTrue(); } } diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AccountClientLiveTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AccountClientLiveTest.java index 5a41e1fd2d..3c4526fba4 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AccountClientLiveTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AccountClientLiveTest.java @@ -75,7 +75,8 @@ public class AccountClientLiveTest extends BaseCloudStackClientLiveTest { assert account.getVMLimit() == null || account.getVMLimit() >= 0 : account; assert account.getVMsRunning() >= 0 : account; assert account.getVMsStopped() >= 0 : account; - assert account.getVMs() >= 0 : account; + // TODO update to 2.2.4 as this is a bug in 2.2.3 + // assert account.getVMs() >= 0 : account; assert account.getVolumesAvailable() == null || account.getVolumesAvailable() >= 0 : account; assert account.getVolumeLimit() == null || account.getVolumeLimit() >= 0 : account; assert account.getVolumes() >= 0 : account; diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NetworkClientLiveTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NetworkClientLiveTest.java index e27ce5fc6e..2f83ad3a48 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NetworkClientLiveTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NetworkClientLiveTest.java @@ -30,12 +30,12 @@ import org.jclouds.cloudstack.domain.Network; import org.jclouds.cloudstack.domain.NetworkOffering; import org.jclouds.cloudstack.domain.Zone; import org.jclouds.cloudstack.options.ListNetworksOptions; +import org.jclouds.cloudstack.predicates.NetworkOfferingPredicates; import org.jclouds.cloudstack.predicates.ZonePredicates; import org.testng.annotations.AfterGroups; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; -import com.google.common.base.Predicate; import com.google.common.collect.Iterables; /** @@ -58,21 +58,17 @@ public class NetworkClientLiveTest extends BaseCloudStackClientLiveTest { super.setupClient(); try { - zone = find(client.getZoneClient().listZones(), ZonePredicates.supportsAdvancedNetworks()); - offering = Iterables.find(client.getOfferingClient().listNetworkOfferings(), new Predicate() { - - @Override - public boolean apply(NetworkOffering arg0) { - return "Optional".equals(arg0.getAvailability()); - } - - }); + // you can create guest direct network by Admin user, but since we are + // not admin, let's try to create a guest virtual one + zone = find(client.getZoneClient().listZones(), ZonePredicates.supportsGuestVirtualNetworks()); + offering = Iterables.find(client.getOfferingClient().listNetworkOfferings(), + NetworkOfferingPredicates.supportsGuestVirtualNetworks()); networksSupported = true; } catch (NoSuchElementException e) { } } - public void testCreateNetworks() throws Exception { + public void testCreateNetwork() throws Exception { if (!networksSupported) return; network = client.getNetworkClient().createNetworkInZone(zone.getId(), offering.getId(), prefix, prefix); diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/VirtualMachineClientLiveTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/VirtualMachineClientLiveTest.java index 3e571c4cd8..22b5a2c953 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/VirtualMachineClientLiveTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/VirtualMachineClientLiveTest.java @@ -72,39 +72,39 @@ public class VirtualMachineClientLiveTest extends BaseCloudStackClientLiveTest { static final Ordering DEFAULT_SIZE_ORDERING = new Ordering() { public int compare(ServiceOffering left, ServiceOffering right) { - return ComparisonChain.start().compare(left.getCpuNumber(), right.getCpuNumber()).compare(left.getMemory(), - right.getMemory()).result(); + return ComparisonChain.start().compare(left.getCpuNumber(), right.getCpuNumber()) + .compare(left.getMemory(), right.getMemory()).result(); } }; public static VirtualMachine createVirtualMachine(CloudStackClient client, RetryablePredicate jobComplete, - RetryablePredicate virtualMachineRunning) { + RetryablePredicate virtualMachineRunning) { Set networks = client.getNetworkClient().listNetworks(); if (networks.size() > 0) { return createVirtualMachineInNetwork(get(networks, 0), client, jobComplete, virtualMachineRunning); } else { - return createVirtualMachineWithSecurityGroupInZone(find(client.getZoneClient().listZones(), - new Predicate() { + return createVirtualMachineWithSecurityGroupInZone( + find(client.getZoneClient().listZones(), new Predicate() { - @Override - public boolean apply(Zone arg0) { - return arg0.isSecurityGroupsEnabled(); - } + @Override + public boolean apply(Zone arg0) { + return arg0.isSecurityGroupsEnabled(); + } - }).getId(), get(client.getSecurityGroupClient().listSecurityGroups(), 0).getId(), client, - jobComplete, virtualMachineRunning); + }).getId(), get(client.getSecurityGroupClient().listSecurityGroups(), 0).getId(), client, jobComplete, + virtualMachineRunning); } } public static VirtualMachine createVirtualMachineWithSecurityGroupInZone(long zoneId, long groupId, - CloudStackClient client, RetryablePredicate jobComplete, - RetryablePredicate virtualMachineRunning) { + CloudStackClient client, RetryablePredicate jobComplete, + RetryablePredicate virtualMachineRunning) { return createVirtualMachineWithOptionsInZone(new DeployVirtualMachineOptions().securityGroupId(groupId), zoneId, - client, jobComplete, virtualMachineRunning); + client, jobComplete, virtualMachineRunning); } public static VirtualMachine createVirtualMachineInNetwork(Network network, CloudStackClient client, - RetryablePredicate jobComplete, RetryablePredicate virtualMachineRunning) { + RetryablePredicate jobComplete, RetryablePredicate virtualMachineRunning) { DeployVirtualMachineOptions options = new DeployVirtualMachineOptions(); long zoneId = network.getZoneId(); options.networkId(network.getId()); @@ -112,8 +112,8 @@ public class VirtualMachineClientLiveTest extends BaseCloudStackClientLiveTest { } public static VirtualMachine createVirtualMachineWithOptionsInZone(DeployVirtualMachineOptions options, - final long zoneId, CloudStackClient client, RetryablePredicate jobComplete, - RetryablePredicate virtualMachineRunning) { + final long zoneId, CloudStackClient client, RetryablePredicate jobComplete, + RetryablePredicate virtualMachineRunning) { // TODO enum, as this is way too easy to mess up. Set acceptableCategories = ImmutableSet.of("Ubuntu", "CentOS"); @@ -121,9 +121,9 @@ public class VirtualMachineClientLiveTest extends BaseCloudStackClientLiveTest { final Predicate