mirror of https://github.com/apache/jclouds.git
Add updatePod
This commit is contained in:
parent
0821b02726
commit
36fd32b08e
|
@ -23,6 +23,7 @@ import org.jclouds.cloudstack.domain.Pod;
|
|||
import org.jclouds.cloudstack.filters.QuerySigner;
|
||||
import org.jclouds.cloudstack.options.CreatePodOptions;
|
||||
import org.jclouds.cloudstack.options.ListPodsOptions;
|
||||
import org.jclouds.cloudstack.options.UpdatePodOptions;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.OnlyElement;
|
||||
import org.jclouds.rest.annotations.QueryParams;
|
||||
|
@ -119,4 +120,17 @@ public interface GlobalPodAsyncClient {
|
|||
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
|
||||
ListenableFuture<Void> deletePod(@QueryParam("id") long id);
|
||||
|
||||
/**
|
||||
* Updates a Pod.
|
||||
* @param id the ID of the Pod
|
||||
* @param updatePodOptions optional arguments
|
||||
* @return the updated pod
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "updatePod")
|
||||
@SelectJson("pod")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<Pod> updatePod(@QueryParam("id") long id, UpdatePodOptions... updatePodOptions);
|
||||
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.jclouds.cloudstack.features;
|
|||
import org.jclouds.cloudstack.domain.Pod;
|
||||
import org.jclouds.cloudstack.options.CreatePodOptions;
|
||||
import org.jclouds.cloudstack.options.ListPodsOptions;
|
||||
import org.jclouds.cloudstack.options.UpdatePodOptions;
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
|
||||
import java.util.Set;
|
||||
|
@ -88,4 +89,13 @@ public interface GlobalPodClient {
|
|||
* @param id the ID of the Pod
|
||||
*/
|
||||
void deletePod(long id);
|
||||
|
||||
/**
|
||||
* Updates a Pod.
|
||||
* @param id the ID of the Pod
|
||||
* @param updatePodOptions optional arguments
|
||||
* @return the updated pod
|
||||
*/
|
||||
Pod updatePod(long id, UpdatePodOptions... updatePodOptions);
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
/**
|
||||
* 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.jclouds.cloudstack.domain.AllocationState;
|
||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
/**
|
||||
* Options to the GlobalPodClient.updatePod API call.
|
||||
*
|
||||
* @author Richard Downer
|
||||
*/
|
||||
public class UpdatePodOptions extends BaseHttpRequestOptions {
|
||||
|
||||
public static final UpdatePodOptions NONE = new UpdatePodOptions();
|
||||
|
||||
public static class Builder {
|
||||
|
||||
public static UpdatePodOptions name(String name) {
|
||||
return new UpdatePodOptions().name(name);
|
||||
}
|
||||
|
||||
public static UpdatePodOptions startIp(String startIp) {
|
||||
return new UpdatePodOptions().startIp(startIp);
|
||||
}
|
||||
|
||||
public static UpdatePodOptions endIp(String endIp) {
|
||||
return new UpdatePodOptions().endIp(endIp);
|
||||
}
|
||||
|
||||
public static UpdatePodOptions gateway(String gateway) {
|
||||
return new UpdatePodOptions().gateway(gateway);
|
||||
}
|
||||
|
||||
public static UpdatePodOptions netmask(String netmask) {
|
||||
return new UpdatePodOptions().netmask(netmask);
|
||||
}
|
||||
|
||||
public static UpdatePodOptions allocationState(AllocationState allocationState) {
|
||||
return new UpdatePodOptions().allocationState(allocationState);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public UpdatePodOptions name(String name) {
|
||||
this.queryParameters.replaceValues("name", ImmutableSet.<String>of(name));
|
||||
return this;
|
||||
}
|
||||
|
||||
public UpdatePodOptions startIp(String startIp) {
|
||||
this.queryParameters.replaceValues("startip", ImmutableSet.<String>of(startIp));
|
||||
return this;
|
||||
}
|
||||
|
||||
public UpdatePodOptions endIp(String endIp) {
|
||||
this.queryParameters.replaceValues("endip", ImmutableSet.<String>of(endIp));
|
||||
return this;
|
||||
}
|
||||
|
||||
public UpdatePodOptions gateway(String gateway) {
|
||||
this.queryParameters.replaceValues("gateway", ImmutableSet.<String>of(gateway));
|
||||
return this;
|
||||
}
|
||||
|
||||
public UpdatePodOptions netmask(String netmask) {
|
||||
this.queryParameters.replaceValues("netmask", ImmutableSet.<String>of(netmask));
|
||||
return this;
|
||||
}
|
||||
|
||||
public UpdatePodOptions allocationState(AllocationState allocationState) {
|
||||
this.queryParameters.replaceValues("allocationstate", ImmutableSet.of(allocationState.toString()));
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
|
@ -24,6 +24,7 @@ import org.jclouds.cloudstack.CloudStackContext;
|
|||
import org.jclouds.cloudstack.domain.AllocationState;
|
||||
import org.jclouds.cloudstack.domain.Pod;
|
||||
import org.jclouds.cloudstack.options.CreatePodOptions;
|
||||
import org.jclouds.cloudstack.options.UpdatePodOptions;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -136,6 +137,46 @@ public class GlobalPodClientExpectTest extends BaseCloudStackRestClientExpectTes
|
|||
assertEquals(actual, expected);
|
||||
}
|
||||
|
||||
public void testUpdatePodWhenResponseIs2xx() {
|
||||
GlobalPodClient client = requestSendsResponse(
|
||||
HttpRequest.builder()
|
||||
.method("GET")
|
||||
.endpoint(
|
||||
URI.create("http://localhost:8080/client/api?response=json&command=updatePod&id=7&netmask=255.255.255.128&name=richard-updatepod&startip=172.21.0.129&endip=172.21.0.250&gateway=172.21.0.254&allocationstate=Disabled&apiKey=identity&signature=QpdbRyyF%2FxJ78ioJWhPKXEWhthY%3D"))
|
||||
.headers(
|
||||
ImmutableMultimap.<String, String>builder()
|
||||
.put("Accept", "application/json")
|
||||
.build())
|
||||
.build(),
|
||||
HttpResponse.builder()
|
||||
.statusCode(200)
|
||||
.payload(payloadFromResource("/updatepodresponse.json"))
|
||||
.build());
|
||||
|
||||
Pod expected = Pod.builder()
|
||||
.id(7)
|
||||
.name("richard-updatedpod")
|
||||
.zoneId(11)
|
||||
.zoneName("richard-zone")
|
||||
.gateway("172.21.0.254")
|
||||
.netmask("255.255.255.128")
|
||||
.startIp("172.21.0.129")
|
||||
.endIp("172.21.0.250")
|
||||
.allocationState(AllocationState.DISABLED)
|
||||
.build();
|
||||
|
||||
Pod actual = client.updatePod(7, UpdatePodOptions.Builder
|
||||
.netmask("255.255.255.128")
|
||||
.name("richard-updatepod")
|
||||
.startIp("172.21.0.129")
|
||||
.endIp("172.21.0.250")
|
||||
.gateway("172.21.0.254")
|
||||
.allocationState(AllocationState.DISABLED)
|
||||
);
|
||||
|
||||
assertEquals(actual, expected);
|
||||
}
|
||||
|
||||
public void testDeletePodWhenResponseIs2xx() {
|
||||
GlobalPodClient client = requestSendsResponse(
|
||||
HttpRequest.builder()
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.jclouds.cloudstack.domain.Pod;
|
|||
import org.jclouds.cloudstack.domain.Zone;
|
||||
import org.jclouds.cloudstack.options.CreatePodOptions;
|
||||
import org.jclouds.cloudstack.options.ListPodsOptions;
|
||||
import org.jclouds.cloudstack.options.UpdatePodOptions;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -87,6 +88,28 @@ public class GlobalPodClientLiveTest extends BaseCloudStackClientLiveTest {
|
|||
assertEquals(pod.getAllocationState(), AllocationState.ENABLED);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testCreatePod")
|
||||
public void testUpdatePod() {
|
||||
Pod updated = globalAdminClient.getPodClient().updatePod(pod.getId(), UpdatePodOptions.Builder
|
||||
.name(prefix + "-updatedpod")
|
||||
.startIp("172.21.0.129")
|
||||
.endIp("172.21.0.250")
|
||||
.gateway("172.21.0.254")
|
||||
.netmask("255.255.255.128")
|
||||
.allocationState(AllocationState.DISABLED)
|
||||
);
|
||||
|
||||
assertNotNull(updated);
|
||||
assertEquals(updated.getName(), prefix + "-updatedpod");
|
||||
assertEquals(updated.getZoneId(), zone.getId());
|
||||
assertEquals(updated.getZoneName(), prefix + "-zone");
|
||||
assertEquals(updated.getStartIp(), "172.21.0.129");
|
||||
assertEquals(updated.getEndIp(), "172.21.0.250");
|
||||
assertEquals(updated.getGateway(), "172.21.0.254");
|
||||
assertEquals(updated.getNetmask(), "255.255.255.128");
|
||||
assertEquals(updated.getAllocationState(), AllocationState.DISABLED);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public void testFixtureTearDown() {
|
||||
if (pod != null) {
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
/**
|
||||
* 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.jclouds.cloudstack.domain.AllocationState;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.jclouds.cloudstack.options.UpdatePodOptions.Builder.*;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code UpdatePodOptions}
|
||||
*
|
||||
* @author Richard Downer
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
public class UpdatePodOptionsTest {
|
||||
|
||||
public void testName() {
|
||||
UpdatePodOptions options = new UpdatePodOptions().name("fred");
|
||||
assertEquals(ImmutableList.of("fred"), options.buildQueryParameters().get("name"));
|
||||
}
|
||||
|
||||
public void testNameStatic() {
|
||||
UpdatePodOptions options = name("fred");
|
||||
assertEquals(ImmutableList.of("fred"), options.buildQueryParameters().get("name"));
|
||||
}
|
||||
|
||||
public void testStartIp() {
|
||||
UpdatePodOptions options = new UpdatePodOptions().startIp("192.168.42.42");
|
||||
assertEquals(ImmutableList.of("192.168.42.42"), options.buildQueryParameters().get("startip"));
|
||||
}
|
||||
|
||||
public void testStartIpStatic() {
|
||||
UpdatePodOptions options = startIp("192.168.42.42");
|
||||
assertEquals(ImmutableList.of("192.168.42.42"), options.buildQueryParameters().get("startip"));
|
||||
}
|
||||
|
||||
public void testEndIp() {
|
||||
UpdatePodOptions options = new UpdatePodOptions().endIp("192.168.42.52");
|
||||
assertEquals(ImmutableList.of("192.168.42.52"), options.buildQueryParameters().get("endip"));
|
||||
}
|
||||
|
||||
public void testEndIpStatic() {
|
||||
UpdatePodOptions options = endIp("192.168.42.52");
|
||||
assertEquals(ImmutableList.of("192.168.42.52"), options.buildQueryParameters().get("endip"));
|
||||
}
|
||||
|
||||
public void testGateway() {
|
||||
UpdatePodOptions options = new UpdatePodOptions().gateway("192.168.42.62");
|
||||
assertEquals(ImmutableList.of("192.168.42.62"), options.buildQueryParameters().get("gateway"));
|
||||
}
|
||||
|
||||
public void testGatewayStatic() {
|
||||
UpdatePodOptions options = gateway("192.168.42.62");
|
||||
assertEquals(ImmutableList.of("192.168.42.62"), options.buildQueryParameters().get("gateway"));
|
||||
}
|
||||
|
||||
public void testNetmask() {
|
||||
UpdatePodOptions options = new UpdatePodOptions().netmask("255.255.240.0");
|
||||
assertEquals(ImmutableList.of("255.255.240.0"), options.buildQueryParameters().get("netmask"));
|
||||
}
|
||||
|
||||
public void testNetmaskStatic() {
|
||||
UpdatePodOptions options = netmask("255.255.240.0");
|
||||
assertEquals(ImmutableList.of("255.255.240.0"), options.buildQueryParameters().get("netmask"));
|
||||
}
|
||||
|
||||
public void testAllocationState() {
|
||||
UpdatePodOptions options = new UpdatePodOptions().allocationState(AllocationState.ENABLED);
|
||||
assertEquals(ImmutableList.of("Enabled"), options.buildQueryParameters().get("allocationstate"));
|
||||
}
|
||||
|
||||
public void testAllocationStateStatic() {
|
||||
UpdatePodOptions options = allocationState(AllocationState.ENABLED);
|
||||
assertEquals(ImmutableList.of("Enabled"), options.buildQueryParameters().get("allocationstate"));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
{ "updatepodresponse" : { "pod" : {"id":7,"name":"richard-updatedpod","zoneid":11,"zonename":"richard-zone","gateway":"172.21.0.254","netmask":"255.255.255.128","startip":"172.21.0.129","endip":"172.21.0.250","allocationstate":"Disabled"} } }
|
Loading…
Reference in New Issue