You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by Yavor Yanchev <ya...@yanchev.com> on 2015/07/16 15:25:10 UTC

Combination of image name and owner in AWS-EC2 AMI

Hi all,

How in Brooklyn do I select an AWS-EC2 AMI by matching on a combination 
of image name and owner?

The reason I need to do this is that the community Windows AMIs get 
regularly replaced, so I can't use just the imageId. However, there are 
image(s) in the marketplace that have very similar names, so I can't 
just rely on the image name.

Regards,
Yavor


Re: Combination of image name and owner in AWS-EC2 AMI

Posted by Aled Sage <al...@gmail.com>.
Hi Yavor,

Within our jclouds integration code (in 
ComputeServiceRegistryImpl.findComputeService) we have:

    properties.setProperty(PROPERTY_EC2_AMI_QUERY,
    "owner-id="+conf.getStringKey("imageOwner")+";state=available;image-type=machine");

(It's a bit ugly having the code there; would be nicer if that were a 
first-class property on jclouds' AWSEC2TemplateOptions. That's an 
improvement we could make in jclouds).

---
You can thus specify imageOwner in your location's configuration, along 
with the imageNameRegex.

For example, in brooklyn.properties:

    brooklyn.location.named.mywindows1=aws-ec2:us-east-1
    brooklyn.location.named.mywindows1.imageOwner=801119661308
    brooklyn.location.named.mywindows1.imageNameRegex=Windows_Server-2012-R2_RTM-English-64Bit-Base-.*

    # And with wrong imageOwner
    brooklyn.location.named.mywindows2=aws-ec2:us-east-1
    brooklyn.location.named.mywindows2.imageOwner=1234567890
    brooklyn.location.named.mywindows2.imageNameRegex=Windows_Server-2012-R2_RTM-English-64Bit-Base-.*

Then try running:

     > brooklyn cloud-compute default-template --location mywindows1

    Location {
         provider: aws-ec2
         displayName: AWS Virginia
         identity: AKIAJB4XYEF3QZHA2NIA
         region: us-east-1
         Default template {
             Image: {id=us-east-1/ami-5b9e6b30, providerId=ami-5b9e6b30,
    name=Windows_Server-2012-R2_RTM-English-64Bit-Base-2015.06.10,
    location={scope=REGION, id=us-east-1, description=us-east-1,
    parent=aws-ec2, iso3166Codes=[US-VA]}, os={family=windows, arch=hvm,
    version=,
    description=amazon/Windows_Server-2012-R2_RTM-English-64Bit-Base-2015.06.10,
    is64Bit=true}, description=Microsoft Windows Server 2012 R2 RTM
    64-bit Locale English AMI provided by Amazon, version=2015.06.10,
    status=AVAILABLE[available], loginUser=root,
    userMetadata={owner=801119661308, rootDeviceType=ebs,
    virtualizationType=hvm, hypervisor=xen}}
             Hardware: {id=t2.micro, providerId=t2.micro,
    processors=[{cores=1.0, speed=0.1}], ram=1024,
    supportsImage=Predicates.and(requiresRootDeviceType(ebs),requiresVirtualizationType(hvm),Predicates.alwaysTrue(),Predicates.alwaysTrue())}
             Location: {scope=REGION, id=us-east-1,
    description=us-east-1, parent=aws-ec2, iso3166Codes=[US-VA]}
             Options: {userDataCksum=06fee983}
         }
    }

Whereas with the wrong imageOwner, it fails:

     > brooklyn cloud-compute default-template --location mywindows2

    ...
    java.lang.IllegalStateException: Unable to match required VM
    template constraints PortableTemplateBuilder[ports=[22],
    locationId=us-east-1,
    imageNameRegex=Windows_Server-2012-R2_RTM-English-64Bit-Base-.*,
    imageChooserFunction=brooklyn.location.jclouds.BrooklynImageChooser$ImageChooserFromOrdering@6f0bc1b6]
    when trying to provision VM in JcloudsLocation[AWS
    Virginia:AKIAJB4XYEF3QZHA2NIA/aws-ec2:us-east-1@R26byq4u]; see list
    of images in log. Root cause: java.util.NoSuchElementException: no
    image matched predicate:
    Predicates.and(nullEqualToIsParentOrIsGrandparentOfCurrentLocation(),imageName(Windows_Server-2012-R2_RTM-English-64Bit-Base-.*))

Aled


On 16/07/2015 14:25, Yavor Yanchev wrote:
> Hi all,
>
> How in Brooklyn do I select an AWS-EC2 AMI by matching on a 
> combination of image name and owner?
>
> The reason I need to do this is that the community Windows AMIs get 
> regularly replaced, so I can't use just the imageId. However, there 
> are image(s) in the marketplace that have very similar names, so I 
> can't just rely on the image name.
>
> Regards,
> Yavor
>