Merge pull request #339 from richardcloudsoft/cs-vlan

Implement the Cloudstack "Vlan" API
This commit is contained in:
Andrei Savu 2012-01-27 16:08:07 -08:00
commit bf02dd918b
15 changed files with 1357 additions and 0 deletions

View File

@ -30,6 +30,7 @@ import org.jclouds.cloudstack.features.GlobalPodAsyncClient;
import org.jclouds.cloudstack.features.GlobalStoragePoolAsyncClient;
import org.jclouds.cloudstack.features.GlobalUsageAsyncClient;
import org.jclouds.cloudstack.features.GlobalUserAsyncClient;
import org.jclouds.cloudstack.features.GlobalVlanAsyncClient;
import org.jclouds.cloudstack.features.GlobalZoneAsyncClient;
import org.jclouds.rest.annotations.Delegate;
@ -122,4 +123,10 @@ public interface CloudStackGlobalAsyncClient extends CloudStackDomainAsyncClient
*/
@Delegate
GlobalPodAsyncClient getPodClient();
/**
* Provides asynchronous access to Vlan
*/
@Delegate
GlobalVlanAsyncClient getVlanClient();
}

View File

@ -31,6 +31,7 @@ import org.jclouds.cloudstack.features.GlobalPodClient;
import org.jclouds.cloudstack.features.GlobalStoragePoolClient;
import org.jclouds.cloudstack.features.GlobalUsageClient;
import org.jclouds.cloudstack.features.GlobalUserClient;
import org.jclouds.cloudstack.features.GlobalVlanClient;
import org.jclouds.cloudstack.features.GlobalZoneClient;
import org.jclouds.concurrent.Timeout;
import org.jclouds.rest.annotations.Delegate;
@ -125,4 +126,10 @@ public interface CloudStackGlobalClient extends CloudStackDomainClient {
*/
@Delegate
GlobalPodClient getPodClient();
/**
* Provides synchronous access to Vlan
*/
@Delegate
GlobalVlanClient getVlanClient();
}

View File

@ -72,6 +72,8 @@ import org.jclouds.cloudstack.features.GlobalUsageAsyncClient;
import org.jclouds.cloudstack.features.GlobalUsageClient;
import org.jclouds.cloudstack.features.GlobalUserAsyncClient;
import org.jclouds.cloudstack.features.GlobalUserClient;
import org.jclouds.cloudstack.features.GlobalVlanAsyncClient;
import org.jclouds.cloudstack.features.GlobalVlanClient;
import org.jclouds.cloudstack.features.GlobalZoneAsyncClient;
import org.jclouds.cloudstack.features.GlobalZoneClient;
import org.jclouds.cloudstack.features.GuestOSAsyncClient;
@ -172,6 +174,7 @@ public class CloudStackRestClientModule extends RestClientModule<CloudStackClien
.put(GlobalStoragePoolClient.class, GlobalStoragePoolAsyncClient.class)//
.put(GlobalUsageClient.class, GlobalUsageAsyncClient.class)//
.put(GlobalPodClient.class, GlobalPodAsyncClient.class)//
.put(GlobalVlanClient.class, GlobalVlanAsyncClient.class)//
.build();
@Override

View File

@ -0,0 +1,305 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.cloudstack.domain;
import com.google.gson.annotations.SerializedName;
/**
* Represents the data object used in CloudStack's "Vlan" API.
*
* @author Richard Downer
*/
public class VlanIPRange implements Comparable<VlanIPRange> {
public static Builder builder() {
return new Builder();
}
public static class Builder {
private long id;
private String description;
private boolean forVirtualNetwork;
private long zoneId;
private String vlan;
private String account;
private long domainId;
private String domain;
private long podId;
private String podName;
private String gateway;
private String netmask;
private String startIP;
private String endIP;
private long networkId;
public Builder id(long id) {
this.id = id;
return this;
}
public Builder description(String description) {
this.description = description;
return this;
}
public Builder forVirtualNetwork(boolean forVirtualNetwork) {
this.forVirtualNetwork = forVirtualNetwork;
return this;
}
public Builder zoneId(long zoneId) {
this.zoneId = zoneId;
return this;
}
public Builder vlan(long vlan) {
this.vlan = vlan+"";
return this;
}
public Builder vlan(String vlan) {
this.vlan = vlan;
return this;
}
public Builder account(String account) {
this.account = account;
return this;
}
public Builder domainId(long domainId) {
this.domainId = domainId;
return this;
}
public Builder domain(String domain) {
this.domain = domain;
return this;
}
public Builder podId(long podId) {
this.podId = podId;
return this;
}
public Builder podName(String podName) {
this.podName = podName;
return this;
}
public Builder gateway(String gateway) {
this.gateway = gateway;
return this;
}
public Builder netmask(String netmask) {
this.netmask = netmask;
return this;
}
public Builder startIP(String startIP) {
this.startIP = startIP;
return this;
}
public Builder endIP(String endIP) {
this.endIP = endIP;
return this;
}
public Builder networkId(long networkId) {
this.networkId = networkId;
return this;
}
public VlanIPRange build() {
return new VlanIPRange(id, description, forVirtualNetwork, zoneId, vlan, account, domainId, domain, podId, podName, gateway, netmask, startIP, endIP, networkId);
}
}
private long id;
private String description;
@SerializedName("forvirtualnetwork") private boolean forVirtualNetwork;
@SerializedName("zoneid") private long zoneId;
private String vlan;
private String account;
@SerializedName("domainid") private long domainId;
private String domain;
@SerializedName("podid") private long podId;
@SerializedName("podname") private String podName;
private String gateway;
private String netmask;
@SerializedName("startip") private String startIP;
@SerializedName("endip") private String endIP;
@SerializedName("networkid") private long networkId;
/* just for the deserializer */
VlanIPRange() {}
public VlanIPRange(long id, String description, boolean forVirtualNetwork, long zoneId, String vlan, String account, long domainId, String domain, long podId, String podName, String gateway, String netmask, String startIP, String endIP, long networkId) {
this.id = id;
this.description = description;
this.forVirtualNetwork = forVirtualNetwork;
this.zoneId = zoneId;
this.vlan = vlan;
this.account = account;
this.domainId = domainId;
this.domain = domain;
this.podId = podId;
this.podName = podName;
this.gateway = gateway;
this.netmask = netmask;
this.startIP = startIP;
this.endIP = endIP;
this.networkId = networkId;
}
public long getId() {
return id;
}
public String getDescription() {
return description;
}
public boolean isForVirtualNetwork() {
return forVirtualNetwork;
}
public long getZoneId() {
return zoneId;
}
public String getVlan() {
return vlan;
}
public String getAccount() {
return account;
}
public long getDomainId() {
return domainId;
}
public String getDomain() {
return domain;
}
public long getPodId() {
return podId;
}
public String getPodName() {
return podName;
}
public String getGateway() {
return gateway;
}
public String getNetmask() {
return netmask;
}
public String getStartIP() {
return startIP;
}
public String getEndIP() {
return endIP;
}
public long getNetworkId() {
return networkId;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
VlanIPRange that = (VlanIPRange) o;
if (domainId != that.domainId) return false;
if (forVirtualNetwork != that.forVirtualNetwork) return false;
if (id != that.id) return false;
if (networkId != that.networkId) return false;
if (podId != that.podId) return false;
if (zoneId != that.zoneId) return false;
if (account != null ? !account.equals(that.account) : that.account != null) return false;
if (description != null ? !description.equals(that.description) : that.description != null) return false;
if (domain != null ? !domain.equals(that.domain) : that.domain != null) return false;
if (endIP != null ? !endIP.equals(that.endIP) : that.endIP != null) return false;
if (gateway != null ? !gateway.equals(that.gateway) : that.gateway != null) return false;
if (netmask != null ? !netmask.equals(that.netmask) : that.netmask != null) return false;
if (podName != null ? !podName.equals(that.podName) : that.podName != null) return false;
if (startIP != null ? !startIP.equals(that.startIP) : that.startIP != null) return false;
if (vlan != null ? !vlan.equals(that.vlan) : that.vlan != null) return false;
return true;
}
@Override
public int hashCode() {
int result = (int) (id ^ (id >>> 32));
result = 31 * result + (description != null ? description.hashCode() : 0);
result = 31 * result + (forVirtualNetwork ? 1 : 0);
result = 31 * result + (int) (zoneId ^ (zoneId >>> 32));
result = 31 * result + (vlan != null ? vlan.hashCode() : 0);
result = 31 * result + (account != null ? account.hashCode() : 0);
result = 31 * result + (int) (domainId ^ (domainId >>> 32));
result = 31 * result + (domain != null ? domain.hashCode() : 0);
result = 31 * result + (int) (podId ^ (podId >>> 32));
result = 31 * result + (podName != null ? podName.hashCode() : 0);
result = 31 * result + (gateway != null ? gateway.hashCode() : 0);
result = 31 * result + (netmask != null ? netmask.hashCode() : 0);
result = 31 * result + (startIP != null ? startIP.hashCode() : 0);
result = 31 * result + (endIP != null ? endIP.hashCode() : 0);
result = 31 * result + (int) (networkId ^ (networkId >>> 32));
return result;
}
@Override
public String toString() {
return "VlanIPRange{" +
"id=" + id +
", description='" + description + '\'' +
", forVirtualNetwork=" + forVirtualNetwork +
", zoneId=" + zoneId +
", vlan='" + vlan + '\'' +
", account='" + account + '\'' +
", domainId=" + domainId +
", domain='" + domain + '\'' +
", podId=" + podId +
", podName='" + podName + '\'' +
", gateway='" + gateway + '\'' +
", netmask='" + netmask + '\'' +
", startIP='" + startIP + '\'' +
", endIP='" + endIP + '\'' +
", networkId=" + networkId +
'}';
}
@Override
public int compareTo(VlanIPRange other) {
return Long.valueOf(this.id).compareTo(other.id);
}
}

View File

@ -0,0 +1,104 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.cloudstack.features;
import com.google.common.util.concurrent.ListenableFuture;
import org.jclouds.cloudstack.domain.VlanIPRange;
import org.jclouds.cloudstack.filters.QuerySigner;
import org.jclouds.cloudstack.options.CreateVlanIPRangeOptions;
import org.jclouds.cloudstack.options.ListVlanIPRangesOptions;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.OnlyElement;
import org.jclouds.rest.annotations.QueryParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import java.util.Set;
/**
* Provides asynchronous access to cloudstack via their REST API.
* <p/>
*
* @see org.jclouds.cloudstack.features.GlobalVlanClient
* @see <a href="http://download.cloud.com/releases/2.2.0/api_2.2.12/TOC_Global_Admin.html" />
* @author Richard Downer
*/
@RequestFilters(QuerySigner.class)
@QueryParams(keys = "response", values = "json")
public interface GlobalVlanAsyncClient {
/**
* Get the details of an IP range by its id.
* @param id the required IP range.
* @return the requested IP range.
*/
@GET
@QueryParams(keys = "command", values = "listVlanIpRanges")
@SelectJson("vlaniprange")
@OnlyElement
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<VlanIPRange> getVlanIPRange(@QueryParam("id") long id);
/**
* Lists all VLAN IP ranges.
*
* @param options optional arguments.
* @return the list of IP ranges that match the criteria.
*/
@GET
@QueryParams(keys = "command", values = "listVlanIpRanges")
@SelectJson("vlaniprange")
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<Set<VlanIPRange>> listVlanIPRanges(ListVlanIPRangesOptions... options);
/**
* Creates a VLAN IP range.
*
* @param startIP the beginning IP address in the VLAN IP range
* @param endIP the ending IP address in the VLAN IP range
* @param options optional arguments
* @return the newly-create IP range.
*/
@GET
@QueryParams(keys = "command", values = "createVlanIpRange")
@SelectJson("vlaniprange")
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<VlanIPRange> createVlanIPRange(@QueryParam("startip") String startIP, @QueryParam("endip") String endIP, CreateVlanIPRangeOptions... options);
/**
* Deletes a VLAN IP range.
* @param rangeId the id of the VLAN IP range
* @return void
*/
@GET
@QueryParams(keys = "command", values = "deleteVlanIpRange")
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
ListenableFuture<Void> deleteVlanIPRange(@QueryParam("id") long rangeId);
}

View File

@ -0,0 +1,70 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.cloudstack.features;
import org.jclouds.cloudstack.domain.VlanIPRange;
import org.jclouds.cloudstack.options.CreateVlanIPRangeOptions;
import org.jclouds.cloudstack.options.ListVlanIPRangesOptions;
import org.jclouds.concurrent.Timeout;
import java.util.Set;
import java.util.concurrent.TimeUnit;
/**
* Provides synchronous access to CloudStack VLAN features.
* <p/>
*
* @see GlobalOfferingAsyncClient
* @see <a href="http://download.cloud.com/releases/2.2.0/api_2.2.12/TOC_Global_Admin.html" />
* @author Richard Downer
*/
@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS)
public interface GlobalVlanClient {
/**
* Get the details of an IP range by its id.
* @param id the required IP range.
* @return the requested IP range.
*/
VlanIPRange getVlanIPRange(long id);
/**
* Lists all VLAN IP ranges.
*
* @param options optional arguments.
* @return the list of IP ranges that match the criteria.
*/
Set<VlanIPRange> listVlanIPRanges(ListVlanIPRangesOptions... options);
/**
* Creates a VLAN IP range.
*
* @param startIP the beginning IP address in the VLAN IP range
* @param endIP the ending IP address in the VLAN IP range
* @param options optional arguments
* @return the newly-create IP range.
*/
VlanIPRange createVlanIPRange(String startIP, String endIP, CreateVlanIPRangeOptions... options);
/**
* Deletes a VLAN IP range.
* @param rangeId the id of the VLAN IP range
*/
void deleteVlanIPRange(long rangeId);
}

View File

@ -0,0 +1,123 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.cloudstack.options;
import com.google.common.collect.ImmutableSet;
/**
* Options to the createVlanIPRange API call.
*
* @author Richard Downer
*/
public class CreateVlanIPRangeOptions extends AccountInDomainOptions {
public static class Builder {
public static CreateVlanIPRangeOptions accountInDomain(String account, long domain) {
return new CreateVlanIPRangeOptions().accountInDomain(account, domain);
}
public static CreateVlanIPRangeOptions domainId(long domainId) {
return new CreateVlanIPRangeOptions().domainId(domainId);
}
public static CreateVlanIPRangeOptions forVirtualNetwork(boolean forVirtualNetwork) {
return new CreateVlanIPRangeOptions().forVirtualNetwork(forVirtualNetwork);
}
public static CreateVlanIPRangeOptions zoneId(long zoneId) {
return new CreateVlanIPRangeOptions().zoneId(zoneId);
}
public static CreateVlanIPRangeOptions vlan(long vlan) {
return new CreateVlanIPRangeOptions().vlan(vlan);
}
public static CreateVlanIPRangeOptions vlan(String vlan) {
return new CreateVlanIPRangeOptions().vlan(vlan);
}
public static CreateVlanIPRangeOptions podId(long podId) {
return new CreateVlanIPRangeOptions().podId(podId);
}
public static CreateVlanIPRangeOptions gateway(String gateway) {
return new CreateVlanIPRangeOptions().gateway(gateway);
}
public static CreateVlanIPRangeOptions netmask(String netmask) {
return new CreateVlanIPRangeOptions().netmask(netmask);
}
public static CreateVlanIPRangeOptions networkId(long networkId) {
return new CreateVlanIPRangeOptions().networkId(networkId);
}
}
@Override
public CreateVlanIPRangeOptions accountInDomain(String account, long domain) {
return (CreateVlanIPRangeOptions) super.accountInDomain(account, domain);
}
@Override
public CreateVlanIPRangeOptions domainId(long domainId) {
return (CreateVlanIPRangeOptions) super.domainId(domainId);
}
public CreateVlanIPRangeOptions forVirtualNetwork(boolean forVirtualNetwork) {
this.queryParameters.replaceValues("forvirtualnetwork", ImmutableSet.of(forVirtualNetwork+""));
return this;
}
public CreateVlanIPRangeOptions zoneId(long zoneId) {
this.queryParameters.replaceValues("zoneid", ImmutableSet.of(zoneId+""));
return this;
}
public CreateVlanIPRangeOptions vlan(long vlan) {
this.queryParameters.replaceValues("vlan", ImmutableSet.of(vlan+""));
return this;
}
public CreateVlanIPRangeOptions vlan(String vlan) {
this.queryParameters.replaceValues("vlan", ImmutableSet.of(vlan));
return this;
}
public CreateVlanIPRangeOptions podId(long podId) {
this.queryParameters.replaceValues("podid", ImmutableSet.of(podId+""));
return this;
}
public CreateVlanIPRangeOptions gateway(String gateway) {
this.queryParameters.replaceValues("gateway", ImmutableSet.of(gateway));
return this;
}
public CreateVlanIPRangeOptions netmask(String netmask) {
this.queryParameters.replaceValues("netmask", ImmutableSet.of(netmask));
return this;
}
public CreateVlanIPRangeOptions networkId(long networkId) {
this.queryParameters.replaceValues("networkid", ImmutableSet.of(networkId+""));
return this;
}
}

View File

@ -0,0 +1,122 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.cloudstack.options;
import com.google.common.collect.ImmutableSet;
/**
* Options to the listVLANIPRanges() API call
*
* @author Richard Downer
*/
public class ListVlanIPRangesOptions extends AccountInDomainOptions {
public static class Builder {
public static ListVlanIPRangesOptions accountInDomain(String account, long domainId) {
return new ListVlanIPRangesOptions().accountInDomain(account, domainId);
}
public static ListVlanIPRangesOptions domainId(long domainId) {
return new ListVlanIPRangesOptions().domainId(domainId);
}
public static ListVlanIPRangesOptions forVirtualNetwork(boolean forVirtualNetwork) {
return new ListVlanIPRangesOptions().forVirtualNetwork(forVirtualNetwork);
}
public static ListVlanIPRangesOptions id(long id) {
return new ListVlanIPRangesOptions().id(id);
}
public static ListVlanIPRangesOptions keyword(String keyword) {
return new ListVlanIPRangesOptions().keyword(keyword);
}
public static ListVlanIPRangesOptions networkId(long networkId) {
return new ListVlanIPRangesOptions().networkId(networkId);
}
public static ListVlanIPRangesOptions podId(long podId) {
return new ListVlanIPRangesOptions().podId(podId);
}
public static ListVlanIPRangesOptions vlan(String vlan) {
return new ListVlanIPRangesOptions().vlan(vlan);
}
public static ListVlanIPRangesOptions vlan(long vlan) {
return new ListVlanIPRangesOptions().vlan(vlan+"");
}
public static ListVlanIPRangesOptions zoneId(long zoneId) {
return new ListVlanIPRangesOptions().zoneId(zoneId);
}
}
@Override
public ListVlanIPRangesOptions accountInDomain(String account, long domainId) {
return (ListVlanIPRangesOptions) super.accountInDomain(account, domainId);
}
@Override
public ListVlanIPRangesOptions domainId(long domainId) {
return (ListVlanIPRangesOptions) super.domainId(domainId);
}
public ListVlanIPRangesOptions forVirtualNetwork(boolean forVirtualNetwork) {
this.queryParameters.replaceValues("forvirtualnetwork", ImmutableSet.of(forVirtualNetwork+""));
return this;
}
public ListVlanIPRangesOptions id(long id) {
this.queryParameters.replaceValues("id", ImmutableSet.of(id+""));
return this;
}
public ListVlanIPRangesOptions keyword(String keyword) {
this.queryParameters.replaceValues("keyword", ImmutableSet.of(keyword));
return this;
}
public ListVlanIPRangesOptions networkId(long networkId) {
this.queryParameters.replaceValues("networkid", ImmutableSet.of(networkId+""));
return this;
}
public ListVlanIPRangesOptions podId(long podId) {
this.queryParameters.replaceValues("podid", ImmutableSet.of(podId+""));
return this;
}
public ListVlanIPRangesOptions vlan(String vlan) {
this.queryParameters.replaceValues("vlan", ImmutableSet.of(vlan));
return this;
}
public ListVlanIPRangesOptions vlan(long vlan) {
this.queryParameters.replaceValues("vlan", ImmutableSet.of(vlan+""));
return this;
}
public ListVlanIPRangesOptions zoneId(long zoneId) {
this.queryParameters.replaceValues("zoneid", ImmutableSet.of(zoneId+""));
return this;
}
}

View File

@ -0,0 +1,184 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.cloudstack.features;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableSet;
import org.jclouds.cloudstack.CloudStackContext;
import org.jclouds.cloudstack.domain.VlanIPRange;
import org.jclouds.cloudstack.options.CreateVlanIPRangeOptions;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.testng.annotations.Test;
import java.net.URI;
import static junit.framework.Assert.assertEquals;
/**
* Test the CloudStack VlanClient
*
* @author Richard Downer
*/
@Test(groups = "unit", testName = "GlobalVlanClientExpectTest")
public class GlobalVlanClientExpectTest extends BaseCloudStackRestClientExpectTest<GlobalVlanClient> {
public void testListVlanIpRangesWhenResponseIs2xx() {
GlobalVlanClient client = requestSendsResponse(
HttpRequest.builder()
.method("GET")
.endpoint(
URI.create("http://localhost:8080/client/api?response=json&" +
"command=listVlanIpRanges&apiKey=identity&signature=mS38BVfJjz1Y8bk0EdjJTeusJ0w%3D"))
.headers(
ImmutableMultimap.<String, String>builder()
.put("Accept", "application/json")
.build())
.build(),
HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResource("/listvlaniprangesresponse.json"))
.build());
VlanIPRange range1 = VlanIPRange.builder()
.id(1)
.forVirtualNetwork(true)
.zoneId(1)
.vlan(127)
.account("system")
.domainId(1)
.domain("ROOT")
.gateway("10.27.27.254")
.netmask("255.255.255.0")
.startIP("10.27.27.50")
.endIP("10.27.27.100")
.networkId(200)
.build();
VlanIPRange range2 = VlanIPRange.builder()
.id(2)
.forVirtualNetwork(false)
.zoneId(2)
.vlan("untagged")
.account("system")
.domainId(1)
.domain("ROOT")
.podId(2)
.podName("Dev Pod 2")
.gateway("10.22.22.254")
.netmask("255.255.255.0")
.startIP("10.22.22.51")
.endIP("10.22.22.100")
.networkId(209)
.build();
assertEquals(client.listVlanIPRanges(), ImmutableSet.of(range1, range2));
}
public void testListVlanIpRangesWhenResponseIs404() {
GlobalVlanClient client = requestSendsResponse(
HttpRequest.builder()
.method("GET")
.endpoint(
URI.create("http://localhost:8080/client/api?response=json&" +
"command=listVlanIpRanges&apiKey=identity&signature=mS38BVfJjz1Y8bk0EdjJTeusJ0w%3D"))
.headers(
ImmutableMultimap.<String, String>builder()
.put("Accept", "application/json")
.build())
.build(),
HttpResponse.builder()
.statusCode(404)
.build());
assertEquals(client.listVlanIPRanges(), ImmutableSet.of());
}
public void testCreateVlanIpRangeWhenResponseIs2xx() {
GlobalVlanClient client = requestSendsResponse(
HttpRequest.builder()
.method("GET")
.endpoint(
URI.create("http://localhost:8080/client/api?response=json&" +
"command=createVlanIpRange&startip=10.22.22.51&endip=10.22.22.100&forvirtualnetwork=false&zoneid=2&vlan=untagged&account=system&domainid=1&podid=2&gateway=10.22.22.254&netmask=255.255.255.0&networkid=209&apiKey=identity&signature=XgDjPYAQNLMVCuSMGRA6QjV8mOY%3D"))
.headers(
ImmutableMultimap.<String, String>builder()
.put("Accept", "application/json")
.build())
.build(),
HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResource("/createvlaniprangeresponse.json"))
.build());
VlanIPRange actual = client.createVlanIPRange("10.22.22.51", "10.22.22.100", new CreateVlanIPRangeOptions()
.forVirtualNetwork(false)
.zoneId(2)
.vlan("untagged")
.accountInDomain("system", 1)
.podId(2)
.gateway("10.22.22.254")
.netmask("255.255.255.0")
.networkId(209));
VlanIPRange expected = VlanIPRange.builder()
.id(2)
.forVirtualNetwork(false)
.zoneId(2)
.vlan("untagged")
.account("system")
.domainId(1)
.domain("ROOT")
.podId(2)
.podName("Dev Pod 2")
.gateway("10.22.22.254")
.netmask("255.255.255.0")
.startIP("10.22.22.51")
.endIP("10.22.22.100")
.networkId(209)
.build();
assertEquals(actual, expected);
}
public void testDeleteVlanIpRangeWhenResponseIs2xx() {
GlobalVlanClient client = requestSendsResponse(
HttpRequest.builder()
.method("GET")
.endpoint(
URI.create("http://localhost:8080/client/api?response=json&" +
"command=deleteVlanIpRange&id=1&apiKey=identity&signature=tTBbpdCndgHXdR397fbbJaN1RZU%3D"))
.headers(
ImmutableMultimap.<String, String>builder()
.put("Accept", "application/json")
.build())
.build(),
HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResource("/createvlaniprangeresponse.json"))
.build());
client.deleteVlanIPRange(1);
}
@Override
protected GlobalVlanClient clientFrom(CloudStackContext context) {
return context.getGlobalContext().getApi().getVlanClient();
}
}

View File

@ -0,0 +1,100 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.cloudstack.features;
import com.google.common.base.Strings;
import com.google.common.collect.Iterables;
import org.jclouds.cloudstack.domain.Network;
import org.jclouds.cloudstack.domain.NetworkOffering;
import org.jclouds.cloudstack.domain.VlanIPRange;
import org.jclouds.cloudstack.domain.Zone;
import org.jclouds.cloudstack.options.CreateVlanIPRangeOptions;
import org.jclouds.cloudstack.options.ListVlanIPRangesOptions;
import org.jclouds.cloudstack.predicates.NetworkOfferingPredicates;
import org.jclouds.cloudstack.predicates.ZonePredicates;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
import java.util.Set;
import static com.google.common.collect.Iterables.find;
import static org.testng.Assert.*;
/**
* Tests behavior of {@code GlobalVlanClient}
*
* @author Richard Downer
*/
@Test(groups = "live", singleThreaded = true, testName = "GlobalVlanClientLiveTest")
public class GlobalVlanClientLiveTest extends BaseCloudStackClientLiveTest {
private Network network;
private VlanIPRange range;
public void testListVlanIPRanges() throws Exception {
Set<VlanIPRange> response = globalAdminClient.getVlanClient().listVlanIPRanges();
assert null != response;
long rangeCount = response.size();
assertTrue(rangeCount >= 0);
for (VlanIPRange range : response) {
VlanIPRange newDetails = Iterables.getOnlyElement(globalAdminClient.getVlanClient().listVlanIPRanges(
ListVlanIPRangesOptions.Builder.id(range.getId())));
assertEquals(range, newDetails);
assertEquals(range, globalAdminClient.getVlanClient().getVlanIPRange(range.getId()));
assertFalse(range.getId() <= 0);
assertFalse(range.getZoneId() <= 0);
assertFalse(Strings.isNullOrEmpty(range.getVlan()));
assertFalse(Strings.isNullOrEmpty(range.getAccount()));
assertFalse(range.getDomainId() <= 0);
assertFalse(Strings.isNullOrEmpty(range.getDomain()));
assertFalse(Strings.isNullOrEmpty(range.getGateway()));
assertFalse(Strings.isNullOrEmpty(range.getNetmask()));
assertFalse(Strings.isNullOrEmpty(range.getStartIP()));
assertFalse(Strings.isNullOrEmpty(range.getEndIP()));
assertFalse(range.getNetworkId() <= 0);
}
}
public void testCreateVlanIPRange() {
Zone zone = Iterables.find(client.getZoneClient().listZones(), ZonePredicates.supportsAdvancedNetworks());
NetworkOffering offering = find(client.getOfferingClient().listNetworkOfferings(), NetworkOfferingPredicates.supportsGuestVirtualNetworks());
network = client.getNetworkClient().createNetworkInZone(zone.getId(), offering.getId(), "net-"+prefix, "jclouds test "+prefix);
range = globalAdminClient.getVlanClient().createVlanIPRange("172.19.1.1", "172.19.1.199", CreateVlanIPRangeOptions.Builder
.accountInDomain(user.getAccount(), user.getDomainId())
.forVirtualNetwork(true)
.vlan(1001)
.networkId(network.getId())
);
}
@AfterClass
public void testFixtureTearDown() {
if (range != null) {
globalAdminClient.getVlanClient().deleteVlanIPRange(range.getId());
range = null;
}
if (network != null) {
client.getNetworkClient().deleteNetwork(network.getId());
network = null;
}
}
}

View File

@ -0,0 +1,127 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.cloudstack.options;
import com.google.common.collect.ImmutableSet;
import org.testng.annotations.Test;
import static org.jclouds.cloudstack.options.CreateVlanIPRangeOptions.Builder.*;
import static org.testng.Assert.assertEquals;
/**
* Tests behavior of {@code CreateVlanIPRangeOptions}
*
* @author Richard Downer
*/
@Test(groups = "unit")
public class CreateVlanIPRangeOptionsTest {
public void testAccountInDomain() {
CreateVlanIPRangeOptions options = new CreateVlanIPRangeOptions().accountInDomain("fred", 6);
assertEquals(ImmutableSet.of("fred"), options.buildQueryParameters().get("account"));
assertEquals(ImmutableSet.of("6"), options.buildQueryParameters().get("domainid"));
}
public void testAccountInDomainStatic() {
CreateVlanIPRangeOptions options = accountInDomain("fred", 6);
assertEquals(ImmutableSet.of("fred"), options.buildQueryParameters().get("account"));
assertEquals(ImmutableSet.of("6"), options.buildQueryParameters().get("domainid"));
}
public void testDomainId() {
CreateVlanIPRangeOptions options = new CreateVlanIPRangeOptions().domainId(6);
assertEquals(ImmutableSet.of("6"), options.buildQueryParameters().get("domainid"));
}
public void testDomainIdStatic() {
CreateVlanIPRangeOptions options = domainId(6);
assertEquals(ImmutableSet.of("6"), options.buildQueryParameters().get("domainid"));
}
public void testForVirtualNetwork() {
CreateVlanIPRangeOptions options = new CreateVlanIPRangeOptions().forVirtualNetwork(true);
assertEquals(ImmutableSet.of("true"), options.buildQueryParameters().get("forvirtualnetwork"));
}
public void testForVirtualNetworkStatic() {
CreateVlanIPRangeOptions options = forVirtualNetwork(true);
assertEquals(ImmutableSet.of("true"), options.buildQueryParameters().get("forvirtualnetwork"));
}
public void testGateway() {
CreateVlanIPRangeOptions options = new CreateVlanIPRangeOptions().gateway("192.168.42.24");
assertEquals(ImmutableSet.of("192.168.42.24"), options.buildQueryParameters().get("gateway"));
}
public void testGatewayStatic() {
CreateVlanIPRangeOptions options = gateway("192.168.42.24");
assertEquals(ImmutableSet.of("192.168.42.24"), options.buildQueryParameters().get("gateway"));
}
public void testNetmask() {
CreateVlanIPRangeOptions options = new CreateVlanIPRangeOptions().netmask("255.255.255.240");
assertEquals(ImmutableSet.of("255.255.255.240"), options.buildQueryParameters().get("netmask"));
}
public void testNetmaskStatic() {
CreateVlanIPRangeOptions options = netmask("255.255.255.240");
assertEquals(ImmutableSet.of("255.255.255.240"), options.buildQueryParameters().get("netmask"));
}
public void testNetworkId() {
CreateVlanIPRangeOptions options = new CreateVlanIPRangeOptions().networkId(9);
assertEquals(ImmutableSet.of("9"), options.buildQueryParameters().get("networkid"));
}
public void testNetworkIdStatic() {
CreateVlanIPRangeOptions options = networkId(9);
assertEquals(ImmutableSet.of("9"), options.buildQueryParameters().get("networkid"));
}
public void testPodId() {
CreateVlanIPRangeOptions options = new CreateVlanIPRangeOptions().podId(8);
assertEquals(ImmutableSet.of("8"), options.buildQueryParameters().get("podid"));
}
public void testPodIdStatic() {
CreateVlanIPRangeOptions options = podId(8);
assertEquals(ImmutableSet.of("8"), options.buildQueryParameters().get("podid"));
}
public void testVlan() {
CreateVlanIPRangeOptions options = new CreateVlanIPRangeOptions().vlan(1001);
assertEquals(ImmutableSet.of("1001"), options.buildQueryParameters().get("vlan"));
}
public void testVlanStatic() {
CreateVlanIPRangeOptions options = vlan(1001);
assertEquals(ImmutableSet.of("1001"), options.buildQueryParameters().get("vlan"));
}
public void testZoneId() {
CreateVlanIPRangeOptions options = new CreateVlanIPRangeOptions().zoneId(7);
assertEquals(ImmutableSet.of("7"), options.buildQueryParameters().get("zoneid"));
}
public void testZoneIdStatic() {
CreateVlanIPRangeOptions options = zoneId(7);
assertEquals(ImmutableSet.of("7"), options.buildQueryParameters().get("zoneid"));
}
}

View File

@ -0,0 +1,127 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.cloudstack.options;
import com.google.common.collect.ImmutableList;
import org.testng.annotations.Test;
import static org.jclouds.cloudstack.options.ListVlanIPRangesOptions.Builder.*;
import static org.testng.Assert.assertEquals;
/**
* Tests behavior of {@code ListVlanIPRangesOptions}
*
* @author Richard Downer
*/
@Test(groups = "unit")
public class ListVlanIPRangesOptionsTest {
public void testAccountInDomain() {
ListVlanIPRangesOptions options = new ListVlanIPRangesOptions().accountInDomain("fred", 19);
assertEquals(ImmutableList.of("fred"), options.buildQueryParameters().get("account"));
assertEquals(ImmutableList.of("19"), options.buildQueryParameters().get("domainid"));
}
public void testAccountInDomainStatic() {
ListVlanIPRangesOptions options = accountInDomain("fred", 19);
assertEquals(ImmutableList.of("fred"), options.buildQueryParameters().get("account"));
assertEquals(ImmutableList.of("19"), options.buildQueryParameters().get("domainid"));
}
public void testDomainId() {
ListVlanIPRangesOptions options = new ListVlanIPRangesOptions().domainId(19);
assertEquals(ImmutableList.of("19"), options.buildQueryParameters().get("domainid"));
}
public void testDomainIdStatic() {
ListVlanIPRangesOptions options = domainId(19);
assertEquals(ImmutableList.of("19"), options.buildQueryParameters().get("domainid"));
}
public void testForVirtualNetwork() {
ListVlanIPRangesOptions options = new ListVlanIPRangesOptions().forVirtualNetwork(true);
assertEquals(ImmutableList.of("true"), options.buildQueryParameters().get("forvirtualnetwork"));
}
public void testForVirtualNetworkStatic() {
ListVlanIPRangesOptions options = forVirtualNetwork(true);
assertEquals(ImmutableList.of("true"), options.buildQueryParameters().get("forvirtualnetwork"));
}
public void testId() {
ListVlanIPRangesOptions options = new ListVlanIPRangesOptions().id(6);
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("id"));
}
public void testIdStatic() {
ListVlanIPRangesOptions options = id(6);
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("id"));
}
public void testKeyword() {
ListVlanIPRangesOptions options = new ListVlanIPRangesOptions().keyword("fred");
assertEquals(ImmutableList.of("fred"), options.buildQueryParameters().get("keyword"));
}
public void testKeywordStatic() {
ListVlanIPRangesOptions options = keyword("fred");
assertEquals(ImmutableList.of("fred"), options.buildQueryParameters().get("keyword"));
}
public void testNetworkId() {
ListVlanIPRangesOptions options = new ListVlanIPRangesOptions().networkId(209);
assertEquals(ImmutableList.of("209"), options.buildQueryParameters().get("networkid"));
}
public void testNetworkIdStatic() {
ListVlanIPRangesOptions options = networkId(209);
assertEquals(ImmutableList.of("209"), options.buildQueryParameters().get("networkid"));
}
public void testPodId() {
ListVlanIPRangesOptions options = new ListVlanIPRangesOptions().podId(13);
assertEquals(ImmutableList.of("13"), options.buildQueryParameters().get("podid"));
}
public void testPodIdStatic() {
ListVlanIPRangesOptions options = podId(13);
assertEquals(ImmutableList.of("13"), options.buildQueryParameters().get("podid"));
}
public void testVlan() {
ListVlanIPRangesOptions options = new ListVlanIPRangesOptions().vlan(1001);
assertEquals(ImmutableList.of("1001"), options.buildQueryParameters().get("vlan"));
}
public void testVlanStatic() {
ListVlanIPRangesOptions options = vlan(1001);
assertEquals(ImmutableList.of("1001"), options.buildQueryParameters().get("vlan"));
}
public void testZoneId() {
ListVlanIPRangesOptions options = new ListVlanIPRangesOptions().zoneId(6);
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("zoneid"));
}
public void testZoneIdStatic() {
ListVlanIPRangesOptions options = zoneId(6);
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("zoneid"));
}
}

View File

@ -0,0 +1,76 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.cloudstack.parse;
import com.google.common.collect.ImmutableSet;
import org.jclouds.cloudstack.domain.VlanIPRange;
import org.jclouds.json.BaseSetParserTest;
import org.jclouds.rest.annotations.SelectJson;
import org.testng.annotations.Test;
import java.util.Set;
/**
*
* @author Richard Downer
*/
@Test(groups = "unit")
public class ListVlanIPRangesResponseTest extends BaseSetParserTest<VlanIPRange> {
@Override
public String resource() {
return "/listvlaniprangesresponse.json";
}
@Override
@SelectJson("vlaniprange")
public Set<VlanIPRange> expected() {
VlanIPRange range1 = VlanIPRange.builder()
.id(1)
.forVirtualNetwork(true)
.zoneId(1)
.vlan(127)
.account("system")
.domainId(1)
.domain("ROOT")
.gateway("10.27.27.254")
.netmask("255.255.255.0")
.startIP("10.27.27.50")
.endIP("10.27.27.100")
.networkId(200)
.build();
VlanIPRange range2 = VlanIPRange.builder()
.id(2)
.forVirtualNetwork(false)
.zoneId(2)
.vlan("untagged")
.account("system")
.domainId(1)
.domain("ROOT")
.podId(2)
.podName("Dev Pod 2")
.gateway("10.22.22.254")
.netmask("255.255.255.0")
.startIP("10.22.22.51")
.endIP("10.22.22.100")
.networkId(209)
.build();
return ImmutableSet.of(range1, range2);
}
}

View File

@ -0,0 +1 @@
{ "createvlaniprangeresponse" : { "vlaniprange" : {"id":2,"forvirtualnetwork":false,"zoneid":2,"vlan":"untagged","account":"system","domainid":1,"domain":"ROOT","podid":2,"podname":"Dev Pod 2","gateway":"10.22.22.254","netmask":"255.255.255.0","startip":"10.22.22.51","endip":"10.22.22.100","networkid":209} } }

View File

@ -0,0 +1 @@
{ "listvlaniprangesresponse" : { "count":2 ,"vlaniprange" : [ {"id":1,"forvirtualnetwork":true,"zoneid":1,"vlan":"127","account":"system","domainid":1,"domain":"ROOT","gateway":"10.27.27.254","netmask":"255.255.255.0","startip":"10.27.27.50","endip":"10.27.27.100","networkid":200}, {"id":2,"forvirtualnetwork":false,"zoneid":2,"vlan":"untagged","account":"system","domainid":1,"domain":"ROOT","podid":2,"podname":"Dev Pod 2","gateway":"10.22.22.254","netmask":"255.255.255.0","startip":"10.22.22.51","endip":"10.22.22.100","networkid":209} ] } }