diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackAsyncClient.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackAsyncClient.java index a191033fe6..891b2f6ffe 100644 --- a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackAsyncClient.java +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackAsyncClient.java @@ -21,8 +21,10 @@ package org.jclouds.cloudstack; import org.jclouds.cloudstack.features.AddressAsyncClient; import org.jclouds.cloudstack.features.AsyncJobAsyncClient; +import org.jclouds.cloudstack.features.ConfigurationAsyncClient; import org.jclouds.cloudstack.features.FirewallAsyncClient; import org.jclouds.cloudstack.features.GuestOSAsyncClient; +import org.jclouds.cloudstack.features.HypervisorAsyncClient; import org.jclouds.cloudstack.features.LoadBalancerAsyncClient; import org.jclouds.cloudstack.features.NATAsyncClient; import org.jclouds.cloudstack.features.NetworkAsyncClient; @@ -114,4 +116,16 @@ public interface CloudStackAsyncClient { */ @Delegate GuestOSAsyncClient getGuestOSClient(); + + /** + * Provides asynchronous access to Hypervisor features. + */ + @Delegate + HypervisorAsyncClient getHypervisorClient(); + + /** + * Provides asynchronous access to Configuration features. + */ + @Delegate + ConfigurationAsyncClient getConfigurationClient(); } diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackClient.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackClient.java index e284b655a3..980ecb80e2 100644 --- a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackClient.java +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackClient.java @@ -23,8 +23,10 @@ import java.util.concurrent.TimeUnit; import org.jclouds.cloudstack.features.AddressClient; import org.jclouds.cloudstack.features.AsyncJobClient; +import org.jclouds.cloudstack.features.ConfigurationClient; import org.jclouds.cloudstack.features.FirewallClient; import org.jclouds.cloudstack.features.GuestOSClient; +import org.jclouds.cloudstack.features.HypervisorClient; import org.jclouds.cloudstack.features.LoadBalancerClient; import org.jclouds.cloudstack.features.NATClient; import org.jclouds.cloudstack.features.NetworkClient; @@ -117,4 +119,16 @@ public interface CloudStackClient { */ @Delegate GuestOSClient getGuestOSClient(); + + /** + * Provides synchronous access to Hypervisor features. + */ + @Delegate + HypervisorClient getHypervisorClient(); + + /** + * Provides synchronous access to Configuration features. + */ + @Delegate + ConfigurationClient getConfigurationClient(); } diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/binders/BindAccountSecurityGroupPairsToIndexedQueryParams.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/binders/BindAccountSecurityGroupPairsToIndexedQueryParams.java new file mode 100644 index 0000000000..c5f7afa38f --- /dev/null +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/binders/BindAccountSecurityGroupPairsToIndexedQueryParams.java @@ -0,0 +1,70 @@ +/** + * + * Copyright (C) 2010 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.binders; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Map.Entry; + +import javax.inject.Inject; +import javax.inject.Provider; +import javax.inject.Singleton; +import javax.ws.rs.core.UriBuilder; + +import org.jclouds.http.HttpRequest; +import org.jclouds.http.utils.ModifyRequest; +import org.jclouds.rest.Binder; + +import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.Multimap; +import com.google.common.collect.ImmutableMultimap.Builder; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class BindAccountSecurityGroupPairsToIndexedQueryParams implements Binder { + private final Provider uriBuilderProvider; + + @Inject + public BindAccountSecurityGroupPairsToIndexedQueryParams(Provider uriBuilderProvider) { + this.uriBuilderProvider = checkNotNull(uriBuilderProvider, "uriBuilderProvider"); + } + + @SuppressWarnings("unchecked") + @Override + public R bindToRequest(R request, Object input) { + checkArgument(input instanceof Multimap, "this binder is only valid for Multimaps!"); + Multimap pairs = (Multimap) checkNotNull(input, "account group pairs"); + checkArgument(pairs.size() > 0, "you must specify at least one account, group pair"); + UriBuilder builder = uriBuilderProvider.get(); + builder.uri(request.getEndpoint()); + Builder map = ImmutableMultimap. builder().putAll( + ModifyRequest.parseQueryToMap(request.getEndpoint().getQuery())); + int i = 0; + for (Entry entry : pairs.entries()) + map.put(String.format("usersecuritygrouplist[%d].account", i), entry.getKey()).put( + String.format("usersecuritygrouplist[%d].group", i++), entry.getValue()); + builder.replaceQuery(ModifyRequest.makeQueryLine(map.build(), null)); + return (R) request.toBuilder().endpoint(builder.build()).build(); + } +} diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/binders/BindCIDRsToCommaDelimitedQueryParam.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/binders/BindCIDRsToCommaDelimitedQueryParam.java new file mode 100644 index 0000000000..4ef7f5565b --- /dev/null +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/binders/BindCIDRsToCommaDelimitedQueryParam.java @@ -0,0 +1,58 @@ +/** + * + * Copyright (C) 2010 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.binders; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.inject.Inject; +import javax.inject.Provider; +import javax.inject.Singleton; +import javax.ws.rs.core.UriBuilder; + +import org.jclouds.http.HttpRequest; +import org.jclouds.http.utils.ModifyRequest; +import org.jclouds.rest.Binder; + +import com.google.common.base.Joiner; +import com.google.common.collect.Iterables; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class BindCIDRsToCommaDelimitedQueryParam implements Binder { + private final Provider uriBuilderProvider; + + @Inject + public BindCIDRsToCommaDelimitedQueryParam(Provider uriBuilderProvider) { + this.uriBuilderProvider = checkNotNull(uriBuilderProvider, "uriBuilderProvider"); + } + + @SuppressWarnings("unchecked") + @Override + public R bindToRequest(R request, Object input) { + checkArgument(input instanceof Iterable, "this binder is only valid for Iterables!"); + Iterable cidrs = (Iterable) checkNotNull(input, "cidr list"); + checkArgument(Iterables.size(cidrs) > 0, "you must specify at least one cidr range"); + return ModifyRequest.addQueryParam(request, "cidrlist", Joiner.on(',').join(cidrs), uriBuilderProvider.get()); + } +} diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackRestClientModule.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackRestClientModule.java index 885154edc3..cac06eae68 100644 --- a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackRestClientModule.java +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackRestClientModule.java @@ -27,10 +27,14 @@ import org.jclouds.cloudstack.features.AddressAsyncClient; import org.jclouds.cloudstack.features.AddressClient; import org.jclouds.cloudstack.features.AsyncJobAsyncClient; import org.jclouds.cloudstack.features.AsyncJobClient; +import org.jclouds.cloudstack.features.ConfigurationAsyncClient; +import org.jclouds.cloudstack.features.ConfigurationClient; import org.jclouds.cloudstack.features.FirewallAsyncClient; import org.jclouds.cloudstack.features.FirewallClient; import org.jclouds.cloudstack.features.GuestOSAsyncClient; import org.jclouds.cloudstack.features.GuestOSClient; +import org.jclouds.cloudstack.features.HypervisorAsyncClient; +import org.jclouds.cloudstack.features.HypervisorClient; import org.jclouds.cloudstack.features.LoadBalancerAsyncClient; import org.jclouds.cloudstack.features.LoadBalancerClient; import org.jclouds.cloudstack.features.NATAsyncClient; @@ -72,19 +76,21 @@ import com.google.common.collect.ImmutableMap; public class CloudStackRestClientModule extends RestClientModule { public static final Map, Class> DELEGATE_MAP = ImmutableMap., Class> builder()// - .put(ZoneClient.class, ZoneAsyncClient.class)// - .put(TemplateClient.class, TemplateAsyncClient.class)// - .put(OfferingClient.class, OfferingAsyncClient.class)// - .put(NetworkClient.class, NetworkAsyncClient.class)// - .put(VirtualMachineClient.class, VirtualMachineAsyncClient.class)// - .put(SecurityGroupClient.class, SecurityGroupAsyncClient.class)// - .put(AsyncJobClient.class, AsyncJobAsyncClient.class)// - .put(AddressClient.class, AddressAsyncClient.class)// - .put(NATClient.class, NATAsyncClient.class)// - .put(FirewallClient.class, FirewallAsyncClient.class)// - .put(LoadBalancerClient.class, LoadBalancerAsyncClient.class)// - .put(GuestOSClient.class, GuestOSAsyncClient.class)// - .build(); + .put(ZoneClient.class, ZoneAsyncClient.class)// + .put(TemplateClient.class, TemplateAsyncClient.class)// + .put(OfferingClient.class, OfferingAsyncClient.class)// + .put(NetworkClient.class, NetworkAsyncClient.class)// + .put(VirtualMachineClient.class, VirtualMachineAsyncClient.class)// + .put(SecurityGroupClient.class, SecurityGroupAsyncClient.class)// + .put(AsyncJobClient.class, AsyncJobAsyncClient.class)// + .put(AddressClient.class, AddressAsyncClient.class)// + .put(NATClient.class, NATAsyncClient.class)// + .put(FirewallClient.class, FirewallAsyncClient.class)// + .put(LoadBalancerClient.class, LoadBalancerAsyncClient.class)// + .put(GuestOSClient.class, GuestOSAsyncClient.class)// + .put(HypervisorClient.class, HypervisorAsyncClient.class)// + .put(ConfigurationClient.class, ConfigurationAsyncClient.class)// + .build(); public CloudStackRestClientModule() { super(CloudStackClient.class, CloudStackAsyncClient.class, DELEGATE_MAP); diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Capabilities.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Capabilities.java new file mode 100644 index 0000000000..74efd7ed03 --- /dev/null +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Capabilities.java @@ -0,0 +1,140 @@ +/** + * + * Copyright (C) 2010 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.domain; + +import com.google.gson.annotations.SerializedName; + +/** + * + * @author Adrian Cole + */ +public class Capabilities { + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + private String cloudStackVersion; + private boolean securityGroupsEnabled; + private boolean canShareTemplates; + + public Builder cloudStackVersion(String cloudStackVersion) { + this.cloudStackVersion = cloudStackVersion; + return this; + } + + public Builder securityGroupsEnabled(boolean securityGroupsEnabled) { + this.securityGroupsEnabled = securityGroupsEnabled; + return this; + } + + public Builder sharedTemplatesEnabled(boolean canShareTemplates) { + this.canShareTemplates = canShareTemplates; + return this; + } + + public Capabilities build() { + return new Capabilities(cloudStackVersion, securityGroupsEnabled, canShareTemplates); + } + } + + @SerializedName("cloudstackversion") + private String cloudStackVersion; + @SerializedName("securitygroupsenabled") + private boolean securityGroupsEnabled; + @SerializedName("userpublictemplateenabled") + private boolean canShareTemplates; + + /** + * present only for serializer + * + */ + Capabilities() { + + } + + public Capabilities(String cloudStackVersion, boolean securityGroupsEnabled, boolean canShareTemplates) { + this.cloudStackVersion = cloudStackVersion; + this.securityGroupsEnabled = securityGroupsEnabled; + this.canShareTemplates = canShareTemplates; + + } + + /** + * + * @return version of the cloud stack + */ + public String getCloudStackVersion() { + return cloudStackVersion; + } + + /** + * + * @return true if security groups support is enabled, false otherwise + */ + public boolean isSecurityGroupsEnabled() { + return securityGroupsEnabled; + } + + /** + * + * @return true if user and domain admins can set templates to be shared, false otherwise + */ + public boolean isSharedTemplatesEnabled() { + return canShareTemplates; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (canShareTemplates ? 1231 : 1237); + result = prime * result + ((cloudStackVersion == null) ? 0 : cloudStackVersion.hashCode()); + result = prime * result + (securityGroupsEnabled ? 1231 : 1237); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Capabilities other = (Capabilities) obj; + if (canShareTemplates != other.canShareTemplates) + return false; + if (cloudStackVersion == null) { + if (other.cloudStackVersion != null) + return false; + } else if (!cloudStackVersion.equals(other.cloudStackVersion)) + return false; + if (securityGroupsEnabled != other.securityGroupsEnabled) + return false; + return true; + } + + @Override + public String toString() { + return "[cloudStackVersion=" + cloudStackVersion + ", canShareTemplates=" + canShareTemplates + + ", securityGroupsEnabled=" + securityGroupsEnabled + "]"; + } +} diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/IngressRule.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/IngressRule.java index ed3ad47d52..cd0f22553c 100644 --- a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/IngressRule.java +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/IngressRule.java @@ -19,6 +19,8 @@ package org.jclouds.cloudstack.domain; +import static com.google.common.base.Preconditions.checkArgument; + import com.google.gson.annotations.SerializedName; /** @@ -33,13 +35,13 @@ public class IngressRule implements Comparable { public static class Builder { private String account; private String CIDR; - private int endPort; - private int ICMPCode; - private int ICMPType; + private int endPort = -1; + private int ICMPCode = -1; + private int ICMPType = -1; private String protocol; - private long id; + private long id = -1; private String securityGroupName; - private int startPort; + private int startPort = -1; public Builder account(String account) { this.account = account; @@ -95,28 +97,34 @@ public class IngressRule implements Comparable { @SerializedName("cidr") private String CIDR; @SerializedName("endport") - private int endPort; + private int endPort = -1; @SerializedName("icmpcode") - private int ICMPCode; + private int ICMPCode = -1; @SerializedName("icmptype") - private int ICMPType; + private int ICMPType = -1; private String protocol; @SerializedName("ruleid") - private long id; + private long id = -1; @SerializedName("securitygroupname") private String securityGroupName; @SerializedName("startport") - private int startPort; + private int startPort = -1; // for serialization IngressRule() { } - public IngressRule(String account, String cIDR, int endPort, int iCMPCode, int iCMPType, String protocol, long id, - String securityGroupName, int startPort) { + public IngressRule(String account, String CIDR, int endPort, int iCMPCode, int iCMPType, String protocol, long id, + String securityGroupName, int startPort) { + if (account == null) + checkArgument(securityGroupName == null && CIDR != null, + "if you do not specify an account and security group, you must specify a CIDR range"); + if (CIDR == null) + checkArgument(account != null && securityGroupName != null, + "if you do not specify an account and security group, you must specify a CIDR range"); this.account = account; - this.CIDR = cIDR; + this.CIDR = CIDR; this.endPort = endPort; this.ICMPCode = iCMPCode; this.ICMPType = iCMPType; @@ -250,8 +258,8 @@ public class IngressRule implements Comparable { @Override public String toString() { return "[id=" + id + ", securityGroupName=" + securityGroupName + ", account=" + account + ", startPort=" - + startPort + ", endPort=" + endPort + ", protocol=" + protocol + ", CIDR=" + CIDR + ", ICMPCode=" - + ICMPCode + ", ICMPType=" + ICMPType + "]"; + + startPort + ", endPort=" + endPort + ", protocol=" + protocol + ", CIDR=" + CIDR + ", ICMPCode=" + + ICMPCode + ", ICMPType=" + ICMPType + "]"; } @Override diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Zone.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Zone.java index da77254687..8f03dc75d2 100644 --- a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Zone.java +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Zone.java @@ -287,7 +287,7 @@ public class Zone implements Comparable { /** * - * @return true if this is an advanced network with security groups enabled, or a basic network. + * @return true if this zone has security groups enabled */ public boolean isSecurityGroupsEnabled() { return securityGroupsEnabled; diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/ConfigurationAsyncClient.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/ConfigurationAsyncClient.java new file mode 100644 index 0000000000..efefb7947c --- /dev/null +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/ConfigurationAsyncClient.java @@ -0,0 +1,55 @@ +/** + * + * Copyright (C) 2010 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.features; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.core.MediaType; + +import org.jclouds.cloudstack.domain.Capabilities; +import org.jclouds.cloudstack.filters.QuerySigner; +import org.jclouds.rest.annotations.QueryParams; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.Unwrap; + +import com.google.common.util.concurrent.ListenableFuture; + +/** + * Provides asynchronous access to cloudstack via their REST API. + *

+ * + * @see ConfigurationClient + * @see + * @author Adrian Cole + */ +@RequestFilters(QuerySigner.class) +@QueryParams(keys = "response", values = "json") +public interface ConfigurationAsyncClient { + + /** + * @see ConfigurationClient#listCapabilities + */ + @GET + @QueryParams(keys = "command", values = "listCapabilities") + @Unwrap(depth = 2) + @Consumes(MediaType.APPLICATION_JSON) + ListenableFuture listCapabilities(); + +} diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/ConfigurationClient.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/ConfigurationClient.java new file mode 100644 index 0000000000..00170aacf9 --- /dev/null +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/ConfigurationClient.java @@ -0,0 +1,45 @@ +/** + * + * Copyright (C) 2010 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.features; + +import java.util.concurrent.TimeUnit; + +import org.jclouds.cloudstack.domain.Capabilities; +import org.jclouds.concurrent.Timeout; + +/** + * Provides synchronous access to CloudStack Configuration features. + *

+ * + * @see ConfigurationAsyncClient + * @see + * @author Adrian Cole + */ +@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) +public interface ConfigurationClient { + /** + * Lists capabilities + * + * @return current capabilities of this cloud + * + */ + Capabilities listCapabilities(); + +} diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GuestOSAsyncClient.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GuestOSAsyncClient.java index 40a9ec84f8..7f8b12fb49 100644 --- a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GuestOSAsyncClient.java +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GuestOSAsyncClient.java @@ -19,6 +19,7 @@ package org.jclouds.cloudstack.features; +import java.util.Map; import java.util.Set; import javax.ws.rs.Consumes; @@ -28,10 +29,13 @@ import javax.ws.rs.core.MediaType; import org.jclouds.cloudstack.domain.OSType; import org.jclouds.cloudstack.filters.QuerySigner; +import org.jclouds.cloudstack.functions.ParseIdToNameEntryFromHttpResponse; +import org.jclouds.cloudstack.functions.ParseIdToNameFromHttpResponse; import org.jclouds.cloudstack.options.ListOSTypesOptions; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.QueryParams; import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.ResponseParser; import org.jclouds.rest.annotations.Unwrap; import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; @@ -69,4 +73,23 @@ public interface GuestOSAsyncClient { @Consumes(MediaType.APPLICATION_JSON) @ExceptionParser(ReturnNullOnNotFoundOr404.class) ListenableFuture getOSType(@QueryParam("id") long id); + + /** + * @see GuestOSClient#listOSCategories + */ + @GET + @QueryParams(keys = "command", values = "listOsCategories") + @ResponseParser(ParseIdToNameFromHttpResponse.class) + @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) + ListenableFuture> listOSCategories(); + + /** + * @see GuestOSClient#getOSCategory + */ + @GET + @QueryParams(keys = "command", values = "listOsCategories") + @ResponseParser(ParseIdToNameEntryFromHttpResponse.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture> getOSCategory(@QueryParam("id") long id); + } diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GuestOSClient.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GuestOSClient.java index 80c4d76a3e..9ae99fd15e 100644 --- a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GuestOSClient.java +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GuestOSClient.java @@ -19,6 +19,7 @@ package org.jclouds.cloudstack.features; +import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; @@ -53,4 +54,20 @@ public interface GuestOSClient { * @return os type or null if not found */ OSType getOSType(long id); + + /** + * Lists all supported OS categories for this cloud. + * + * @return os categories matching query, or empty set, if no categories are found + */ + Map listOSCategories(); + + /** + * get a specific os category by id + * + * @param id + * os category to get + * @return os category or null if not found + */ + Map.Entry getOSCategory(long id); } diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/HypervisorAsyncClient.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/HypervisorAsyncClient.java new file mode 100644 index 0000000000..c9ac333710 --- /dev/null +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/HypervisorAsyncClient.java @@ -0,0 +1,66 @@ +/** + * + * Copyright (C) 2010 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.features; + +import java.util.Set; + +import javax.ws.rs.GET; +import javax.ws.rs.QueryParam; + +import org.jclouds.cloudstack.filters.QuerySigner; +import org.jclouds.cloudstack.functions.ParseNamesFromHttpResponse; +import org.jclouds.rest.annotations.ExceptionParser; +import org.jclouds.rest.annotations.QueryParams; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.ResponseParser; +import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; + +import com.google.common.util.concurrent.ListenableFuture; + +/** + * Provides asynchronous access to cloudstack via their REST API. + *

+ * + * @see AsyncJobClient + * @see + * @author Adrian Cole + */ +@RequestFilters(QuerySigner.class) +@QueryParams(keys = "response", values = "json") +public interface HypervisorAsyncClient { + + /** + * @see HypervisorClient#listHypervisors + */ + @GET + @QueryParams(keys = "command", values = "listHypervisors") + @ResponseParser(ParseNamesFromHttpResponse.class) + @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) + ListenableFuture> listHypervisors(); + + /** + * @see HypervisorClient#listHypervisorsInZone + */ + @GET + @QueryParams(keys = "command", values = "listHypervisors") + @ResponseParser(ParseNamesFromHttpResponse.class) + @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) + ListenableFuture> listHypervisorsInZone(@QueryParam("zoneid") long zoneId); +} diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/HypervisorClient.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/HypervisorClient.java new file mode 100644 index 0000000000..f54454f3c7 --- /dev/null +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/HypervisorClient.java @@ -0,0 +1,53 @@ +/** + * + * Copyright (C) 2010 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.features; + +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import org.jclouds.concurrent.Timeout; + +/** + * Provides synchronous access to CloudStack Operating System features. + *

+ * + * @see GuestOSAsyncClient + * @see + * @author Adrian Cole + */ +@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) +public interface HypervisorClient { + /** + * Lists all supported hypervisors for this cloud. + * + * @return hypervisors, or empty set, if no hypervisors are found + */ + Set listHypervisors(); + + /** + * Lists all supported hypervisors for this zone. + * + * @param zoneId + * the zone id for listing hypervisors. + * @return hypervisors in the zone, or empty set, if no hypervisors are found + */ + Set listHypervisorsInZone(long zoneId); + +} diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/SecurityGroupAsyncClient.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/SecurityGroupAsyncClient.java index c64b6d4e11..fe761f32c0 100644 --- a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/SecurityGroupAsyncClient.java +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/SecurityGroupAsyncClient.java @@ -26,9 +26,13 @@ import javax.ws.rs.GET; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; +import org.jclouds.cloudstack.binders.BindAccountSecurityGroupPairsToIndexedQueryParams; +import org.jclouds.cloudstack.binders.BindCIDRsToCommaDelimitedQueryParam; import org.jclouds.cloudstack.domain.SecurityGroup; import org.jclouds.cloudstack.filters.QuerySigner; +import org.jclouds.cloudstack.options.AccountInDomainOptions; import org.jclouds.cloudstack.options.ListSecurityGroupsOptions; +import org.jclouds.rest.annotations.BinderParam; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.QueryParams; import org.jclouds.rest.annotations.RequestFilters; @@ -37,6 +41,7 @@ import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; +import com.google.common.collect.Multimap; import com.google.common.util.concurrent.ListenableFuture; /** @@ -80,6 +85,70 @@ public interface SecurityGroupAsyncClient { @Consumes(MediaType.APPLICATION_JSON) ListenableFuture createSecurityGroup(@QueryParam("name") String name); + /** + * @see SecurityGroupClient#authorizeIngressPortsToCIDRs + */ + @GET + @QueryParams(keys = "command", values = "authorizeSecurityGroupIngress") + @Unwrap(depth = 2) + @Consumes(MediaType.APPLICATION_JSON) + ListenableFuture authorizeIngressPortsToCIDRs(@QueryParam("securitygroupid") long securityGroupId, + @QueryParam("protocol") String protocol, @QueryParam("startport") int startPort, + @QueryParam("endport") int endPort, + @BinderParam(BindCIDRsToCommaDelimitedQueryParam.class) Iterable cidrList, + AccountInDomainOptions... options); + + /** + * @see SecurityGroupClient#authorizeIngressPortsToSecurityGroups + */ + @GET + @QueryParams(keys = "command", values = "authorizeSecurityGroupIngress") + @Unwrap(depth = 2) + @Consumes(MediaType.APPLICATION_JSON) + ListenableFuture authorizeIngressPortsToSecurityGroups( + @QueryParam("securitygroupid") long securityGroupId, + @QueryParam("protocol") String protocol, + @QueryParam("startport") int startPort, + @QueryParam("endport") int endPort, + @BinderParam(BindAccountSecurityGroupPairsToIndexedQueryParams.class) Multimap accountToGroup, + AccountInDomainOptions... options); + + /** + * @see SecurityGroupClient#authorizeIngressICMPToCIDRs + */ + @GET + @QueryParams(keys = { "command", "protocol" }, values = { "authorizeSecurityGroupIngress", "ICMP" }) + @Unwrap(depth = 2) + @Consumes(MediaType.APPLICATION_JSON) + ListenableFuture authorizeIngressICMPToCIDRs(@QueryParam("securitygroupid") long securityGroupId, + @QueryParam("icmpcode") int ICMPCode, @QueryParam("icmptype") int ICMPType, + @BinderParam(BindCIDRsToCommaDelimitedQueryParam.class) Iterable cidrList, + AccountInDomainOptions... options); + + /** + * @see SecurityGroupClient#authorizeIngressICMPToSecurityGroups + */ + @GET + @QueryParams(keys = { "command", "protocol" }, values = { "authorizeSecurityGroupIngress", "ICMP" }) + @Unwrap(depth = 2) + @Consumes(MediaType.APPLICATION_JSON) + ListenableFuture authorizeIngressICMPToSecurityGroups( + @QueryParam("securitygroupid") long securityGroupId, + @QueryParam("icmpcode") int ICMPCode, + @QueryParam("icmptype") int ICMPType, + @BinderParam(BindAccountSecurityGroupPairsToIndexedQueryParams.class) Multimap accountToGroup, + AccountInDomainOptions... options); + + /** + * @see SecurityGroupClient#revokeIngressRule + */ + @GET + @QueryParams(keys = "command", values = "revokeSecurityGroupIngress") + @ExceptionParser(ReturnVoidOnNotFoundOr404.class) + @Unwrap(depth = 2) + @Consumes(MediaType.APPLICATION_JSON) + ListenableFuture revokeIngressRule(@QueryParam("id") long id, AccountInDomainOptions... options); + /** * @see SecurityGroupClient#deleteSecurityGroup */ diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/SecurityGroupClient.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/SecurityGroupClient.java index 9569b4a0a6..0860ae75a5 100644 --- a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/SecurityGroupClient.java +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/SecurityGroupClient.java @@ -23,9 +23,12 @@ import java.util.Set; import java.util.concurrent.TimeUnit; import org.jclouds.cloudstack.domain.SecurityGroup; +import org.jclouds.cloudstack.options.AccountInDomainOptions; import org.jclouds.cloudstack.options.ListSecurityGroupsOptions; import org.jclouds.concurrent.Timeout; +import com.google.common.collect.Multimap; + /** * Provides synchronous access to CloudStack security group features. *

@@ -45,6 +48,82 @@ public interface SecurityGroupClient { */ Set listSecurityGroups(ListSecurityGroupsOptions... options); + /** + * Authorizes a particular TCP or UDP ingress rule for this security group + * + * @param securityGroupId + * The ID of the security group + * @param protocol + * tcp or udp + * @param startPort + * start port for this ingress rule + * @param endPort + * end port for this ingress rule + * @param cidrList + * the cidr list associated + * @return response relating to the creation of this ingress rule + */ + long authorizeIngressPortsToCIDRs(long securityGroupId, String protocol, int startPort, int endPort, + Iterable cidrList, AccountInDomainOptions... options); + + /** + * Authorizes a particular TCP or UDP ingress rule for this security group + * + * @param securityGroupId + * The ID of the security group + * @param protocol + * tcp or udp + * @param startPort + * start port for this ingress rule + * @param endPort + * end port for this ingress rule + * @param accountToGroup + * mapping of account names to security groups you wish to authorize + * @return response relating to the creation of this ingress rule + */ + long authorizeIngressPortsToSecurityGroups(long securityGroupId, String protocol, int startPort, + int endPort, Multimap accountToGroup, AccountInDomainOptions... options); + + /** + * Authorizes a particular ICMP ingress rule for this security group + * + * @param securityGroupId + * The ID of the security group + * @param ICMPCode + * type of the icmp message being sent + * @param ICMPType + * error code for this icmp message + * @param cidrList + * the cidr list associated + * @return response relating to the creation of this ingress rule + */ + long authorizeIngressICMPToCIDRs(long securityGroupId, int ICMPCode, int ICMPType, + Iterable cidrList, AccountInDomainOptions... options); + + /** + * Authorizes a particular ICMP ingress rule for this security group + * + * @param securityGroupId + * The ID of the security group + * @param ICMPCode + * type of the icmp message being sent + * @param ICMPType + * error code for this icmp message + * @param accountToGroup + * mapping of account names to security groups you wish to authorize + * @return response relating to the creation of this ingress rule + */ + long authorizeIngressICMPToSecurityGroups(long securityGroupId, int ICMPCode, int ICMPType, + Multimap accountToGroup, AccountInDomainOptions... options); + + /** + * Deletes a particular ingress rule from this security group + * + * @param id The ID of the ingress rule + * @param options scope of the rule. + */ + long revokeIngressRule(long id, AccountInDomainOptions... options);; + /** * get a specific security group by id * diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/TemplateAsyncClient.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/TemplateAsyncClient.java index b26b8a61d9..cc0ba9428a 100644 --- a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/TemplateAsyncClient.java +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/TemplateAsyncClient.java @@ -78,6 +78,6 @@ public interface TemplateAsyncClient { @Unwrap(depth = 3, edgeCollection = Set.class) @Consumes(MediaType.APPLICATION_JSON) @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture