Add GlobalHost[Async]Client.deleteHost()

This commit is contained in:
Richard Downer 2012-01-12 14:13:23 +02:00
parent 2b1c5f78f3
commit 350e01c230
5 changed files with 158 additions and 0 deletions

View File

@ -23,6 +23,7 @@ import org.jclouds.cloudstack.domain.Cluster;
import org.jclouds.cloudstack.domain.Host;
import org.jclouds.cloudstack.filters.QuerySigner;
import org.jclouds.cloudstack.options.AddHostOptions;
import org.jclouds.cloudstack.options.DeleteHostOptions;
import org.jclouds.cloudstack.options.ListClustersOptions;
import org.jclouds.cloudstack.options.ListHostsOptions;
import org.jclouds.cloudstack.options.UpdateHostOptions;
@ -102,6 +103,17 @@ public interface GlobalHostAsyncClient {
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Void> updateHostPassword(@QueryParam("hostid") long hostId, @QueryParam("username") String username, @QueryParam("password") String password);
/**
* Deletes a host.
*
* @param hostId the host ID
* @param options optional arguments
*/
@GET
@QueryParams(keys = "command", values = "deleteHost")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Void> deleteHost(@QueryParam("id") long hostId, DeleteHostOptions... options);
/**
* @see GlobalHostClient#listClusters
*/

View File

@ -21,6 +21,7 @@ package org.jclouds.cloudstack.features;
import org.jclouds.cloudstack.domain.Cluster;
import org.jclouds.cloudstack.domain.Host;
import org.jclouds.cloudstack.options.AddHostOptions;
import org.jclouds.cloudstack.options.DeleteHostOptions;
import org.jclouds.cloudstack.options.ListClustersOptions;
import org.jclouds.cloudstack.options.ListHostsOptions;
import org.jclouds.cloudstack.options.UpdateHostOptions;
@ -81,6 +82,14 @@ public interface GlobalHostClient {
*/
void updateHostPassword(long hostId, String username, String password);
/**
* Deletes a host.
*
* @param hostId the host ID
* @param options optional arguments
*/
void deleteHost(long hostId, DeleteHostOptions... options);
/**
* Lists clusters
*

View File

@ -0,0 +1,66 @@
/**
* 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.http.options.BaseHttpRequestOptions;
/**
* Options to the GlobalHostClient.deleteHost() API call
*
* @author Richard Downer
*/
public class DeleteHostOptions extends BaseHttpRequestOptions {
public static final DeleteHostOptions NONE = new DeleteHostOptions();
/**
* @param forced Force delete the host. All HA enabled vms running on the host will be put to HA; HA disabled ones will be stopped
*/
public DeleteHostOptions forced(boolean forced) {
this.queryParameters.replaceValues("forced", ImmutableSet.of(forced + ""));
return this;
}
/**
* @param forceDestroyLocalStorage Force destroy local storage on this host. All VMs created on this local storage will be destroyed
*/
public DeleteHostOptions forceDestroyLocalStorage(boolean forceDestroyLocalStorage) {
this.queryParameters.replaceValues("forcedestroylocalstorage", ImmutableSet.of(forceDestroyLocalStorage + ""));
return this;
}
public static class Builder {
/**
* @param forced Force delete the host. All HA enabled vms running on the host will be put to HA; HA disabled ones will be stopped
*/
public static DeleteHostOptions forced(boolean forced) {
return new DeleteHostOptions().forced(forced);
}
/**
* @param forceDestroyLocalStorage Force destroy local storage on this host. All VMs created on this local storage will be destroyed
*/
public static DeleteHostOptions forceDestroyLocalStorage(boolean forceDestroyLocalStorage) {
return new DeleteHostOptions().forceDestroyLocalStorage(forceDestroyLocalStorage);
}
}
}

View File

@ -26,6 +26,7 @@ import org.jclouds.cloudstack.domain.Cluster;
import org.jclouds.cloudstack.domain.ConfigurationEntry;
import org.jclouds.cloudstack.domain.Host;
import org.jclouds.cloudstack.options.AddHostOptions;
import org.jclouds.cloudstack.options.DeleteHostOptions;
import org.jclouds.cloudstack.options.UpdateHostOptions;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
@ -151,6 +152,19 @@ public class GlobalHostClientExpectTest extends BaseCloudStackRestClientExpectTe
requestSendsResponse(request, response).updateHostPassword(1, "fred", "sekrit");
}
@Test
public void testDeleteHostWhenResponseIs2xx() {
HttpRequest request = HttpRequest.builder()
.method("GET")
.endpoint(URI.create("http://localhost:8080/client/api?response=json&command=deleteHost&id=1&forced=true&forcedestroylocalstorage=true&apiKey=identity&signature=ZdvO1BWBkdPiDAjsVlKtqDe6N7k%3D"))
.headers(ImmutableMultimap.<String, String>builder().put("Accept", "application/json").build())
.build();
HttpResponse response = HttpResponse.builder()
.statusCode(200).build();
requestSendsResponse(request, response).deleteHost(1, DeleteHostOptions.Builder.forced(true).forceDestroyLocalStorage(true));
}
@Test
public void testListClustersWhenResponseIs2xx() {
HttpRequest request = HttpRequest.builder()

View File

@ -0,0 +1,57 @@
/**
* 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 com.google.common.collect.ImmutableSet;
import org.jclouds.cloudstack.domain.Host;
import org.testng.annotations.Test;
import static org.jclouds.cloudstack.options.DeleteHostOptions.Builder.*;
import static org.testng.Assert.assertEquals;
/**
* Tests behavior of {@code DeleteHostOptions}
*
* @author Richard Downer
*/
@Test(groups = "unit")
public class DeleteHostOptionsTest {
public void testForced() {
DeleteHostOptions options = new DeleteHostOptions().forced(true);
assertEquals(ImmutableList.of("true"), options.buildQueryParameters().get("forced"));
}
public void testForcedStatic() {
DeleteHostOptions options = forced(true);
assertEquals(ImmutableList.of("true"), options.buildQueryParameters().get("forced"));
}
public void testForceDestroyLocalStorage() {
DeleteHostOptions options = new DeleteHostOptions().forceDestroyLocalStorage(true);
assertEquals(ImmutableList.of("true"), options.buildQueryParameters().get("forcedestroylocalstorage"));
}
public void testForceDestroyLocalStorageStatic() {
DeleteHostOptions options = forceDestroyLocalStorage(true);
assertEquals(ImmutableList.of("true"), options.buildQueryParameters().get("forcedestroylocalstorage"));
}
}