summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKenny Woodson <kwoodson@redhat.com>2015-01-29 15:21:12 -0500
committerKenny Woodson <kwoodson@redhat.com>2015-01-29 15:21:12 -0500
commit4ed3d1e3c8051bc0b76b098d2848460355e46cc6 (patch)
tree29a686e964877e3738bb8d6830a31ba432b801c8
parent37ddb5a297c5b71fc6caf021853b3dfa562b068c (diff)
parent2272985a2dde3201bc5c2a6db617edaaa7c98534 (diff)
downloadopenshift-4ed3d1e3c8051bc0b76b098d2848460355e46cc6.tar.gz
openshift-4ed3d1e3c8051bc0b76b098d2848460355e46cc6.tar.bz2
openshift-4ed3d1e3c8051bc0b76b098d2848460355e46cc6.tar.xz
openshift-4ed3d1e3c8051bc0b76b098d2848460355e46cc6.zip
Merge pull request #49 from kwoodson/filters
Adding filtering capabilities to oo_select ansible filtering.
-rw-r--r--filter_plugins/oo_filters.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/filter_plugins/oo_filters.py b/filter_plugins/oo_filters.py
index 703506b88..b57056375 100644
--- a/filter_plugins/oo_filters.py
+++ b/filter_plugins/oo_filters.py
@@ -31,10 +31,16 @@ def get_attr(data, attribute=None):
return ptr
-def oo_collect(data, attribute=None):
+def oo_collect(data, attribute=None, filters={}):
''' This takes a list of dict and collects all attributes specified into a list
- Ex: data = [ {'a':1,'b':5}, {'a':2}, {'a':3} ]
+ If filter is specified then we will include all items that match _ALL_ of filters.
+ Ex: data = [ {'a':1, 'b':5, 'z': 'z'}, # True, return
+ {'a':2, 'z': 'z'}, # True, return
+ {'a':3, 'z': 'z'}, # True, return
+ {'a':4, 'z': 'b'}, # FAILED, obj['z'] != obj['z']
+ ]
attribute = 'a'
+ filters = {'z': 'z'}
returns [1, 2, 3]
'''
@@ -44,7 +50,10 @@ def oo_collect(data, attribute=None):
if not attribute:
raise errors.AnsibleFilterError("|failed expects attribute to be set")
- retval = [get_attr(d, attribute) for d in data]
+ if filters:
+ retval = [get_attr(d, attribute) for d in data if all([ d[key] == filters[key] for key in filters ]) ]
+ else:
+ retval = [get_attr(d, attribute) for d in data]
return retval