Adding Support for Get All DHCP Options
add DescribeDhcpOptionsResponse support filtering describe_dhcp_options add get_all_dhcp_options
This commit is contained in:
parent
32dd72f6b7
commit
41873b59f7
@ -2511,6 +2511,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 NetworkAclBackend(object):
|
||||
def __init__(self):
|
||||
|
@ -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,
|
||||
dhcp_opt_ids_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 = dhcp_opt_ids_from_querystring(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"""
|
||||
<DescribeDhcpOptionsResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-15/">
|
||||
<requestId>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</requestId>
|
||||
<item>
|
||||
{% for dhcp_options_set in dhcp_options %}
|
||||
<dhcpOptions>
|
||||
<dhcpOptionsSet>
|
||||
{% for dhcp_options_set in dhcp_options %}
|
||||
<item>
|
||||
<dhcpOptionsId>{{ dhcp_options_set.id }}</dhcpOptionsId>
|
||||
<dhcpConfigurationSet>
|
||||
{% for key, values in dhcp_options_set.options.items() %}
|
||||
{{ values }}
|
||||
{% if values %}
|
||||
<item>
|
||||
<key>{{key}}</key>
|
||||
<key>{{ key }}</key>
|
||||
<valueSet>
|
||||
{% for value in values %}
|
||||
<item>
|
||||
@ -135,9 +133,9 @@ DESCRIBE_DHCP_OPTIONS_RESPONSE = u"""
|
||||
</item>
|
||||
{% endfor %}
|
||||
</tagSet>
|
||||
</dhcpOptions>
|
||||
{% endfor %}
|
||||
</item>
|
||||
</item>
|
||||
{% endfor %}
|
||||
</dhcpOptionsSet>
|
||||
</DescribeDhcpOptionsResponse>
|
||||
"""
|
||||
|
||||
|
@ -185,6 +185,14 @@ def network_acl_ids_from_querystring(querystring_dict):
|
||||
return network_acl_ids
|
||||
|
||||
|
||||
def dhcp_opt_ids_from_querystring(querystring_dict):
|
||||
dhcp_opt_ids = []
|
||||
for key, value in querystring_dict.items():
|
||||
if 'DhcpOptionsId' in key:
|
||||
dhcp_opt_ids.append(value[0])
|
||||
return dhcp_opt_ids
|
||||
|
||||
|
||||
def vpc_ids_from_querystring(querystring_dict):
|
||||
vpc_ids = []
|
||||
for key, value in querystring_dict.items():
|
||||
|
Loading…
Reference in New Issue
Block a user