Merge pull request #466 from EarthmanT/support_get_all_dhcp_options_set

Adding Support for Get All DHCP Options
This commit is contained in:
Steve Pulec 2015-12-21 15:18:41 -05:00
commit 42423f47e7
2 changed files with 25 additions and 16 deletions

View File

@ -2527,6 +2527,17 @@ class DHCPOptionsSetBackend(object):
raise InvalidDHCPOptionsIdError(options_id) raise InvalidDHCPOptionsIdError(options_id)
return True 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): class VPNConnection(TaggedEC2Resource):
def __init__(self, ec2_backend, id, type, def __init__(self, ec2_backend, id, type,

View File

@ -1,8 +1,9 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from moto.core.responses import BaseResponse from moto.core.responses import BaseResponse
from moto.ec2.utils import ( from moto.ec2.utils import (
dhcp_configuration_from_querystring, filters_from_querystring,
sequence_from_querystring) sequence_from_querystring,
dhcp_configuration_from_querystring)
class DHCPOptions(BaseResponse): class DHCPOptions(BaseResponse):
@ -47,15 +48,12 @@ class DHCPOptions(BaseResponse):
return template.render(delete_status=delete_status) return template.render(delete_status=delete_status)
def describe_dhcp_options(self): def describe_dhcp_options(self):
if "Filter.1.Name" in 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_ids = sequence_from_querystring("DhcpOptionsId", self.querystring)
dhcp_opt = self.ec2_backend.describe_dhcp_options(dhcp_opt_ids) if filters_from_querystring(self.querystring):
else: raise NotImplementedError("Filtering not supported in describe_dhcp_options.")
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) 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""" CREATE_DHCP_OPTIONS_RESPONSE = u"""
@ -104,16 +102,16 @@ DELETE_DHCP_OPTIONS_RESPONSE = u"""
DESCRIBE_DHCP_OPTIONS_RESPONSE = u""" DESCRIBE_DHCP_OPTIONS_RESPONSE = u"""
<DescribeDhcpOptionsResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-15/"> <DescribeDhcpOptionsResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-15/">
<requestId>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</requestId> <requestId>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</requestId>
<item> <dhcpOptionsSet>
{% for dhcp_options_set in dhcp_options %} {% for dhcp_options_set in dhcp_options %}
<dhcpOptions> <item>
<dhcpOptionsId>{{ dhcp_options_set.id }}</dhcpOptionsId> <dhcpOptionsId>{{ dhcp_options_set.id }}</dhcpOptionsId>
<dhcpConfigurationSet> <dhcpConfigurationSet>
{% for key, values in dhcp_options_set.options.items() %} {% for key, values in dhcp_options_set.options.items() %}
{{ values }} {{ values }}
{% if values %} {% if values %}
<item> <item>
<key>{{key}}</key> <key>{{ key }}</key>
<valueSet> <valueSet>
{% for value in values %} {% for value in values %}
<item> <item>
@ -135,9 +133,9 @@ DESCRIBE_DHCP_OPTIONS_RESPONSE = u"""
</item> </item>
{% endfor %} {% endfor %}
</tagSet> </tagSet>
</dhcpOptions>
{% endfor %}
</item> </item>
{% endfor %}
</dhcpOptionsSet>
</DescribeDhcpOptionsResponse> </DescribeDhcpOptionsResponse>
""" """