mirror of https://github.com/apache/jclouds.git
Issue 695 Added service call getAssignedIpAddresses
This commit is contained in:
parent
e7847fa3cc
commit
16e16fa353
|
@ -21,6 +21,7 @@ package org.jclouds.tmrk.enterprisecloud.domain;
|
|||
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.net.URI;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
@ -28,6 +29,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||
/**
|
||||
* @author Jason King
|
||||
*/
|
||||
@XmlRootElement(name="AssignedIpAddresses")
|
||||
public class AssignedIpAddresses extends BaseResource<AssignedIpAddresses> {
|
||||
|
||||
//TODO builder stuff
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.jclouds.rest.annotations.Headers;
|
|||
import org.jclouds.rest.annotations.JAXBResponseParser;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.AssignedIpAddresses;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.VirtualMachine;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.VirtualMachines;
|
||||
|
||||
|
@ -67,4 +68,14 @@ public interface VirtualMachineAsyncClient {
|
|||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<VirtualMachine> getVirtualMachine(@PathParam("id") long id);
|
||||
|
||||
/**
|
||||
* @see VirtualMachineClient#getVirtualMachine
|
||||
*/
|
||||
@GET
|
||||
@Path("/virtualMachines/{id}/assignedIps")
|
||||
@Consumes("application/vnd.tmrk.cloud.virtualMachineAssignedIps")
|
||||
@JAXBResponseParser
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<AssignedIpAddresses> getAssignedIpAddresses(@PathParam("id") long id);
|
||||
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package org.jclouds.tmrk.enterprisecloud.features;
|
||||
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.AssignedIpAddresses;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.VirtualMachine;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.VirtualMachines;
|
||||
|
||||
|
@ -52,4 +53,12 @@ public interface VirtualMachineClient {
|
|||
*/
|
||||
VirtualMachine getVirtualMachine(long id);
|
||||
|
||||
/**
|
||||
* The Get Virtual Machines Assigned IP Addresses call returns information
|
||||
* regarding the IP addresses assigned to a specified virtual machine in a compute pool.
|
||||
* @param id the id of the virtual machine
|
||||
* @return the assigned ip addresses
|
||||
*/
|
||||
AssignedIpAddresses getAssignedIpAddresses(long id);
|
||||
|
||||
}
|
||||
|
|
|
@ -64,6 +64,20 @@ public class VirtualMachineAsyncClientTest extends BaseTerremarkEnterpriseCloudA
|
|||
checkFilters(httpRequest);
|
||||
}
|
||||
|
||||
public void testGetAssignedIpAddresses() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VirtualMachineAsyncClient.class.getMethod("getAssignedIpAddresses", long.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method,1);
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/virtualMachines/1/assignedIps HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/vnd.tmrk.cloud.virtualMachineAssignedIps\nx-tmrk-version: 2011-07-01\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseXMLWithJAXB.class);
|
||||
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TypeLiteral<RestAnnotationProcessor<VirtualMachineAsyncClient>> createTypeLiteral() {
|
||||
return new TypeLiteral<RestAnnotationProcessor<VirtualMachineAsyncClient>>() {
|
||||
|
|
|
@ -18,14 +18,19 @@
|
|||
*/
|
||||
package org.jclouds.tmrk.enterprisecloud.features;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.AssignedIpAddresses;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.DeviceNetwork;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.VirtualMachine;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.VirtualMachines;
|
||||
import org.testng.annotations.BeforeGroups;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code VirtualMachineClient}
|
||||
|
@ -61,6 +66,15 @@ public class VirtualMachineClientLiveTest extends BaseTerremarkEnterpriseCloudCl
|
|||
assertEquals(virtualMachine.getStatus(),VirtualMachine.VirtualMachineStatus.DEPLOYED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAssignedIpAddresses() throws Exception {
|
||||
AssignedIpAddresses assignedIpAddresses = client.getAssignedIpAddresses(5504);
|
||||
assert null != assignedIpAddresses;
|
||||
DeviceNetwork network = Iterables.getOnlyElement(assignedIpAddresses.getNetworks().getDeviceNetworks());
|
||||
Set<String> ipAddresses = network.getIpAddresses().getIpAddresses();
|
||||
assertTrue(ipAddresses.size()>0, "vm has no assigned ip addresses");
|
||||
}
|
||||
|
||||
// TODO: We are not supposed to parse the href's
|
||||
// The alternative is to use URI's on the method calls.
|
||||
// But this has the risk of exposing strings like "/virtualmachines/5504" and "/computepools/89" to users
|
||||
|
|
|
@ -0,0 +1,119 @@
|
|||
/**
|
||||
* 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.tmrk.enterprisecloud.xml;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.Provides;
|
||||
import org.jclouds.crypto.Crypto;
|
||||
import org.jclouds.date.internal.SimpleDateFormatDateService;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.functions.ParseXMLWithJAXB;
|
||||
import org.jclouds.logging.config.NullLoggingModule;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.BaseRestClientTest;
|
||||
import org.jclouds.rest.RestContextSpec;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.*;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.VirtualMachine.VirtualMachineStatus;
|
||||
import org.jclouds.tmrk.enterprisecloud.features.VirtualMachineAsyncClient;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import javax.inject.Named;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jclouds.io.Payloads.newInputStreamPayload;
|
||||
import static org.jclouds.rest.RestContextFactory.contextSpec;
|
||||
import static org.jclouds.rest.RestContextFactory.createContextBuilder;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.AssertJUnit.assertEquals;
|
||||
import static org.testng.AssertJUnit.assertNotNull;
|
||||
|
||||
/**
|
||||
* Tests behavior of JAXB parsing for AssignedIpAddresses
|
||||
*
|
||||
* @author Jason King
|
||||
*/
|
||||
@Test(groups = "unit", testName = "AssignedIpAddressesJAXBParsingTest")
|
||||
public class AssignedIpAddressesJAXBParsingTest extends BaseRestClientTest {
|
||||
private SimpleDateFormatDateService dateService;
|
||||
|
||||
@BeforeMethod
|
||||
public void setUp() {
|
||||
dateService = new SimpleDateFormatDateService();
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
void setupFactory() {
|
||||
RestContextSpec<String, Integer> contextSpec = contextSpec("test", "http://localhost:9999", "1", "", "userfoo",
|
||||
"credentialFoo", String.class, Integer.class,
|
||||
ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule(), new AbstractModule() {
|
||||
|
||||
@Override
|
||||
protected void configure() {}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Provides
|
||||
@Named("exception")
|
||||
Set<String> exception() {
|
||||
throw new AuthorizationException();
|
||||
}
|
||||
|
||||
}));
|
||||
|
||||
injector = createContextBuilder(contextSpec).buildInjector();
|
||||
parserFactory = injector.getInstance(ParseSax.Factory.class);
|
||||
crypto = injector.getInstance(Crypto.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseAssignedIpAddressesWithJAXB() throws Exception {
|
||||
|
||||
Method method = VirtualMachineAsyncClient.class.getMethod("getAssignedIpAddresses", long.class);
|
||||
HttpRequest request = factory(VirtualMachineAsyncClient.class).createRequest(method,1);
|
||||
assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class);
|
||||
|
||||
Function<HttpResponse, AssignedIpAddresses> parser = (Function<HttpResponse, AssignedIpAddresses>) RestAnnotationProcessor
|
||||
.createResponseParser(parserFactory, injector, method, request);
|
||||
|
||||
InputStream is = getClass().getResourceAsStream("/assignedIpAddresses.xml");
|
||||
AssignedIpAddresses addresses = parser.apply(new HttpResponse(200, "ok", newInputStreamPayload(is)));
|
||||
|
||||
Assert.assertNotNull(addresses);
|
||||
Set<DeviceNetwork> deviceNetworks = addresses.getNetworks().getDeviceNetworks();
|
||||
assertEquals(1,deviceNetworks.size());
|
||||
DeviceNetwork network = Iterables.getOnlyElement(deviceNetworks);
|
||||
Set<String> ips = network.getIpAddresses().getIpAddresses();
|
||||
assertEquals(2,ips.size());
|
||||
assertTrue(ips.contains("10.146.204.98"));
|
||||
assertTrue(ips.contains("10.146.204.99"));
|
||||
}
|
||||
}
|
|
@ -20,6 +20,7 @@ package org.jclouds.tmrk.enterprisecloud.xml;
|
|||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.Provides;
|
||||
|
@ -179,7 +180,7 @@ public class VirtualMachineJAXBParsingTest extends BaseRestClientTest {
|
|||
Assert.assertNotNull(assignedIpAddresses);
|
||||
Set<DeviceNetwork> deviceNetworks = assignedIpAddresses.getNetworks().getDeviceNetworks();
|
||||
assertEquals(1,deviceNetworks.size());
|
||||
DeviceNetwork network = deviceNetworks.iterator().next(); //todo use guava instead.
|
||||
DeviceNetwork network = Iterables.getOnlyElement(deviceNetworks);
|
||||
Set<String> ips = network.getIpAddresses().getIpAddresses();
|
||||
assertEquals(2,ips.size());
|
||||
assertTrue(ips.contains("10.146.204.67"));
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
<AssignedIpAddresses href="/cloudapi/ecloud/virtualmachines/5504/assignedips"
|
||||
type="application/vnd.tmrk.cloud.virtualMachineAssignedIps"
|
||||
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<Actions>
|
||||
<Action href="/cloudapi/ecloud/virtualmachines/5504/assignedips"
|
||||
name="edit"
|
||||
type="application/vnd.tmrk.cloud.virtualMachineAssignedIps"/>
|
||||
</Actions>
|
||||
<Networks>
|
||||
<Network href="/cloudapi/ecloud/networks/3936"
|
||||
name="10.146.204.64/28 (INT_202)"
|
||||
type="application/vnd.tmrk.cloud.network">
|
||||
<IpAddresses>
|
||||
<IpAddress>10.146.204.98</IpAddress>
|
||||
<IpAddress>10.146.204.99</IpAddress>
|
||||
</IpAddresses>
|
||||
</Network>
|
||||
</Networks>
|
||||
</AssignedIpAddresses>
|
Loading…
Reference in New Issue