diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2PropertiesBuilder.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2PropertiesBuilder.java index 4126123015..b2f0e9e4d9 100644 --- a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2PropertiesBuilder.java +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2PropertiesBuilder.java @@ -83,10 +83,12 @@ public class AWSEC2PropertiesBuilder extends org.jclouds.ec2.EC2PropertiesBuilde if (props.containsKey(PROPERTY_EC2_AMI_OWNERS)) { StringBuilder query = new StringBuilder(); String owners = properties.remove(PROPERTY_EC2_AMI_OWNERS).toString(); - if (!"*".equals(owners) && !"".equals(owners)) - query.append("owner-id=").append(owners).append(';'); - if (!"".equals(owners)) + if ("*".equals(owners)) query.append("state=available;image-type=machine"); + else if (!"".equals(owners)) + query.append("owner-id=").append(owners).append(";state=available;image-type=machine"); + else if ("".equals(owners)) + query = new StringBuilder(); props.setProperty(PROPERTY_EC2_AMI_QUERY, query.toString()); Logger.getAnonymousLogger().warning( String.format("Property %s is deprecated, please use new syntax: %s=%s", PROPERTY_EC2_AMI_OWNERS, @@ -97,7 +99,7 @@ public class AWSEC2PropertiesBuilder extends org.jclouds.ec2.EC2PropertiesBuilde protected void warnAndReplaceIfUsingOldCCImageKey(Properties props) { if (props.containsKey(PROPERTY_EC2_CC_AMIs)) { String amis = properties.remove(PROPERTY_EC2_CC_AMIs).toString(); - String value = "image-id=" + amis.replace("us-east-1/", ""); + String value = ("".equals(amis)) ? "" : "image-id=" + amis.replace("us-east-1/", ""); props.setProperty(PROPERTY_EC2_CC_AMI_QUERY, value); Logger.getAnonymousLogger().warning( String.format("Property %s is deprecated, please use new syntax: %s=%s", PROPERTY_EC2_CC_AMIs, diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2TemplateBuilderLiveTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2TemplateBuilderLiveTest.java index 459f94a515..406ea0d600 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2TemplateBuilderLiveTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2TemplateBuilderLiveTest.java @@ -37,6 +37,7 @@ import org.jclouds.compute.domain.Template; import org.jclouds.ec2.compute.predicates.EC2ImagePredicates; import org.jclouds.ec2.domain.InstanceType; import org.jclouds.ec2.domain.RootDeviceType; +import org.jclouds.ec2.reference.EC2Constants; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.testng.annotations.Test; @@ -243,6 +244,42 @@ public class AWSEC2TemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { } } + @Test + public void testTemplateBuilderWithNoOwnersParsesImageOnDemandDeprecated() throws IOException { + ComputeServiceContext context = null; + try { + Properties overrides = setupProperties(); + // set owners to nothing + overrides.setProperty(AWSEC2Constants.PROPERTY_EC2_CC_AMIs, ""); + overrides.setProperty(EC2Constants.PROPERTY_EC2_AMI_OWNERS, ""); + + context = new ComputeServiceContextFactory().createContext(provider, ImmutableSet + . of(new Log4JLoggingModule()), overrides); + + assertEquals(context.getComputeService().listImages().size(), 0); + + Template template = context.getComputeService().templateBuilder().imageId("us-east-1/ami-ccb35ea5").build(); + System.out.println(template.getHardware()); + assert (template.getImage().getProviderId().startsWith("ami-")) : template; + assertEquals(template.getImage().getOperatingSystem().getVersion(), "5.4"); + assertEquals(template.getImage().getOperatingSystem().is64Bit(), true); + assertEquals(template.getImage().getOperatingSystem().getFamily(), OsFamily.CENTOS); + assertEquals(template.getImage().getVersion(), "4.4.10"); + assertEquals(template.getImage().getUserMetadata().get("rootDeviceType"), "instance-store"); + assertEquals(template.getLocation().getId(), "us-east-1"); + assertEquals(getCores(template.getHardware()), 2.0d); + assertEquals(template.getHardware().getId(), "m1.large"); // because it + // is 64bit + + // ensure we cache the new image for next time + assertEquals(context.getComputeService().listImages().size(), 1); + + } finally { + if (context != null) + context.close(); + } + } + @Test public void testTemplateBuilderWithLessRegions() throws IOException { ComputeServiceContext context = null;