[Block Device] Add block device mapping to launch config backend
This commit is contained in:
parent
912c3ceb39
commit
a0e48a6cf5
3 changed files with 149 additions and 2 deletions
|
|
@ -1,6 +1,7 @@
|
|||
from jinja2 import Template
|
||||
|
||||
from moto.core.responses import BaseResponse
|
||||
from moto.core.utils import camelcase_to_underscores
|
||||
from .models import autoscaling_backend
|
||||
|
||||
|
||||
|
|
@ -17,6 +18,21 @@ class AutoScalingResponse(BaseResponse):
|
|||
def _get_multi_param(self, param_prefix):
|
||||
return [value[0] for key, value in self.querystring.items() if key.startswith(param_prefix)]
|
||||
|
||||
def _get_list_prefix(self, param_prefix):
|
||||
results = []
|
||||
param_index = 1
|
||||
while True:
|
||||
index_prefix = "{0}.{1}.".format(param_prefix, param_index)
|
||||
new_items = {}
|
||||
for key, value in self.querystring.items():
|
||||
if key.startswith(index_prefix):
|
||||
new_items[camelcase_to_underscores(key.replace(index_prefix, ""))] = value[0]
|
||||
if not new_items:
|
||||
break
|
||||
results.append(new_items)
|
||||
param_index += 1
|
||||
return results
|
||||
|
||||
def create_launch_configuration(self):
|
||||
instance_monitoring_string = self._get_param('InstanceMonitoring.Enabled')
|
||||
if instance_monitoring_string == 'true':
|
||||
|
|
@ -35,6 +51,7 @@ class AutoScalingResponse(BaseResponse):
|
|||
spot_price=self._get_param('SpotPrice'),
|
||||
ebs_optimized=self._get_param('EbsOptimized'),
|
||||
associate_public_ip_address=self._get_param("AssociatePublicIpAddress"),
|
||||
block_device_mappings=self._get_list_prefix('BlockDeviceMappings.member')
|
||||
)
|
||||
template = Template(CREATE_LAUNCH_CONFIGURATION_TEMPLATE)
|
||||
return template.render()
|
||||
|
|
@ -173,7 +190,34 @@ DESCRIBE_LAUNCH_CONFIGURATIONS_TEMPLATE = """<DescribeLaunchConfigurationsRespon
|
|||
<InstanceType>m1.small</InstanceType>
|
||||
<LaunchConfigurationARN>arn:aws:autoscaling:us-east-1:803981987763:launchConfiguration:
|
||||
9dbbbf87-6141-428a-a409-0752edbe6cad:launchConfigurationName/my-test-lc</LaunchConfigurationARN>
|
||||
<BlockDeviceMappings/>
|
||||
{% if launch_configuration.block_device_mappings %}
|
||||
<BlockDeviceMappings>
|
||||
{% for mount_point, mapping in launch_configuration.block_device_mappings.iteritems() %}
|
||||
<member>
|
||||
<DeviceName>{{ mount_point }}</DeviceName>
|
||||
{% if mapping.ephemeral_name %}
|
||||
<VirtualName>{{ mapping.ephemeral_name }}</VirtualName>
|
||||
{% else %}
|
||||
<Ebs>
|
||||
{% if mapping.snapshot_id %}
|
||||
<SnapshotId>{{ mapping.snapshot_id }}</SnapshotId>
|
||||
{% endif %}
|
||||
{% if mapping.size %}
|
||||
<VolumeSize>{{ mapping.size }}</VolumeSize>
|
||||
{% endif %}
|
||||
{% if mapping.iops %}
|
||||
<Iops>{{ mapping.iops }}</Iops>
|
||||
{% endif %}
|
||||
<DeleteOnTermination>{{ mapping.delete_on_termination }}</DeleteOnTermination>
|
||||
<VolumeType>{{ mapping.volume_type }}</VolumeType>
|
||||
</Ebs>
|
||||
{% endif %}
|
||||
</member>
|
||||
{% endfor %}
|
||||
</BlockDeviceMappings>
|
||||
{% else %}
|
||||
<BlockDeviceMappings/>
|
||||
{% endif %}
|
||||
<ImageId>{{ launch_configuration.image_id }}</ImageId>
|
||||
{% if launch_configuration.key_name %}
|
||||
<KeyName>{{ launch_configuration.key_name }}</KeyName>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue