summaryrefslogtreecommitdiffstats
path: root/filter_plugins
diff options
context:
space:
mode:
authorKenny Woodson <kwoodson@redhat.com>2014-09-16 13:15:48 -0400
committerKenny Woodson <kwoodson@redhat.com>2014-09-16 13:15:48 -0400
commit5994dee9a8b3b1ee97f9e3b3529fd32ffb896187 (patch)
tree4c17abdd1e5b39e845d33d7d970ac216a82d766d /filter_plugins
downloadopenshift-5994dee9a8b3b1ee97f9e3b3529fd32ffb896187.tar.gz
openshift-5994dee9a8b3b1ee97f9e3b3529fd32ffb896187.tar.bz2
openshift-5994dee9a8b3b1ee97f9e3b3529fd32ffb896187.tar.xz
openshift-5994dee9a8b3b1ee97f9e3b3529fd32ffb896187.zip
Initial Commit. Sharing is caring
Diffstat (limited to 'filter_plugins')
-rw-r--r--filter_plugins/.gitignore1
-rw-r--r--filter_plugins/oo_filters.py69
2 files changed, 70 insertions, 0 deletions
diff --git a/filter_plugins/.gitignore b/filter_plugins/.gitignore
new file mode 100644
index 000000000..72723e50a
--- /dev/null
+++ b/filter_plugins/.gitignore
@@ -0,0 +1 @@
+*pyc
diff --git a/filter_plugins/oo_filters.py b/filter_plugins/oo_filters.py
new file mode 100644
index 000000000..0c34cfc3e
--- /dev/null
+++ b/filter_plugins/oo_filters.py
@@ -0,0 +1,69 @@
+from ansible import errors, runner
+import json
+import pdb
+
+def oo_pdb(arg):
+ ''' This pops you into a pdb instance where arg is the data passed in from the filter.
+ Ex: "{{ hostvars | oo_pdb }}"
+ '''
+ pdb.set_trace()
+ return arg
+
+def get_attr(data, attribute=None):
+ ''' This looks up dictionary attributes of the form a.b.c and returns the value.
+ Ex: data = {'a': {'b': {'c': 5}}}
+ attribute = "a.b.c"
+ returns 5
+ '''
+
+ if not attribute:
+ raise errors.AnsibleFilterError("|failed expects attribute to be set")
+
+ ptr = data
+ for attr in attribute.split('.'):
+ ptr = ptr[attr]
+
+ return ptr
+
+def oo_collect(data, attribute=None):
+ ''' This takes a list of dict and collects all attributes specified into a list
+ Ex: data = [ {'a':1,'b':5}, {'a':2}, {'a':3} ]
+ attribute = 'a'
+ returns [1, 2, 3]
+ '''
+
+ if not issubclass(type(data), list):
+ raise errors.AnsibleFilterError("|failed expects to filter on a List")
+
+ if not attribute:
+ raise errors.AnsibleFilterError("|failed expects attribute to be set")
+
+ retval = [get_attr(d, attribute) for d in data]
+
+ return retval
+
+def oo_select_keys(data, keys):
+ ''' This returns a list, which contains the value portions for the keys
+ Ex: data = { 'a':1, 'b':2, 'c':3 }
+ keys = ['a', 'c']
+ returns [1, 3]
+ '''
+
+ if not issubclass(type(data), dict):
+ raise errors.AnsibleFilterError("|failed expects to filter on a Dictionary")
+
+ if not issubclass(type(keys), list):
+ raise errors.AnsibleFilterError("|failed expects first param is a list")
+
+ # Gather up the values for the list of keys passed in
+ retval = [data[key] for key in keys]
+
+ return retval
+
+class FilterModule (object):
+ def filters(self):
+ return {
+ "oo_select_keys": oo_select_keys,
+ "oo_collect": oo_collect,
+ "oo_pdb": oo_pdb
+ }