mirror of https://github.com/apache/jclouds.git
Fixes for SSHKeyPair implementation
- Updated JavaDoc - Added API Method for deleteSSHKeyPair. - Updated test to delete Key pair.
This commit is contained in:
parent
e1d41bd8b6
commit
c1b1061712
|
@ -35,17 +35,23 @@ import org.jclouds.rest.annotations.RequestFilters;
|
||||||
import org.jclouds.rest.annotations.SelectJson;
|
import org.jclouds.rest.annotations.SelectJson;
|
||||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||||
|
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
|
||||||
|
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides asynchronous access to CloudStack SSHKeyPair features.
|
||||||
|
*
|
||||||
|
* @author Vijay Kiran
|
||||||
|
* @see <a
|
||||||
|
* href="http://download.cloud.com/releases/2.2.0/api_2.2.8/TOC_User.html"
|
||||||
|
* />
|
||||||
|
*/
|
||||||
@RequestFilters(QuerySigner.class)
|
@RequestFilters(QuerySigner.class)
|
||||||
@QueryParams(keys = "response", values = "json")
|
@QueryParams(keys = "response", values = "json")
|
||||||
/**
|
|
||||||
* @author Vijay Kiran
|
|
||||||
*/
|
|
||||||
public interface SSHKeyPairAsyncClient {
|
public interface SSHKeyPairAsyncClient {
|
||||||
/**
|
/**
|
||||||
* @see org.jclouds.cloudstack.features.SSHKeyPairClient#listSSHKeyPairs
|
* @see SSHKeyPairClient#listSSHKeyPairs
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@QueryParams(keys = "command", values = "listSSHKeyPairs")
|
@QueryParams(keys = "command", values = "listSSHKeyPairs")
|
||||||
|
@ -54,12 +60,18 @@ public interface SSHKeyPairAsyncClient {
|
||||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||||
ListenableFuture<Set<SshKeyPair>> listSSHKeyPairs(ListSSHKeyPairsOptions... options);
|
ListenableFuture<Set<SshKeyPair>> listSSHKeyPairs(ListSSHKeyPairsOptions... options);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see SSHKeyPairClient#createSSHKeyPair
|
||||||
|
*/
|
||||||
@GET
|
@GET
|
||||||
@QueryParams(keys = "command", values = "createSSHKeyPair")
|
@QueryParams(keys = "command", values = "createSSHKeyPair")
|
||||||
@SelectJson("keypair")
|
@SelectJson("keypair")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
ListenableFuture<SshKeyPair> createSSHKeyPair(@QueryParam("name") String name);
|
ListenableFuture<SshKeyPair> createSSHKeyPair(@QueryParam("name") String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see SSHKeyPairClient#getSSHKeyPair
|
||||||
|
*/
|
||||||
@GET
|
@GET
|
||||||
@QueryParams(keys = "command", values = "listSSHKeyPairs")
|
@QueryParams(keys = "command", values = "listSSHKeyPairs")
|
||||||
@SelectJson("keypair")
|
@SelectJson("keypair")
|
||||||
|
@ -68,4 +80,12 @@ public interface SSHKeyPairAsyncClient {
|
||||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||||
ListenableFuture<SshKeyPair> getSSHKeyPair(@QueryParam("name") String name);
|
ListenableFuture<SshKeyPair> getSSHKeyPair(@QueryParam("name") String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see SSHKeyPairClient#deleteSSHKeyPair
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@QueryParams(keys = "command", values = "deleteSSHKeyPair")
|
||||||
|
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
|
||||||
|
ListenableFuture<Void> deleteSSHKeyPair(@QueryParam("name") String name);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,19 +28,49 @@ import org.jclouds.concurrent.Timeout;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides synchronous access to CloudStack SSHKeyPair features.
|
* Provides synchronous access to CloudStack SSHKeyPair features.
|
||||||
* <p/>
|
|
||||||
*
|
*
|
||||||
* @author Vijay Kiran
|
* @see <a
|
||||||
* @see <a href=
|
* href="http://download.cloud.com/releases/2.2.0/api_2.2.8/TOC_User.html"
|
||||||
* "http://download.cloud.com/releases/2.2.0/api_2.2.8/user/listSSHKeyPairs.html"
|
|
||||||
* />
|
* />
|
||||||
|
* @author Vijay Kiran
|
||||||
*/
|
*/
|
||||||
@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS)
|
@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS)
|
||||||
public interface SSHKeyPairClient {
|
public interface SSHKeyPairClient {
|
||||||
|
/**
|
||||||
|
* Returns a list of {@link SshKeyPair}s registered by current user.
|
||||||
|
*
|
||||||
|
* @param options
|
||||||
|
* if present, how to constrain the list
|
||||||
|
* @return Set of {@link SshKeyPair}s matching the current constrains or
|
||||||
|
* empty set if no SshKeyPairs found.
|
||||||
|
*/
|
||||||
Set<SshKeyPair> listSSHKeyPairs(ListSSHKeyPairsOptions... options);
|
Set<SshKeyPair> listSSHKeyPairs(ListSSHKeyPairsOptions... options);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a {@link SshKeyPair} with specified name.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* of the SshKeyPair.
|
||||||
|
* @return Created SshKeyPair.
|
||||||
|
*/
|
||||||
SshKeyPair createSSHKeyPair(String name);
|
SshKeyPair createSSHKeyPair(String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the {@link SSHKeyPairClient} with given name.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* name of the key pair
|
||||||
|
* @return SSH Key pair or null if not found.
|
||||||
|
*/
|
||||||
SshKeyPair getSSHKeyPair(String name);
|
SshKeyPair getSSHKeyPair(String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the {@link SSHKeyPairClient} with given name.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* name of the key pair
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
void deleteSSHKeyPair(String name);
|
||||||
|
|
||||||
}
|
}
|
|
@ -25,8 +25,10 @@ import org.jclouds.cloudstack.options.ListSSHKeyPairsOptions;
|
||||||
import org.jclouds.functions.IdentityFunction;
|
import org.jclouds.functions.IdentityFunction;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
||||||
|
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||||
|
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
|
||||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -93,6 +95,23 @@ public class SSHKeyPairAsyncClientTest extends BaseCloudStackAsyncClientTest<SSH
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testDeleteSSHKeyPair() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
|
Method method = SSHKeyPairAsyncClient.class.getMethod("deleteSSHKeyPair", String.class);
|
||||||
|
HttpRequest httpRequest = processor.createRequest(method, "jclouds-keypair");
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest,
|
||||||
|
"GET http://localhost:8080/client/api?response=json&command=deleteSSHKeyPair&name=jclouds-keypair HTTP/1.1");
|
||||||
|
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null, null, false);
|
||||||
|
|
||||||
|
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
|
||||||
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
|
||||||
|
|
||||||
|
checkFilters(httpRequest);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected TypeLiteral<RestAnnotationProcessor<SSHKeyPairAsyncClient>> createTypeLiteral() {
|
protected TypeLiteral<RestAnnotationProcessor<SSHKeyPairAsyncClient>> createTypeLiteral() {
|
||||||
return new TypeLiteral<RestAnnotationProcessor<SSHKeyPairAsyncClient>>() {
|
return new TypeLiteral<RestAnnotationProcessor<SSHKeyPairAsyncClient>>() {
|
||||||
|
|
|
@ -33,6 +33,9 @@ import org.testng.annotations.Test;
|
||||||
@Test(groups = "live", singleThreaded = true, testName = "SSHKeyPairClientLiveTest")
|
@Test(groups = "live", singleThreaded = true, testName = "SSHKeyPairClientLiveTest")
|
||||||
public class SSHKeyPairClientLiveTest extends BaseCloudStackClientLiveTest {
|
public class SSHKeyPairClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||||
|
|
||||||
|
protected String prefix = System.getProperty("user.name");
|
||||||
|
private SshKeyPair sshKeyPair;
|
||||||
|
|
||||||
public void testListSSHKeyPairs() {
|
public void testListSSHKeyPairs() {
|
||||||
final Set<SshKeyPair> sshKeyPairs = client.getSSHKeyPairClient().listSSHKeyPairs();
|
final Set<SshKeyPair> sshKeyPairs = client.getSSHKeyPairClient().listSSHKeyPairs();
|
||||||
for (SshKeyPair sshKeyPair : sshKeyPairs) {
|
for (SshKeyPair sshKeyPair : sshKeyPairs) {
|
||||||
|
@ -40,9 +43,13 @@ public class SSHKeyPairClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCreateSSHKeyPair() {
|
public void testCreateDeleteSSHKeyPair() {
|
||||||
final SshKeyPair sshKeyPair = client.getSSHKeyPairClient().createSSHKeyPair("jclouds-keypair");
|
sshKeyPair = client.getSSHKeyPairClient().createSSHKeyPair(prefix + "jclouds-keypair");
|
||||||
System.out.println(sshKeyPair);
|
checkSSHKeyPair(sshKeyPair);
|
||||||
|
client.getSSHKeyPairClient().deleteSSHKeyPair(sshKeyPair.getName());
|
||||||
|
assertEquals(client.getSSHKeyPairClient().getSSHKeyPair(sshKeyPair.getName()), null);
|
||||||
|
// Set the keypair to null , if the delete test is passed.
|
||||||
|
sshKeyPair = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void checkSSHKeyPair(SshKeyPair pair) {
|
protected void checkSSHKeyPair(SshKeyPair pair) {
|
||||||
|
|
Loading…
Reference in New Issue