Use filters attribute rather than eni id so facts can be filtered on much more. Matches the new ec2_vpc_route_table_facts and ec2_vpc_subnet_facts modules

reviewable/pr18780/r1
whiter 9 years ago
parent 15480e3d04
commit 62cd2d9c18

@ -22,11 +22,12 @@ description:
version_added: "2.0" version_added: "2.0"
author: "Rob White (@wimnat)" author: "Rob White (@wimnat)"
options: options:
eni_id: filters:
description: description:
- The ID of the ENI. Pass this option to gather facts about a particular ENI, otherwise, all ENIs are returned. - A dict of filters to apply. Each dict item consists of a filter key and a filter value. See U(http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeNetworkInterfaces.html) for possible filters.
required: false required: false
default: null default: null
extends_documentation_fragment: extends_documentation_fragment:
- aws - aws
- ec2 - ec2
@ -40,12 +41,11 @@ EXAMPLES = '''
# Gather facts about a particular ENI # Gather facts about a particular ENI
- ec2_eni_facts: - ec2_eni_facts:
eni_id: eni-xxxxxxx filters:
network-interface-id: eni-xxxxxxx
''' '''
import xml.etree.ElementTree as ET
try: try:
import boto.ec2 import boto.ec2
from boto.exception import BotoServerError from boto.exception import BotoServerError
@ -53,14 +53,6 @@ try:
except ImportError: except ImportError:
HAS_BOTO = False HAS_BOTO = False
def get_error_message(xml_string):
root = ET.fromstring(xml_string)
for message in root.findall('.//Message'):
return message.text
def get_eni_info(interface): def get_eni_info(interface):
interface_info = {'id': interface.id, interface_info = {'id': interface.id,
@ -89,13 +81,13 @@ def get_eni_info(interface):
def list_eni(connection, module): def list_eni(connection, module):
eni_id = module.params.get("eni_id") filters = module.params.get("filters")
interface_dict_array = [] interface_dict_array = []
try: try:
all_eni = connection.get_all_network_interfaces(eni_id) all_eni = connection.get_all_network_interfaces(filters=filters)
except BotoServerError as e: except BotoServerError as e:
module.fail_json(msg=get_error_message(e.args[2])) module.fail_json(msg=e.message)
for interface in all_eni: for interface in all_eni:
interface_dict_array.append(get_eni_info(interface)) interface_dict_array.append(get_eni_info(interface))
@ -107,7 +99,7 @@ def main():
argument_spec = ec2_argument_spec() argument_spec = ec2_argument_spec()
argument_spec.update( argument_spec.update(
dict( dict(
eni_id = dict(default=None) filters = dict(default=None, type='dict')
) )
) )
@ -131,4 +123,5 @@ def main():
from ansible.module_utils.basic import * from ansible.module_utils.basic import *
from ansible.module_utils.ec2 import * from ansible.module_utils.ec2 import *
main() if __name__ == '__main__':
main()

Loading…
Cancel
Save