When using the amazon-ec2 gem method "describe_images", if both :owner_id and :image_id are specified, it means that it will only fetch information about images matching :image_id that are owned by owner :owner_id. Unfortunately, this means public AMI's are excluded. In the case where we know the image_id, don't set the owner_id; the number of responses can only be 0 (meaning that image_id wasn't found) or 1 (meaning that image_id was found), so it shouldn't pose a performance problem. With this in place I was able to start an EC2 instance from a public AMI.
Signed-off-by: Chris Lalancette clalance@redhat.com --- server/lib/deltacloud/drivers/ec2/ec2_driver.rb | 11 ++++++++--- 1 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb index 3134469..c8b26cc 100644 --- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb +++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb @@ -99,9 +99,14 @@ class EC2Driver < Deltacloud::BaseDriver def images(credentials, opts={} ) ec2 = new_client(credentials) img_arr = [] - config = { :owner_id => "amazon" } - config.merge!({ :owner_id => opts[:owner_id] }) if opts and opts[:owner_id] - config.merge!({ :image_id => opts[:id] }) if opts and opts[:id] + # if we know the image_id, we don't want to limit by owner_id, since this + # will exclude public images + if (opts and opts[:id]) + config = { :image_id => opts[:id] } + else + config = { :owner_id => "amazon" } + config.merge!({ :owner_id => opts[:owner_id] }) if opts and opts[:owner_id] + end safely do ec2.describe_images(config).imagesSet.item.each do |image| img_arr << convert_image(image)
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 05/05/2010 07:36 PM, Chris Lalancette wrote:
Signed-off-by: Chris Lalancette clalance@redhat.com
server/lib/deltacloud/drivers/ec2/ec2_driver.rb | 11 ++++++++--- 1 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb index 3134469..c8b26cc 100644 --- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb +++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb @@ -99,9 +99,14 @@ class EC2Driver < Deltacloud::BaseDriver def images(credentials, opts={} ) ec2 = new_client(credentials) img_arr = []
- config = { :owner_id => "amazon" }
- config.merge!({ :owner_id => opts[:owner_id] }) if opts and opts[:owner_id]
- config.merge!({ :image_id => opts[:id] }) if opts and opts[:id]
- # if we know the image_id, we don't want to limit by owner_id, since this
- # will exclude public images
- if (opts and opts[:id])
config = { :image_id => opts[:id] }
- else
config = { :owner_id => "amazon" }
config.merge!({ :owner_id => opts[:owner_id] }) if opts and opts[:owner_id]
- end safely do ec2.describe_images(config).imagesSet.item.each do |image| img_arr << convert_image(image)
ACK.
- Michal
- -- - -------------------------------------------------------- Michal Fojtik, mfojtik@redhat.com, +420 532 294 4307 Ruby / Ruby On Rails Developer Deltacloud API: http://deltacloud.org - --------------------------------------------------------
deltacloud-devel@lists.fedorahosted.org