mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 08:58:59 +00:00
Merge pull request #46715 from pakdel/ec2_image_name
Salt Cloud EC2: Image Name
This commit is contained in:
commit
c3bcc27712
@ -721,6 +721,28 @@ them have never been used, much less tested, by the Salt Stack team.
|
|||||||
.. __: https://aws.amazon.com/marketplace
|
.. __: https://aws.amazon.com/marketplace
|
||||||
|
|
||||||
|
|
||||||
|
NOTE: If ``image`` of a profile does not start with ``ami-``, latest
|
||||||
|
image with that name will be used. For example, to create a CentOS 7
|
||||||
|
profile, instead of using the AMI like ``image: ami-1caef165``, we
|
||||||
|
can use its name like ``image: 'CentOS Linux 7 x86_64 HVM EBS ENA 1803_01'``.
|
||||||
|
We can also use a pattern like below to get the latest CentOS 7:
|
||||||
|
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
profile-id:
|
||||||
|
provider: provider-name
|
||||||
|
subnetid: subnet-XXXXXXXX
|
||||||
|
image: 'CentOS Linux 7 x86_64 HVM EBS *'
|
||||||
|
size: m1.medium
|
||||||
|
ssh_username: centos
|
||||||
|
securitygroupid:
|
||||||
|
- sg-XXXXXXXX
|
||||||
|
securitygroupname:
|
||||||
|
- AnotherSecurityGroup
|
||||||
|
- AndThirdSecurityGroup
|
||||||
|
|
||||||
|
|
||||||
show_image
|
show_image
|
||||||
==========
|
==========
|
||||||
This is a function that describes an AMI on EC2. This will give insight as to
|
This is a function that describes an AMI on EC2. This will give insight as to
|
||||||
|
@ -1191,6 +1191,33 @@ def get_tenancy(vm_):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def get_imageid(vm_):
|
||||||
|
'''
|
||||||
|
Returns the ImageId to use
|
||||||
|
'''
|
||||||
|
image = config.get_cloud_config_value(
|
||||||
|
'image', vm_, __opts__, search_global=False
|
||||||
|
)
|
||||||
|
if image.startswith('ami-'):
|
||||||
|
return image
|
||||||
|
# a poor man's cache
|
||||||
|
if not hasattr(get_imageid, 'images'):
|
||||||
|
get_imageid.images = {}
|
||||||
|
elif image in get_imageid.images:
|
||||||
|
return get_imageid.images[image]
|
||||||
|
params = {'Action': 'DescribeImages',
|
||||||
|
'Filter.0.Name': 'name',
|
||||||
|
'Filter.0.Value.0': image}
|
||||||
|
# Query AWS, sort by 'creationDate' and get the last imageId
|
||||||
|
_t = lambda x: datetime.datetime.strptime(x['creationDate'], '%Y-%m-%dT%H:%M:%S.%fZ')
|
||||||
|
image_id = sorted(aws.query(params, location=get_location(),
|
||||||
|
provider=get_provider(), opts=__opts__, sigver='4'),
|
||||||
|
lambda i, j: cmp(_t(i), _t(j))
|
||||||
|
)[-1]['imageId']
|
||||||
|
get_imageid.images[image] = image_id
|
||||||
|
return image_id
|
||||||
|
|
||||||
|
|
||||||
def _get_subnetname_id(subnetname):
|
def _get_subnetname_id(subnetname):
|
||||||
'''
|
'''
|
||||||
Returns the SubnetId of a SubnetName to use
|
Returns the SubnetId of a SubnetName to use
|
||||||
@ -1774,7 +1801,7 @@ def request_instance(vm_=None, call=None):
|
|||||||
# Normal instances should have no prefix.
|
# Normal instances should have no prefix.
|
||||||
spot_prefix = ''
|
spot_prefix = ''
|
||||||
|
|
||||||
image_id = vm_['image']
|
image_id = get_imageid(vm_)
|
||||||
params[spot_prefix + 'ImageId'] = image_id
|
params[spot_prefix + 'ImageId'] = image_id
|
||||||
|
|
||||||
userdata = None
|
userdata = None
|
||||||
|
Loading…
Reference in New Issue
Block a user