mirror of https://github.com/apache/jclouds.git
fixes for latest version of cloudstack relating to network parsing
This commit is contained in:
parent
83cbebe6de
commit
15657dc3c5
|
@ -88,7 +88,7 @@ public interface NetworkAsyncClient {
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@QueryParams(keys = "command", values = "deleteNetwork")
|
@QueryParams(keys = "command", values = "deleteNetwork")
|
||||||
@SelectJson("network")
|
@SelectJson("jobid")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||||
ListenableFuture<Long> deleteNetwork(@QueryParam("id") long id);
|
ListenableFuture<Long> deleteNetwork(@QueryParam("id") long id);
|
||||||
|
|
|
@ -20,7 +20,6 @@ package org.jclouds.cloudstack.options;
|
||||||
|
|
||||||
import org.jclouds.cloudstack.domain.NetworkType;
|
import org.jclouds.cloudstack.domain.NetworkType;
|
||||||
import org.jclouds.cloudstack.domain.TrafficType;
|
import org.jclouds.cloudstack.domain.TrafficType;
|
||||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
|
@ -32,7 +31,7 @@ import com.google.common.collect.ImmutableSet;
|
||||||
* />
|
* />
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class ListNetworksOptions extends BaseHttpRequestOptions {
|
public class ListNetworksOptions extends AccountInDomainOptions {
|
||||||
|
|
||||||
public static final ListNetworksOptions NONE = new ListNetworksOptions();
|
public static final ListNetworksOptions NONE = new ListNetworksOptions();
|
||||||
|
|
||||||
|
@ -81,27 +80,6 @@ public class ListNetworksOptions extends BaseHttpRequestOptions {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param account
|
|
||||||
* account who will own the VLAN. If VLAN is Zone wide, this
|
|
||||||
* parameter should be ommited
|
|
||||||
*/
|
|
||||||
public ListNetworksOptions account(String account) {
|
|
||||||
this.queryParameters.replaceValues("account", ImmutableSet.of(account));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param domainId
|
|
||||||
* domain ID of the account owning a VLAN
|
|
||||||
*/
|
|
||||||
public ListNetworksOptions domainId(long domainId) {
|
|
||||||
this.queryParameters.replaceValues("domainid", ImmutableSet.of(domainId + ""));
|
|
||||||
return this;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param zoneId
|
* @param zoneId
|
||||||
* the Zone ID of the network
|
* the Zone ID of the network
|
||||||
|
@ -121,6 +99,22 @@ public class ListNetworksOptions extends BaseHttpRequestOptions {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ListNetworksOptions accountInDomain(String account, long domain) {
|
||||||
|
return ListNetworksOptions.class.cast(super.accountInDomain(account, domain));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ListNetworksOptions domainId(long domainId) {
|
||||||
|
return ListNetworksOptions.class.cast(super.domainId(domainId));
|
||||||
|
}
|
||||||
|
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
/**
|
/**
|
||||||
* @see ListNetworksOptions#isDefault
|
* @see ListNetworksOptions#isDefault
|
||||||
|
@ -154,22 +148,6 @@ public class ListNetworksOptions extends BaseHttpRequestOptions {
|
||||||
return options.type(type);
|
return options.type(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ListNetworksOptions#domainId
|
|
||||||
*/
|
|
||||||
public static ListNetworksOptions domainId(long id) {
|
|
||||||
ListNetworksOptions options = new ListNetworksOptions();
|
|
||||||
return options.domainId(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ListNetworksOptions#account
|
|
||||||
*/
|
|
||||||
public static ListNetworksOptions account(String account) {
|
|
||||||
ListNetworksOptions options = new ListNetworksOptions();
|
|
||||||
return options.account(account);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ListNetworksOptions#id
|
* @see ListNetworksOptions#id
|
||||||
*/
|
*/
|
||||||
|
@ -193,6 +171,22 @@ public class ListNetworksOptions extends BaseHttpRequestOptions {
|
||||||
ListNetworksOptions options = new ListNetworksOptions();
|
ListNetworksOptions options = new ListNetworksOptions();
|
||||||
return options.trafficType(trafficType);
|
return options.trafficType(trafficType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see ListNetworksOptions#accountInDomain
|
||||||
|
*/
|
||||||
|
public static ListNetworksOptions accountInDomain(String account, long domain) {
|
||||||
|
ListNetworksOptions options = new ListNetworksOptions();
|
||||||
|
return options.accountInDomain(account, domain);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see ListNetworksOptions#domainId
|
||||||
|
*/
|
||||||
|
public static ListNetworksOptions domainId(long domainId) {
|
||||||
|
ListNetworksOptions options = new ListNetworksOptions();
|
||||||
|
return options.domainId(domainId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,7 +78,7 @@ public class CloudStackComputeServiceAdapterLiveTest extends BaseCloudStackClien
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bindProperties(binder(), new CloudStackPropertiesBuilder(new Properties()).build());
|
bindProperties(binder(), CloudStackComputeServiceAdapterLiveTest.this.setupProperties());
|
||||||
bind(CloudStackClient.class).toInstance(context.getApi());
|
bind(CloudStackClient.class).toInstance(context.getApi());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,6 +74,7 @@ public class BaseCloudStackClientLiveTest extends BaseVersionedServiceLiveTest {
|
||||||
protected RetryablePredicate<VirtualMachine> virtualMachineRunning;
|
protected RetryablePredicate<VirtualMachine> virtualMachineRunning;
|
||||||
protected RetryablePredicate<VirtualMachine> virtualMachineDestroyed;
|
protected RetryablePredicate<VirtualMachine> virtualMachineDestroyed;
|
||||||
protected SshClient.Factory sshFactory;
|
protected SshClient.Factory sshFactory;
|
||||||
|
protected User currentUser;
|
||||||
protected String password = "password";
|
protected String password = "password";
|
||||||
|
|
||||||
protected Injector injector;
|
protected Injector injector;
|
||||||
|
@ -82,6 +83,7 @@ public class BaseCloudStackClientLiveTest extends BaseVersionedServiceLiveTest {
|
||||||
|
|
||||||
protected ComputeServiceContext computeContext;
|
protected ComputeServiceContext computeContext;
|
||||||
|
|
||||||
|
|
||||||
protected void checkSSH(IPSocket socket) {
|
protected void checkSSH(IPSocket socket) {
|
||||||
socketTester.apply(socket);
|
socketTester.apply(socket);
|
||||||
SshClient client = sshFactory.create(socket, new Credentials("root", password));
|
SshClient client = sshFactory.create(socket, new Credentials("root", password));
|
||||||
|
@ -108,7 +110,6 @@ public class BaseCloudStackClientLiveTest extends BaseVersionedServiceLiveTest {
|
||||||
client = context.getApi();
|
client = context.getApi();
|
||||||
// check access
|
// check access
|
||||||
Iterable<User> users = Iterables.concat(client.getAccountClient().listAccounts());
|
Iterable<User> users = Iterables.concat(client.getAccountClient().listAccounts());
|
||||||
User currentUser;
|
|
||||||
Predicate<User> apiKeyMatches = UserPredicates.apiKeyEquals(identity);
|
Predicate<User> apiKeyMatches = UserPredicates.apiKeyEquals(identity);
|
||||||
try {
|
try {
|
||||||
currentUser = Iterables.find(users, apiKeyMatches);
|
currentUser = Iterables.find(users, apiKeyMatches);
|
||||||
|
|
|
@ -19,6 +19,10 @@
|
||||||
package org.jclouds.cloudstack.features;
|
package org.jclouds.cloudstack.features;
|
||||||
|
|
||||||
import static com.google.common.collect.Iterables.find;
|
import static com.google.common.collect.Iterables.find;
|
||||||
|
import static com.google.common.collect.Iterables.getOnlyElement;
|
||||||
|
import static org.jclouds.cloudstack.options.ListNetworksOptions.Builder.accountInDomain;
|
||||||
|
import static org.jclouds.cloudstack.options.ListNetworksOptions.Builder.id;
|
||||||
|
import static org.jclouds.cloudstack.options.ListNetworksOptions.Builder.zoneId;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
import static org.testng.Assert.assertTrue;
|
import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
|
@ -30,14 +34,13 @@ import org.jclouds.cloudstack.domain.GuestIPType;
|
||||||
import org.jclouds.cloudstack.domain.Network;
|
import org.jclouds.cloudstack.domain.Network;
|
||||||
import org.jclouds.cloudstack.domain.NetworkOffering;
|
import org.jclouds.cloudstack.domain.NetworkOffering;
|
||||||
import org.jclouds.cloudstack.domain.Zone;
|
import org.jclouds.cloudstack.domain.Zone;
|
||||||
import org.jclouds.cloudstack.options.ListNetworksOptions;
|
|
||||||
import org.jclouds.cloudstack.predicates.NetworkOfferingPredicates;
|
import org.jclouds.cloudstack.predicates.NetworkOfferingPredicates;
|
||||||
import org.jclouds.cloudstack.predicates.ZonePredicates;
|
import org.jclouds.cloudstack.predicates.ZonePredicates;
|
||||||
import org.testng.annotations.AfterGroups;
|
import org.testng.annotations.AfterGroups;
|
||||||
import org.testng.annotations.BeforeGroups;
|
import org.testng.annotations.BeforeGroups;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.base.Predicate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests behavior of {@code NetworkClientLiveTest}
|
* Tests behavior of {@code NetworkClientLiveTest}
|
||||||
|
@ -54,6 +57,9 @@ public class NetworkClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||||
|
|
||||||
private Network network;
|
private Network network;
|
||||||
|
|
||||||
|
// only delete networks we create
|
||||||
|
private boolean weCreatedNetwork;
|
||||||
|
|
||||||
@BeforeGroups(groups = "live")
|
@BeforeGroups(groups = "live")
|
||||||
public void setupClient() {
|
public void setupClient() {
|
||||||
super.setupClient();
|
super.setupClient();
|
||||||
|
@ -62,7 +68,7 @@ public class NetworkClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||||
// you can create guest direct network by Admin user, but since we are
|
// you can create guest direct network by Admin user, but since we are
|
||||||
// not admin, let's try to create a guest virtual one
|
// not admin, let's try to create a guest virtual one
|
||||||
zone = find(client.getZoneClient().listZones(), ZonePredicates.supportsGuestVirtualNetworks());
|
zone = find(client.getZoneClient().listZones(), ZonePredicates.supportsGuestVirtualNetworks());
|
||||||
offering = Iterables.find(client.getOfferingClient().listNetworkOfferings(),
|
offering = find(client.getOfferingClient().listNetworkOfferings(),
|
||||||
NetworkOfferingPredicates.supportsGuestVirtualNetworks());
|
NetworkOfferingPredicates.supportsGuestVirtualNetworks());
|
||||||
networksSupported = true;
|
networksSupported = true;
|
||||||
} catch (NoSuchElementException e) {
|
} catch (NoSuchElementException e) {
|
||||||
|
@ -72,34 +78,39 @@ public class NetworkClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||||
public void testCreateNetwork() throws Exception {
|
public void testCreateNetwork() throws Exception {
|
||||||
if (!networksSupported)
|
if (!networksSupported)
|
||||||
return;
|
return;
|
||||||
|
try {
|
||||||
network = client.getNetworkClient().createNetworkInZone(zone.getId(), offering.getId(), prefix, prefix);
|
network = client.getNetworkClient().createNetworkInZone(zone.getId(), offering.getId(), prefix, prefix);
|
||||||
|
weCreatedNetwork = true;
|
||||||
|
} catch (IllegalStateException e) {
|
||||||
|
network = find(
|
||||||
|
client.getNetworkClient().listNetworks(
|
||||||
|
zoneId(zone.getId()).accountInDomain(currentUser.getAccount(), currentUser.getDomainId())),
|
||||||
|
new Predicate<Network>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean apply(Network arg0) {
|
||||||
|
return arg0.getNetworkOfferingId() == offering.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
checkNetwork(network);
|
checkNetwork(network);
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterGroups(groups = "live")
|
@Test(dependsOnMethods = "testCreateNetwork")
|
||||||
protected void tearDown() {
|
|
||||||
if (network != null) {
|
|
||||||
Long jobId = client.getNetworkClient().deleteNetwork(network.getId());
|
|
||||||
if (jobId != null)
|
|
||||||
jobComplete.apply(jobId);
|
|
||||||
}
|
|
||||||
super.tearDown();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testListNetworks() throws Exception {
|
public void testListNetworks() throws Exception {
|
||||||
if (!networksSupported)
|
if (!networksSupported)
|
||||||
return;
|
return;
|
||||||
Set<Network> response = client.getNetworkClient().listNetworks();
|
Set<Network> response = client.getNetworkClient().listNetworks(
|
||||||
|
accountInDomain(network.getAccount(), network.getDomainId()));
|
||||||
assert null != response;
|
assert null != response;
|
||||||
long networkCount = response.size();
|
long networkCount = response.size();
|
||||||
assertTrue(networkCount >= 0);
|
assertTrue(networkCount >= 0);
|
||||||
for (Network network : response) {
|
for (Network network : response) {
|
||||||
Network newDetails = Iterables.getOnlyElement(client.getNetworkClient().listNetworks(
|
Network newDetails = getOnlyElement(client.getNetworkClient().listNetworks(id(network.getId())));
|
||||||
ListNetworksOptions.Builder.id(network.getId())));
|
|
||||||
assertEquals(network, newDetails);
|
assertEquals(network, newDetails);
|
||||||
assertEquals(network, client.getNetworkClient().getNetwork(network.getId()));
|
assertEquals(network, client.getNetworkClient().getNetwork(network.getId()));
|
||||||
checkNetwork(network);
|
checkNetwork(network);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,4 +153,15 @@ public class NetworkClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AfterGroups(groups = "live")
|
||||||
|
protected void tearDown() {
|
||||||
|
if (network != null && weCreatedNetwork) {
|
||||||
|
Long jobId = client.getNetworkClient().deleteNetwork(network.getId());
|
||||||
|
if (jobId != null)
|
||||||
|
jobComplete.apply(jobId);
|
||||||
|
}
|
||||||
|
super.tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.cloudstack.options;
|
package org.jclouds.cloudstack.options;
|
||||||
|
|
||||||
import static org.jclouds.cloudstack.options.ListNetworksOptions.Builder.account;
|
import static org.jclouds.cloudstack.options.ListNetworksOptions.Builder.accountInDomain;
|
||||||
import static org.jclouds.cloudstack.options.ListNetworksOptions.Builder.domainId;
|
import static org.jclouds.cloudstack.options.ListNetworksOptions.Builder.domainId;
|
||||||
import static org.jclouds.cloudstack.options.ListNetworksOptions.Builder.id;
|
import static org.jclouds.cloudstack.options.ListNetworksOptions.Builder.id;
|
||||||
import static org.jclouds.cloudstack.options.ListNetworksOptions.Builder.isDefault;
|
import static org.jclouds.cloudstack.options.ListNetworksOptions.Builder.isDefault;
|
||||||
|
@ -94,13 +94,14 @@ public class ListNetworksOptionsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAccountId() {
|
public void testAccountId() {
|
||||||
ListNetworksOptions options = new ListNetworksOptions().account("moo");
|
ListNetworksOptions options = new ListNetworksOptions().accountInDomain("moo", 1);
|
||||||
assertEquals(ImmutableList.of("moo"), options.buildQueryParameters().get("account"));
|
assertEquals(ImmutableList.of("1"), options.buildQueryParameters().get("domainid"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAccountIdStatic() {
|
public void testAccountIdStatic() {
|
||||||
ListNetworksOptions options = account("moo");
|
ListNetworksOptions options = accountInDomain("moo", 1l);
|
||||||
assertEquals(ImmutableList.of("moo"), options.buildQueryParameters().get("account"));
|
assertEquals(ImmutableList.of("moo"), options.buildQueryParameters().get("account"));
|
||||||
|
assertEquals(ImmutableList.of("1"), options.buildQueryParameters().get("domainid"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testTrafficType() {
|
public void testTrafficType() {
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
/**
|
||||||
|
* 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 org.jclouds.json.BaseItemParserTest;
|
||||||
|
import org.jclouds.rest.annotations.SelectJson;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Test(groups = "unit", testName = "DeleteNetworkResponseTest")
|
||||||
|
public class DeleteNetworkResponseTest extends BaseItemParserTest<Long> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String resource() {
|
||||||
|
return "/deletenetworkresponse.json";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SelectJson("jobid")
|
||||||
|
public Long expected() {
|
||||||
|
return 45612l;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
{ "deletenetworkresponse" : {"jobid":45612} }
|
Loading…
Reference in New Issue