add extattrs as an option when using nios lookup (#35371)

This commit is contained in:
Peter Sprygada 2018-01-26 06:33:44 -05:00 committed by GitHub
parent 0fb916c35e
commit f849dc9cad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -44,6 +44,10 @@ options:
description: a dict object that is used to filter the return objects
required: False
default: null
extattrs:
descrpition: a dict object that is used to filter on extattrs
required: false
default: null
"""
EXAMPLES = """
@ -93,6 +97,7 @@ obj_type:
from ansible.plugins.lookup import LookupBase
from ansible.module_utils.net_tools.nios.api import nios_provider_spec
from ansible.module_utils.net_tools.nios.api import get_connector
from ansible.module_utils.net_tools.nios.api import normalize_extattrs, flatten_extattrs
from ansible.errors import AnsibleError
@ -106,6 +111,11 @@ class LookupModule(LookupBase):
return_fields = kwargs.pop('return_fields', None)
filter_data = kwargs.pop('filter', {})
extattrs = normalize_extattrs(kwargs.pop('extattrs', {}))
provider = kwargs.pop('provider', {})
connector = get_connector(**provider)
return connector.get_object(obj_type, filter_data, return_fields=return_fields)
res = connector.get_object(obj_type, filter_data, return_fields=return_fields)
for obj in res:
if 'extattrs' in obj:
obj['extattrs'] = flatten_extattrs(obj['extattrs'])
return res