mirror of https://github.com/apache/jclouds.git
openstack-nova-ec2: adding NovaEC2KeyPairClient with importKeyPair method and wiring it into rest context
This commit is contained in:
parent
204194ad61
commit
05521685cd
|
@ -29,8 +29,6 @@ import java.util.Properties;
|
||||||
|
|
||||||
import org.jclouds.apis.ApiMetadata;
|
import org.jclouds.apis.ApiMetadata;
|
||||||
import org.jclouds.ec2.EC2ApiMetadata;
|
import org.jclouds.ec2.EC2ApiMetadata;
|
||||||
import org.jclouds.ec2.EC2AsyncClient;
|
|
||||||
import org.jclouds.ec2.EC2Client;
|
|
||||||
import org.jclouds.ec2.compute.config.EC2ResolveImagesModule;
|
import org.jclouds.ec2.compute.config.EC2ResolveImagesModule;
|
||||||
import org.jclouds.openstack.nova.ec2.config.NovaEC2ComputeServiceContextModule;
|
import org.jclouds.openstack.nova.ec2.config.NovaEC2ComputeServiceContextModule;
|
||||||
import org.jclouds.openstack.nova.ec2.config.NovaEC2RestClientModule;
|
import org.jclouds.openstack.nova.ec2.config.NovaEC2RestClientModule;
|
||||||
|
@ -48,10 +46,10 @@ import com.google.inject.Module;
|
||||||
public class NovaEC2ApiMetadata extends EC2ApiMetadata {
|
public class NovaEC2ApiMetadata extends EC2ApiMetadata {
|
||||||
|
|
||||||
/** The serialVersionUID */
|
/** The serialVersionUID */
|
||||||
private static final long serialVersionUID = -1492951757032303845L;
|
private static final long serialVersionUID = -8539835226183747429L;
|
||||||
|
|
||||||
public static final TypeToken<RestContext<EC2Client, EC2AsyncClient>> CONTEXT_TOKEN = new TypeToken<RestContext<EC2Client, EC2AsyncClient>>() {
|
public static final TypeToken<RestContext<NovaEC2Client, NovaEC2AsyncClient>> CONTEXT_TOKEN = new TypeToken<RestContext<NovaEC2Client, NovaEC2AsyncClient>>() {
|
||||||
private static final long serialVersionUID = -5070937833892503232L;
|
private static final long serialVersionUID = -6449920293625658712L;
|
||||||
};
|
};
|
||||||
|
|
||||||
private static Builder builder() {
|
private static Builder builder() {
|
||||||
|
@ -90,12 +88,13 @@ public class NovaEC2ApiMetadata extends EC2ApiMetadata {
|
||||||
|
|
||||||
public static class Builder extends EC2ApiMetadata.Builder {
|
public static class Builder extends EC2ApiMetadata.Builder {
|
||||||
protected Builder(){
|
protected Builder(){
|
||||||
super(EC2Client.class, EC2AsyncClient.class);
|
super(NovaEC2Client.class, NovaEC2AsyncClient.class);
|
||||||
id("openstack-nova-ec2")
|
id("openstack-nova-ec2")
|
||||||
.name("OpenStack Nova's EC2-clone API")
|
.name("OpenStack Nova's EC2-clone API")
|
||||||
.version("2009-04-04")
|
.version("2009-04-04")
|
||||||
.defaultEndpoint("http://localhost:8773/services/Cloud")
|
.defaultEndpoint("http://localhost:8773/services/Cloud")
|
||||||
.defaultProperties(NovaEC2ApiMetadata.defaultProperties())
|
.defaultProperties(NovaEC2ApiMetadata.defaultProperties())
|
||||||
|
.context(CONTEXT_TOKEN)
|
||||||
.defaultModules(ImmutableSet.<Class<? extends Module>>of(NovaEC2RestClientModule.class, EC2ResolveImagesModule.class, NovaEC2ComputeServiceContextModule.class));
|
.defaultModules(ImmutableSet.<Class<? extends Module>>of(NovaEC2RestClientModule.class, EC2ResolveImagesModule.class, NovaEC2ComputeServiceContextModule.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
/**
|
||||||
|
* 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.openstack.nova.ec2;
|
||||||
|
|
||||||
|
import org.jclouds.ec2.EC2AsyncClient;
|
||||||
|
import org.jclouds.openstack.nova.ec2.services.NovaEC2KeyPairAsyncClient;
|
||||||
|
import org.jclouds.rest.annotations.Delegate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides asynchronous access to EC2 services.
|
||||||
|
*
|
||||||
|
* @author Adam Lowe
|
||||||
|
*/
|
||||||
|
public interface NovaEC2AsyncClient extends EC2AsyncClient {
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Delegate
|
||||||
|
@Override
|
||||||
|
NovaEC2KeyPairAsyncClient getKeyPairServices();
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
/**
|
||||||
|
* 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.openstack.nova.ec2;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import org.jclouds.concurrent.Timeout;
|
||||||
|
import org.jclouds.ec2.EC2Client;
|
||||||
|
import org.jclouds.openstack.nova.ec2.services.NovaEC2KeyPairClient;
|
||||||
|
import org.jclouds.rest.annotations.Delegate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides synchronous access to EC2 services.
|
||||||
|
*
|
||||||
|
* @author Adam Lowe
|
||||||
|
*/
|
||||||
|
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
|
||||||
|
public interface NovaEC2Client extends EC2Client {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Delegate
|
||||||
|
@Override
|
||||||
|
NovaEC2KeyPairClient getKeyPairServices();
|
||||||
|
}
|
|
@ -18,9 +18,14 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.nova.ec2.config;
|
package org.jclouds.openstack.nova.ec2.config;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.ec2.EC2AsyncClient;
|
import org.jclouds.ec2.EC2AsyncClient;
|
||||||
import org.jclouds.ec2.EC2Client;
|
import org.jclouds.ec2.EC2Client;
|
||||||
import org.jclouds.ec2.config.EC2RestClientModule;
|
import org.jclouds.ec2.config.EC2RestClientModule;
|
||||||
|
import org.jclouds.ec2.services.*;
|
||||||
import org.jclouds.ec2.suppliers.DescribeAvailabilityZonesInRegion;
|
import org.jclouds.ec2.suppliers.DescribeAvailabilityZonesInRegion;
|
||||||
import org.jclouds.ec2.xml.CreateVolumeResponseHandler;
|
import org.jclouds.ec2.xml.CreateVolumeResponseHandler;
|
||||||
import org.jclouds.ec2.xml.DescribeImagesResponseHandler;
|
import org.jclouds.ec2.xml.DescribeImagesResponseHandler;
|
||||||
|
@ -28,10 +33,17 @@ import org.jclouds.location.config.LocationModule;
|
||||||
import org.jclouds.location.suppliers.RegionIdToZoneIdsSupplier;
|
import org.jclouds.location.suppliers.RegionIdToZoneIdsSupplier;
|
||||||
import org.jclouds.location.suppliers.ZoneIdsSupplier;
|
import org.jclouds.location.suppliers.ZoneIdsSupplier;
|
||||||
import org.jclouds.location.suppliers.derived.ZoneIdsFromRegionIdToZoneIdsValues;
|
import org.jclouds.location.suppliers.derived.ZoneIdsFromRegionIdToZoneIdsValues;
|
||||||
|
import org.jclouds.openstack.nova.ec2.NovaEC2AsyncClient;
|
||||||
|
import org.jclouds.openstack.nova.ec2.NovaEC2Client;
|
||||||
|
import org.jclouds.openstack.nova.ec2.services.NovaEC2KeyPairAsyncClient;
|
||||||
|
import org.jclouds.openstack.nova.ec2.services.NovaEC2KeyPairClient;
|
||||||
import org.jclouds.openstack.nova.ec2.xml.NovaCreateVolumeResponseHandler;
|
import org.jclouds.openstack.nova.ec2.xml.NovaCreateVolumeResponseHandler;
|
||||||
import org.jclouds.openstack.nova.ec2.xml.NovaDescribeImagesResponseHandler;
|
import org.jclouds.openstack.nova.ec2.xml.NovaDescribeImagesResponseHandler;
|
||||||
import org.jclouds.rest.ConfiguresRestClient;
|
import org.jclouds.rest.ConfiguresRestClient;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.google.common.reflect.TypeToken;
|
||||||
|
import com.google.inject.Provides;
|
||||||
import com.google.inject.Scopes;
|
import com.google.inject.Scopes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -40,7 +52,21 @@ import com.google.inject.Scopes;
|
||||||
* @author Adam Lowe
|
* @author Adam Lowe
|
||||||
*/
|
*/
|
||||||
@ConfiguresRestClient
|
@ConfiguresRestClient
|
||||||
public class NovaEC2RestClientModule extends EC2RestClientModule<EC2Client, EC2AsyncClient> {
|
public class NovaEC2RestClientModule extends EC2RestClientModule<NovaEC2Client, NovaEC2AsyncClient> {
|
||||||
|
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()//
|
||||||
|
.put(AMIClient.class, AMIAsyncClient.class)//
|
||||||
|
.put(ElasticIPAddressClient.class, ElasticIPAddressAsyncClient.class)//
|
||||||
|
.put(InstanceClient.class, InstanceAsyncClient.class)//
|
||||||
|
.put(NovaEC2KeyPairClient.class, NovaEC2KeyPairAsyncClient.class)//
|
||||||
|
.put(SecurityGroupClient.class, SecurityGroupAsyncClient.class)//
|
||||||
|
.put(WindowsClient.class, WindowsAsyncClient.class)//
|
||||||
|
.put(AvailabilityZoneAndRegionClient.class, AvailabilityZoneAndRegionAsyncClient.class)//
|
||||||
|
.put(ElasticBlockStoreClient.class, ElasticBlockStoreAsyncClient.class)//
|
||||||
|
.build();
|
||||||
|
|
||||||
|
public NovaEC2RestClientModule() {
|
||||||
|
super(TypeToken.of(NovaEC2Client.class), TypeToken.of(NovaEC2AsyncClient.class), DELEGATE_MAP);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
|
@ -57,4 +83,16 @@ public class NovaEC2RestClientModule extends EC2RestClientModule<EC2Client, EC2A
|
||||||
// there is only one region, and its endpoint is the same as the provider
|
// there is only one region, and its endpoint is the same as the provider
|
||||||
bind(ZoneIdsSupplier.class).to(ZoneIdsFromRegionIdToZoneIdsValues.class).in(Scopes.SINGLETON);
|
bind(ZoneIdsSupplier.class).to(ZoneIdsFromRegionIdToZoneIdsValues.class).in(Scopes.SINGLETON);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Provides
|
||||||
|
EC2Client provide(NovaEC2Client in) {
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Provides
|
||||||
|
EC2AsyncClient provide(NovaEC2AsyncClient in) {
|
||||||
|
return in;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
/**
|
||||||
|
* 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.openstack.nova.ec2.services;
|
||||||
|
|
||||||
|
import static org.jclouds.aws.reference.FormParameters.ACTION;
|
||||||
|
|
||||||
|
import javax.ws.rs.FormParam;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
|
||||||
|
import org.jclouds.aws.filters.FormSigner;
|
||||||
|
import org.jclouds.ec2.domain.KeyPair;
|
||||||
|
import org.jclouds.ec2.functions.EncodedRSAPublicKeyToBase64;
|
||||||
|
import org.jclouds.ec2.services.KeyPairAsyncClient;
|
||||||
|
import org.jclouds.ec2.xml.KeyPairResponseHandler;
|
||||||
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
|
import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull;
|
||||||
|
import org.jclouds.rest.annotations.EndpointParam;
|
||||||
|
import org.jclouds.rest.annotations.FormParams;
|
||||||
|
import org.jclouds.rest.annotations.ParamParser;
|
||||||
|
import org.jclouds.rest.annotations.RequestFilters;
|
||||||
|
import org.jclouds.rest.annotations.VirtualHost;
|
||||||
|
import org.jclouds.rest.annotations.XMLResponseParser;
|
||||||
|
|
||||||
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@RequestFilters(FormSigner.class)
|
||||||
|
@VirtualHost
|
||||||
|
public interface NovaEC2KeyPairAsyncClient extends KeyPairAsyncClient {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see NovaEC2KeyPairClient#importKeyPairInRegion(String, String, String)
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Path("/")
|
||||||
|
@FormParams(keys = ACTION, values = "ImportKeyPair")
|
||||||
|
@XMLResponseParser(KeyPairResponseHandler.class)
|
||||||
|
ListenableFuture<KeyPair> importKeyPairInRegion(
|
||||||
|
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region,
|
||||||
|
@FormParam("KeyName") String keyName,
|
||||||
|
@FormParam("PublicKeyMaterial") @ParamParser(EncodedRSAPublicKeyToBase64.class) String publicKeyMaterial);
|
||||||
|
}
|
|
@ -0,0 +1,69 @@
|
||||||
|
/**
|
||||||
|
* 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.openstack.nova.ec2.services;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import org.jclouds.concurrent.Timeout;
|
||||||
|
import org.jclouds.ec2.domain.KeyPair;
|
||||||
|
import org.jclouds.ec2.services.KeyPairClient;
|
||||||
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Timeout(duration = 90, timeUnit = TimeUnit.SECONDS)
|
||||||
|
public interface NovaEC2KeyPairClient extends KeyPairClient {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Imports the public key from an RSA key pair that you created with a third-party tool. Compare
|
||||||
|
* this with CreateKeyPair, in which AWS creates the key pair and gives the keys to you (Nova
|
||||||
|
* keeps a copy of the public key). With ImportKeyPair, you create the key pair and give Nova just
|
||||||
|
* the public key. The private key is never transferred between you and Nova.
|
||||||
|
*
|
||||||
|
* <p/>
|
||||||
|
* You can easily create an RSA key pair on Windows and Linux using the ssh-keygen command line
|
||||||
|
* tool (provided with the standard OpenSSH installation). Standard library support for RSA key
|
||||||
|
* pair creation is also available in Java, Ruby, Python, and many other programming languages.
|
||||||
|
*
|
||||||
|
* <p/>
|
||||||
|
* <h4>Supported Formats</h4>
|
||||||
|
* <ul>
|
||||||
|
* <li>OpenSSH public key format (e.g., the format in ~/.ssh/authorized_keys)</li>
|
||||||
|
* <li>Base64 encoded DER format</li>
|
||||||
|
* <li>SSH public key file format as specified in RFC4716</li>
|
||||||
|
* </ul>
|
||||||
|
* DSA keys are not supported. Make sure your key generator is set up to create RSA keys.
|
||||||
|
* <p/>
|
||||||
|
* Supported lengths: 1024, 2048, and 4096.
|
||||||
|
* <p/>
|
||||||
|
*
|
||||||
|
* @param region
|
||||||
|
* region to import the key into
|
||||||
|
* @param keyName
|
||||||
|
* A unique name for the key pair. Accepts alphanumeric characters, spaces, dashes, and
|
||||||
|
* underscores.
|
||||||
|
* @param publicKeyMaterial
|
||||||
|
* The public key
|
||||||
|
* @return imported key including fingerprint
|
||||||
|
*/
|
||||||
|
KeyPair importKeyPairInRegion(@Nullable String region, String keyName, String publicKeyMaterial);
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue