mirror of https://github.com/apache/jclouds.git
Add listVlanIpRanges() and getVlanIpRange()
This commit is contained in:
parent
9ca399049a
commit
b15a258fde
|
@ -18,9 +18,23 @@
|
|||
*/
|
||||
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.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 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.
|
||||
|
@ -34,4 +48,30 @@ import org.jclouds.rest.annotations.RequestFilters;
|
|||
@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);
|
||||
|
||||
}
|
||||
|
|
|
@ -18,8 +18,11 @@
|
|||
*/
|
||||
package org.jclouds.cloudstack.features;
|
||||
|
||||
import org.jclouds.cloudstack.domain.VlanIPRange;
|
||||
import org.jclouds.cloudstack.options.ListVlanIPRangesOptions;
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
|
@ -33,4 +36,19 @@ import java.util.concurrent.TimeUnit;
|
|||
@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);
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -18,9 +18,18 @@
|
|||
*/
|
||||
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.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
|
||||
*
|
||||
|
@ -29,6 +38,76 @@ import org.testng.annotations.Test;
|
|||
@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());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GlobalVlanClient clientFrom(CloudStackContext context) {
|
||||
|
|
|
@ -18,9 +18,19 @@
|
|||
*/
|
||||
package org.jclouds.cloudstack.features;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Iterables;
|
||||
import org.jclouds.cloudstack.domain.VlanIPRange;
|
||||
import org.jclouds.cloudstack.options.ListVlanIPRangesOptions;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code GlobalVlanClient}
|
||||
*
|
||||
|
@ -29,6 +39,30 @@ import org.testng.annotations.Test;
|
|||
@Test(groups = "live", singleThreaded = true, testName = "GlobalVlanClientLiveTest")
|
||||
public class GlobalVlanClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public void testFixtureTearDown() {
|
||||
}
|
||||
|
|
|
@ -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"));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue