From c1dd80f9b36b7217006608bc03d3bb756eb2ef48 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Thu, 5 Apr 2012 18:15:39 -0700 Subject: [PATCH] openstack-nova-ec2 errors on authorizing security group to itself, and also needs to auto-allocate elastic ips --- .../nova/ec2/NovaEC2PropertiesBuilder.java | 4 ++ .../NovaEC2ComputeServiceContextModule.java | 3 + .../NovaCreateSecurityGroupIfNeeded.java | 55 +++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 apis/openstack-nova-ec2/src/main/java/org/jclouds/openstack/nova/ec2/loaders/NovaCreateSecurityGroupIfNeeded.java diff --git a/apis/openstack-nova-ec2/src/main/java/org/jclouds/openstack/nova/ec2/NovaEC2PropertiesBuilder.java b/apis/openstack-nova-ec2/src/main/java/org/jclouds/openstack/nova/ec2/NovaEC2PropertiesBuilder.java index fbf3a8a920..41c4b59a67 100644 --- a/apis/openstack-nova-ec2/src/main/java/org/jclouds/openstack/nova/ec2/NovaEC2PropertiesBuilder.java +++ b/apis/openstack-nova-ec2/src/main/java/org/jclouds/openstack/nova/ec2/NovaEC2PropertiesBuilder.java @@ -50,6 +50,10 @@ public class NovaEC2PropertiesBuilder extends EC2PropertiesBuilder { properties.setProperty(PROPERTY_RELAX_HOSTNAME, "true"); properties.setProperty(PROPERTY_TRUST_ALL_CERTS, "true"); properties.setProperty(PROPERTY_EC2_AUTO_ALLOCATE_ELASTIC_IPS, "true"); + // auth fail sometimes happens in EC2, as the rc.local script that injects the + // authorized key executes after ssh has started. + properties.setProperty("jclouds.ssh.max-retries", "7"); + properties.setProperty("jclouds.ssh.retry-auth", "true"); return properties; } diff --git a/apis/openstack-nova-ec2/src/main/java/org/jclouds/openstack/nova/ec2/config/NovaEC2ComputeServiceContextModule.java b/apis/openstack-nova-ec2/src/main/java/org/jclouds/openstack/nova/ec2/config/NovaEC2ComputeServiceContextModule.java index 5d2242ae67..5e8b50cd60 100644 --- a/apis/openstack-nova-ec2/src/main/java/org/jclouds/openstack/nova/ec2/config/NovaEC2ComputeServiceContextModule.java +++ b/apis/openstack-nova-ec2/src/main/java/org/jclouds/openstack/nova/ec2/config/NovaEC2ComputeServiceContextModule.java @@ -20,7 +20,9 @@ package org.jclouds.openstack.nova.ec2.config; import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.ec2.compute.config.EC2ComputeServiceContextModule; +import org.jclouds.ec2.compute.loaders.CreateSecurityGroupIfNeeded; import org.jclouds.ec2.compute.strategy.ReviseParsedImage; +import org.jclouds.openstack.nova.ec2.loaders.NovaCreateSecurityGroupIfNeeded; import org.jclouds.openstack.nova.ec2.strategy.NovaReviseParsedImage; import org.jclouds.openstack.nova.v1_1.compute.functions.ImageToOperatingSystem; @@ -39,6 +41,7 @@ public class NovaEC2ComputeServiceContextModule extends EC2ComputeServiceContext bind(new TypeLiteral>() { }).to(ImageToOperatingSystem.class); bind(ReviseParsedImage.class).to(NovaReviseParsedImage.class); + bind(CreateSecurityGroupIfNeeded.class).to(NovaCreateSecurityGroupIfNeeded.class); } } diff --git a/apis/openstack-nova-ec2/src/main/java/org/jclouds/openstack/nova/ec2/loaders/NovaCreateSecurityGroupIfNeeded.java b/apis/openstack-nova-ec2/src/main/java/org/jclouds/openstack/nova/ec2/loaders/NovaCreateSecurityGroupIfNeeded.java new file mode 100644 index 0000000000..c702534f8e --- /dev/null +++ b/apis/openstack-nova-ec2/src/main/java/org/jclouds/openstack/nova/ec2/loaders/NovaCreateSecurityGroupIfNeeded.java @@ -0,0 +1,55 @@ +/** + * 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.loaders; + +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.aws.AWSResponseException; +import org.jclouds.ec2.EC2Client; +import org.jclouds.ec2.compute.domain.RegionAndName; +import org.jclouds.ec2.compute.loaders.CreateSecurityGroupIfNeeded; + +import com.google.common.base.Predicate; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class NovaCreateSecurityGroupIfNeeded extends CreateSecurityGroupIfNeeded { + + @Inject + public NovaCreateSecurityGroupIfNeeded(EC2Client ec2Client, + @Named("SECURITY") Predicate securityGroupEventualConsistencyDelay) { + super(checkNotNull(ec2Client, "ec2Client").getSecurityGroupServices(), securityGroupEventualConsistencyDelay); + } + + protected void authorizeGroupToItself(String region, String name) { + try { + super.authorizeGroupToItself(region, name); + } catch (AWSResponseException e) { + logger.warn(e, "<< error authorizing securityGroup(%s)", name); + } + } + +}