Allow EC2 to list images based on owner

This commit is contained in:
Joseph Hall 2013-12-13 19:46:38 -07:00
parent 9137d3d15d
commit ddfaffa090
2 changed files with 45 additions and 2 deletions

View File

@ -418,6 +418,36 @@ configuration file:
rename_on_destroy: True
Listing Images
==============
Normally, images can be queried on a cloud provider by passing the
``--list-images`` argument to Salt Cloud. This still holds true for EC2:
.. code-block:: bash
salt-cloud --list-images my-ec2-config
However, the full list of images on EC2 is extremely large, and querying all of
the available images may cause Salt Cloud to behave as if frozen. Therefore,
the default behavior of this option may be modified, by adding an ``owner``
argument to the provider configuration:
.. code-block:: yaml
owner: aws-marketplace
The possible values for this setting are ``amazon``, ``aws-marketplace``,
``self``, ``<AWS account ID>`` or ``all``. The default setting is ``amazon``.
It is also possible to perform this query using different settings without
modifying the configuration files. To do this, call the ``avail_images``
function directly:
.. code-block:: bash
salt-cloud -f avail_images my-ec2-config owner=aws-marketplace
EC2 Images
==========
The following are lists of available AMI images, generally sorted by OS. These

View File

@ -530,12 +530,25 @@ def avail_sizes():
return sizes
def avail_images():
def avail_images(kwargs=None, call=None):
'''
Return a dict of all available VM images on the cloud provider.
'''
if type(kwargs) is not dict:
kwargs = {}
if 'owner' in kwargs:
owner = kwargs['owner']
else:
provider = get_configured_provider()
owner = config.get_cloud_config_value(
'owner', provider, __opts__, default='amazon'
)
ret = {}
params = {'Action': 'DescribeImages'}
params = {'Action': 'DescribeImages',
'Owner': owner}
images = query(params)
for image in images:
ret[image['imageId']] = image