diff --git a/moto/ec2/models.py b/moto/ec2/models.py index 92b26697c..4ae2c00c3 100644 --- a/moto/ec2/models.py +++ b/moto/ec2/models.py @@ -2527,6 +2527,17 @@ class DHCPOptionsSetBackend(object): raise InvalidDHCPOptionsIdError(options_id) return True + def get_all_dhcp_options(self, dhcp_options_ids=None, filters=None): + dhcp_options_sets = self.dhcp_options_sets.values() + + if dhcp_options_ids: + dhcp_options_sets = [dhcp_options_set for dhcp_options_set in dhcp_options_sets if dhcp_options_set.id in dhcp_options_ids] + if len(dhcp_options_sets) != len(dhcp_options_ids): + invalid_id = list(set(dhcp_options_ids).difference(set([dhcp_options_set.id for dhcp_options_set in dhcp_options_sets])))[0] + raise InvalidDHCPOptionsIdError(invalid_id) + + return generic_filter(filters, dhcp_options_sets) + class VPNConnection(TaggedEC2Resource): def __init__(self, ec2_backend, id, type, diff --git a/moto/ec2/responses/dhcp_options.py b/moto/ec2/responses/dhcp_options.py index a3a454a86..57d16a015 100644 --- a/moto/ec2/responses/dhcp_options.py +++ b/moto/ec2/responses/dhcp_options.py @@ -1,8 +1,9 @@ from __future__ import unicode_literals from moto.core.responses import BaseResponse from moto.ec2.utils import ( - dhcp_configuration_from_querystring, - sequence_from_querystring) + filters_from_querystring, + sequence_from_querystring, + dhcp_configuration_from_querystring) class DHCPOptions(BaseResponse): @@ -47,15 +48,12 @@ class DHCPOptions(BaseResponse): return template.render(delete_status=delete_status) def describe_dhcp_options(self): - if "Filter.1.Name" in self.querystring: + dhcp_opt_ids = sequence_from_querystring("DhcpOptionsId", self.querystring) + if filters_from_querystring(self.querystring): raise NotImplementedError("Filtering not supported in describe_dhcp_options.") - elif "DhcpOptionsId.1" in self.querystring: - dhcp_opt_ids = sequence_from_querystring("DhcpOptionsId", self.querystring) - dhcp_opt = self.ec2_backend.describe_dhcp_options(dhcp_opt_ids) - else: - dhcp_opt = self.ec2_backend.describe_dhcp_options() + dhcp_opts = self.ec2_backend.get_all_dhcp_options(dhcp_opt_ids, None) template = self.response_template(DESCRIBE_DHCP_OPTIONS_RESPONSE) - return template.render(dhcp_options=dhcp_opt) + return template.render(dhcp_options=dhcp_opts) CREATE_DHCP_OPTIONS_RESPONSE = u""" @@ -104,16 +102,16 @@ DELETE_DHCP_OPTIONS_RESPONSE = u""" DESCRIBE_DHCP_OPTIONS_RESPONSE = u""" 7a62c49f-347e-4fc4-9331-6e8eEXAMPLE - - {% for dhcp_options_set in dhcp_options %} - + + {% for dhcp_options_set in dhcp_options %} + {{ dhcp_options_set.id }} {% for key, values in dhcp_options_set.options.items() %} {{ values }} {% if values %} - {{key}} + {{ key }} {% for value in values %} @@ -135,9 +133,9 @@ DESCRIBE_DHCP_OPTIONS_RESPONSE = u""" {% endfor %} - - {% endfor %} - + + {% endfor %} + """