refactored properties objects to be consistent w/keystone

This commit is contained in:
Adrian Cole 2012-03-27 10:22:13 -07:00
parent b18e61ae7a
commit c56043db08
5 changed files with 46 additions and 34 deletions

View File

@ -20,9 +20,10 @@ package org.jclouds.openstack.nova.v1_1;
import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import static org.jclouds.openstack.nova.v1_1.reference.NovaConstants.PROPERTY_NOVA_AUTO_ALLOCATE_FLOATING_IPS;
import static org.jclouds.openstack.nova.v1_1.reference.NovaConstants.PROPERTY_NOVA_AUTO_GENERATE_KEYPAIRS;
import static org.jclouds.openstack.nova.v1_1.reference.NovaConstants.PROPERTY_NOVA_TIMEOUT_SECURITYGROUP_PRESENT;
import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.SERVICE_TYPE;
import static org.jclouds.openstack.nova.v1_1.config.NovaProperties.AUTO_ALLOCATE_FLOATING_IPS;
import static org.jclouds.openstack.nova.v1_1.config.NovaProperties.AUTO_GENERATE_KEYPAIRS;
import static org.jclouds.openstack.nova.v1_1.config.NovaProperties.TIMEOUT_SECURITYGROUP_PRESENT;
import java.util.Properties;
@ -40,13 +41,18 @@ public class NovaPropertiesBuilder extends PropertiesBuilder {
protected Properties defaultProperties() {
Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_ENDPOINT, "http://localhost:5000");
properties.setProperty(KeystoneProperties.SERVICE_TYPE, ServiceType.COMPUTE);
properties.setProperty(PROPERTY_API_VERSION, "1.1");
// auth fail can happen while cloud-init applies keypair updates
properties.setProperty("jclouds.ssh.max-retries", "7");
properties.setProperty("jclouds.ssh.retry-auth", "true");
properties.setProperty(SERVICE_TYPE, ServiceType.COMPUTE);
// TODO: this doesn't actually do anything yet.
properties.setProperty(KeystoneProperties.VERSION, "2.0");
properties.setProperty(PROPERTY_API_VERSION, "1.1");
properties.setProperty(PROPERTY_NOVA_AUTO_ALLOCATE_FLOATING_IPS, "false");
properties.setProperty(PROPERTY_NOVA_AUTO_GENERATE_KEYPAIRS, "false");
properties.setProperty(PROPERTY_NOVA_TIMEOUT_SECURITYGROUP_PRESENT, "500");
properties.setProperty(AUTO_ALLOCATE_FLOATING_IPS, "false");
properties.setProperty(AUTO_GENERATE_KEYPAIRS, "false");
properties.setProperty(TIMEOUT_SECURITYGROUP_PRESENT, "500");
return properties;
}

View File

@ -18,6 +18,10 @@
*/
package org.jclouds.openstack.nova.v1_1.compute.config;
import static org.jclouds.openstack.nova.v1_1.config.NovaProperties.AUTO_ALLOCATE_FLOATING_IPS;
import static org.jclouds.openstack.nova.v1_1.config.NovaProperties.AUTO_GENERATE_KEYPAIRS;
import static org.jclouds.openstack.nova.v1_1.config.NovaProperties.TIMEOUT_SECURITYGROUP_PRESENT;
import java.security.SecureRandom;
import java.util.Map;
import java.util.Set;
@ -45,7 +49,13 @@ import org.jclouds.openstack.nova.v1_1.NovaAsyncClient;
import org.jclouds.openstack.nova.v1_1.NovaClient;
import org.jclouds.openstack.nova.v1_1.compute.NovaComputeService;
import org.jclouds.openstack.nova.v1_1.compute.NovaComputeServiceAdapter;
import org.jclouds.openstack.nova.v1_1.compute.functions.*;
import org.jclouds.openstack.nova.v1_1.compute.functions.CreateSecurityGroupIfNeeded;
import org.jclouds.openstack.nova.v1_1.compute.functions.CreateUniqueKeyPair;
import org.jclouds.openstack.nova.v1_1.compute.functions.FlavorInZoneToHardware;
import org.jclouds.openstack.nova.v1_1.compute.functions.ImageInZoneToImage;
import org.jclouds.openstack.nova.v1_1.compute.functions.ImageToOperatingSystem;
import org.jclouds.openstack.nova.v1_1.compute.functions.OrphanedGroupsByZoneId;
import org.jclouds.openstack.nova.v1_1.compute.functions.ServerInZoneToNodeMetadata;
import org.jclouds.openstack.nova.v1_1.compute.loaders.FindKeyPairOrCreate;
import org.jclouds.openstack.nova.v1_1.compute.loaders.FindSecurityGroupOrCreate;
import org.jclouds.openstack.nova.v1_1.compute.loaders.LoadFloatingIpsForInstance;
@ -60,7 +70,6 @@ import org.jclouds.openstack.nova.v1_1.domain.zonescoped.ZoneAndId;
import org.jclouds.openstack.nova.v1_1.domain.zonescoped.ZoneAndName;
import org.jclouds.openstack.nova.v1_1.domain.zonescoped.ZoneSecurityGroupNameAndPorts;
import org.jclouds.openstack.nova.v1_1.predicates.FindSecurityGroupWithNameAndReturnTrue;
import org.jclouds.openstack.nova.v1_1.reference.NovaConstants;
import org.jclouds.predicates.RetryablePredicate;
import com.google.common.base.Function;
@ -143,9 +152,9 @@ public class NovaComputeServiceContextModule
protected TemplateOptions provideTemplateOptions(Injector injector, TemplateOptions options) {
return options.as(NovaTemplateOptions.class)
.autoAssignFloatingIp(injector.getInstance(
Key.get(boolean.class, Names.named(NovaConstants.PROPERTY_NOVA_AUTO_ALLOCATE_FLOATING_IPS))))
Key.get(boolean.class, Names.named(AUTO_ALLOCATE_FLOATING_IPS))))
.generateKeyPair(injector.getInstance(
Key.get(boolean.class, Names.named(NovaConstants.PROPERTY_NOVA_AUTO_GENERATE_KEYPAIRS))));
Key.get(boolean.class, Names.named(AUTO_GENERATE_KEYPAIRS))));
}
@Provides
@ -174,7 +183,7 @@ public class NovaComputeServiceContextModule
@Named("SECURITY")
protected Predicate<AtomicReference<ZoneAndName>> securityGroupEventualConsistencyDelay(
FindSecurityGroupWithNameAndReturnTrue in,
@Named(NovaConstants.PROPERTY_NOVA_TIMEOUT_SECURITYGROUP_PRESENT) long msDelay) {
@Named(TIMEOUT_SECURITYGROUP_PRESENT) long msDelay) {
return new RetryablePredicate<AtomicReference<ZoneAndName>>(in, msDelay, 100l, TimeUnit.MILLISECONDS);
}

View File

@ -16,30 +16,30 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.openstack.nova.v1_1.reference;
package org.jclouds.openstack.nova.v1_1.config;
/**
* Configuration properties and constants used in openstack Nova connections.
*
* @author Adam Lowe
*/
public class NovaConstants {
public class NovaProperties {
/**
* Eventual consistency delay for retrieving a security group after it is created (in ms)
*/
public static final String PROPERTY_NOVA_TIMEOUT_SECURITYGROUP_PRESENT = "jclouds.openstack-nova.timeout.securitygroup-present";
public static final String TIMEOUT_SECURITYGROUP_PRESENT = "jclouds.openstack-nova.timeout.securitygroup-present";
/**
* Whenever a node is created, automatically allocate and assign a floating ip address, also
* deallocate when the node is destroyed.
*/
public static final String PROPERTY_NOVA_AUTO_ALLOCATE_FLOATING_IPS = "jclouds.openstack-nova.auto-allocate-floating-ips";
public static final String AUTO_ALLOCATE_FLOATING_IPS = "jclouds.openstack-nova.auto-allocate-floating-ips";
/**
* Whenever a node is created, automatically generate keypairs for groups, as needed, also
* delete the keypair(s) when the last node in the group is destroyed.
*/
public static final String PROPERTY_NOVA_AUTO_GENERATE_KEYPAIRS = "jclouds.openstack-nova.auto-generate-keypairs";
public static final String AUTO_GENERATE_KEYPAIRS = "jclouds.openstack-nova.auto-generate-keypairs";
}

View File

@ -21,8 +21,8 @@ package org.jclouds.hpcloud.compute;
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import static org.jclouds.Constants.PROPERTY_ISO3166_CODES;
import static org.jclouds.compute.reference.ComputeServiceConstants.PROPERTY_TIMEOUT_NODE_TERMINATED;
import static org.jclouds.openstack.nova.v1_1.reference.NovaConstants.PROPERTY_NOVA_AUTO_ALLOCATE_FLOATING_IPS;
import static org.jclouds.openstack.nova.v1_1.reference.NovaConstants.PROPERTY_NOVA_AUTO_GENERATE_KEYPAIRS;
import static org.jclouds.openstack.nova.v1_1.config.NovaProperties.AUTO_ALLOCATE_FLOATING_IPS;
import static org.jclouds.openstack.nova.v1_1.config.NovaProperties.AUTO_GENERATE_KEYPAIRS;
import java.util.Properties;
@ -39,13 +39,12 @@ public class HPCloudComputePropertiesBuilder extends NovaPropertiesBuilder {
Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_ISO3166_CODES, "US-NV");
properties.setProperty(PROPERTY_ENDPOINT, "https://region-a.geo-1.identity.hpcloudsvc.com:35357");
properties.setProperty(PROPERTY_NOVA_AUTO_ALLOCATE_FLOATING_IPS, "true");
// auth fail can happen while cloud-init applies keypair updates
properties.setProperty("jclouds.ssh.max-retries", "7");
properties.setProperty("jclouds.ssh.retry-auth", "true");
properties.setProperty(PROPERTY_NOVA_AUTO_GENERATE_KEYPAIRS, "true");
// deallocating ip addresses can take a while
properties.setProperty(PROPERTY_TIMEOUT_NODE_TERMINATED, 60 * 1000 + "");
properties.setProperty(AUTO_ALLOCATE_FLOATING_IPS, "true");
properties.setProperty(AUTO_GENERATE_KEYPAIRS, "true");
return properties;
}

View File

@ -20,12 +20,12 @@ package org.jclouds.trystack.nova;
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import static org.jclouds.Constants.PROPERTY_ISO3166_CODES;
import static org.jclouds.openstack.nova.v1_1.reference.NovaConstants.PROPERTY_NOVA_AUTO_GENERATE_KEYPAIRS;
import static org.jclouds.Constants.PROPERTY_TRUST_ALL_CERTS;
import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.CREDENTIAL_TYPE;
import static org.jclouds.openstack.nova.v1_1.config.NovaProperties.AUTO_GENERATE_KEYPAIRS;
import java.util.Properties;
import org.jclouds.Constants;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties;
import org.jclouds.openstack.nova.v1_1.NovaPropertiesBuilder;
/**
@ -39,12 +39,10 @@ public class TryStackNovaPropertiesBuilder extends NovaPropertiesBuilder {
Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_ISO3166_CODES, "US-CA");
properties.setProperty(PROPERTY_ENDPOINT, "https://nova-api.trystack.org:5443");
properties.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
properties.setProperty(KeystoneProperties.CREDENTIAL_TYPE, "passwordCredentials");
// auth fail can happen while cloud-init applies keypair updates
properties.setProperty("jclouds.ssh.max-retries", "7");
properties.setProperty("jclouds.ssh.retry-auth", "true");
properties.setProperty(PROPERTY_NOVA_AUTO_GENERATE_KEYPAIRS, "true");
properties.setProperty(PROPERTY_TRUST_ALL_CERTS, "true");
properties.setProperty(CREDENTIAL_TYPE, "passwordCredentials");
properties.setProperty(AUTO_GENERATE_KEYPAIRS, "true");
return properties;
}