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.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
|
||||
|
||||
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)
|
||||
@QueryParams(keys = "response", values = "json")
|
||||
/**
|
||||
* @author Vijay Kiran
|
||||
*/
|
||||
public interface SSHKeyPairAsyncClient {
|
||||
/**
|
||||
* @see org.jclouds.cloudstack.features.SSHKeyPairClient#listSSHKeyPairs
|
||||
* @see SSHKeyPairClient#listSSHKeyPairs
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "listSSHKeyPairs")
|
||||
|
@ -54,12 +60,18 @@ public interface SSHKeyPairAsyncClient {
|
|||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||
ListenableFuture<Set<SshKeyPair>> listSSHKeyPairs(ListSSHKeyPairsOptions... options);
|
||||
|
||||
/**
|
||||
* @see SSHKeyPairClient#createSSHKeyPair
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "createSSHKeyPair")
|
||||
@SelectJson("keypair")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
ListenableFuture<SshKeyPair> createSSHKeyPair(@QueryParam("name") String name);
|
||||
|
||||
/**
|
||||
* @see SSHKeyPairClient#getSSHKeyPair
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "listSSHKeyPairs")
|
||||
@SelectJson("keypair")
|
||||
|
@ -68,4 +80,12 @@ public interface SSHKeyPairAsyncClient {
|
|||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
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.
|
||||
* <p/>
|
||||
*
|
||||
* @author Vijay Kiran
|
||||
* @see <a href=
|
||||
* "http://download.cloud.com/releases/2.2.0/api_2.2.8/user/listSSHKeyPairs.html"
|
||||
* @see <a
|
||||
* href="http://download.cloud.com/releases/2.2.0/api_2.2.8/TOC_User.html"
|
||||
* />
|
||||
* @author Vijay Kiran
|
||||
*/
|
||||
@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS)
|
||||
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);
|
||||
|
||||
/**
|
||||
* Creates a {@link SshKeyPair} with specified name.
|
||||
*
|
||||
* @param name
|
||||
* of the SshKeyPair.
|
||||
* @return Created SshKeyPair.
|
||||
*/
|
||||
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);
|
||||
|
||||
/**
|
||||
* 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.http.HttpRequest;
|
||||
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
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
|
||||
protected TypeLiteral<RestAnnotationProcessor<SSHKeyPairAsyncClient>> createTypeLiteral() {
|
||||
return new TypeLiteral<RestAnnotationProcessor<SSHKeyPairAsyncClient>>() {
|
||||
|
|
|
@ -33,6 +33,9 @@ import org.testng.annotations.Test;
|
|||
@Test(groups = "live", singleThreaded = true, testName = "SSHKeyPairClientLiveTest")
|
||||
public class SSHKeyPairClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||
|
||||
protected String prefix = System.getProperty("user.name");
|
||||
private SshKeyPair sshKeyPair;
|
||||
|
||||
public void testListSSHKeyPairs() {
|
||||
final Set<SshKeyPair> sshKeyPairs = client.getSSHKeyPairClient().listSSHKeyPairs();
|
||||
for (SshKeyPair sshKeyPair : sshKeyPairs) {
|
||||
|
@ -40,9 +43,13 @@ public class SSHKeyPairClientLiveTest extends BaseCloudStackClientLiveTest {
|
|||
}
|
||||
}
|
||||
|
||||
public void testCreateSSHKeyPair() {
|
||||
final SshKeyPair sshKeyPair = client.getSSHKeyPairClient().createSSHKeyPair("jclouds-keypair");
|
||||
System.out.println(sshKeyPair);
|
||||
public void testCreateDeleteSSHKeyPair() {
|
||||
sshKeyPair = client.getSSHKeyPairClient().createSSHKeyPair(prefix + "jclouds-keypair");
|
||||
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) {
|
||||
|
|
Loading…
Reference in New Issue