mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
When setting del_root_vol_on_destroy, preserve the existing volumeType on the AMI
This commit is contained in:
parent
8b17c77d72
commit
8cef43c68d
1 changed files with 21 additions and 14 deletions
|
@ -1782,14 +1782,17 @@ def request_instance(vm_=None, call=None):
|
|||
# pull the root device name from the result and use it when
|
||||
# launching the new VM
|
||||
rd_name = None
|
||||
rd_type = None
|
||||
if 'blockDeviceMapping' in rd_data[0]:
|
||||
if rd_data[0]['blockDeviceMapping'] is None:
|
||||
# Some ami instances do not have a root volume. Ignore such cases
|
||||
rd_name = None
|
||||
elif isinstance(rd_data[0]['blockDeviceMapping']['item'], list):
|
||||
rd_name = rd_data[0]['blockDeviceMapping']['item'][0]['deviceName']
|
||||
else:
|
||||
rd_name = rd_data[0]['blockDeviceMapping']['item']['deviceName']
|
||||
# Some ami instances do not have a root volume. Ignore such cases
|
||||
if rd_data[0]['blockDeviceMapping'] is not None:
|
||||
item = rd_data[0]['blockDeviceMapping']['item']
|
||||
if isinstance(item, list):
|
||||
item = item[0]
|
||||
rd_name = item['deviceName']
|
||||
# Grab the volume type
|
||||
rd_type = item['ebs'].get('volumeType', None)
|
||||
|
||||
log.info('Found root device name: {0}'.format(rd_name))
|
||||
|
||||
if rd_name is not None:
|
||||
|
@ -1801,21 +1804,25 @@ def request_instance(vm_=None, call=None):
|
|||
dev_list = []
|
||||
|
||||
if rd_name in dev_list:
|
||||
# Device already listed, just grab the index
|
||||
dev_index = dev_list.index(rd_name)
|
||||
termination_key = '{0}BlockDeviceMapping.{1}.Ebs.DeleteOnTermination'.format(spot_prefix, dev_index)
|
||||
params[termination_key] = str(set_del_root_vol_on_destroy).lower()
|
||||
else:
|
||||
dev_index = len(dev_list)
|
||||
# Add the device name in since it wasn't already there
|
||||
params[
|
||||
'{0}BlockDeviceMapping.{1}.DeviceName'.format(
|
||||
spot_prefix, dev_index
|
||||
)
|
||||
] = rd_name
|
||||
params[
|
||||
'{0}BlockDeviceMapping.{1}.Ebs.DeleteOnTermination'.format(
|
||||
spot_prefix, dev_index
|
||||
)
|
||||
] = str(set_del_root_vol_on_destroy).lower()
|
||||
|
||||
# Set the termination value
|
||||
termination_key = '{0}BlockDeviceMapping.{1}.Ebs.DeleteOnTermination'.format(spot_prefix, dev_index)
|
||||
params[termination_key] = str(set_del_root_vol_on_destroy).lower()
|
||||
|
||||
# Preserve the volume type if specified
|
||||
if rd_type is not None:
|
||||
type_key = '{0}BlockDeviceMapping.{1}.Ebs.VolumeType'.format(spot_prefix, dev_index)
|
||||
params[type_key] = rd_type
|
||||
|
||||
set_del_all_vols_on_destroy = config.get_cloud_config_value(
|
||||
'del_all_vols_on_destroy', vm_, __opts__, search_global=False, default=False
|
||||
|
|
Loading…
Add table
Reference in a new issue