summaryrefslogtreecommitdiffstats
path: root/filter_plugins
diff options
context:
space:
mode:
authorWesley Hearn <whearn@redhat.com>2015-05-20 16:47:07 -0400
committerWesley Hearn <whearn@redhat.com>2015-05-20 16:47:07 -0400
commit970ac423967bbe3806e74de2dfefd7da5bb851d2 (patch)
tree0b9155d3ccca1ab5e273adb99f7b6d7e722d27a1 /filter_plugins
parent4da7b790d5eb8e870bd81208f7074bba81a0989b (diff)
downloadopenshift-970ac423967bbe3806e74de2dfefd7da5bb851d2.tar.gz
openshift-970ac423967bbe3806e74de2dfefd7da5bb851d2.tar.bz2
openshift-970ac423967bbe3806e74de2dfefd7da5bb851d2.tar.xz
openshift-970ac423967bbe3806e74de2dfefd7da5bb851d2.zip
Revert "Made a generic set_attr and set_attrs function to reduce dup code"
This reverts commit 4da7b790d5eb8e870bd81208f7074bba81a0989b.
Diffstat (limited to 'filter_plugins')
-rw-r--r--filter_plugins/oo_filters.py32
-rw-r--r--filter_plugins/oo_resourceconfig.py87
2 files changed, 32 insertions, 87 deletions
diff --git a/filter_plugins/oo_filters.py b/filter_plugins/oo_filters.py
index e02114d9e..8feb53f43 100644
--- a/filter_plugins/oo_filters.py
+++ b/filter_plugins/oo_filters.py
@@ -176,6 +176,38 @@ def oo_ec2_volume_definition(data, host_type, docker_ephemeral=False):
return [root_vol, docker_vol]
return [root_vol]
+def oo_set_node_label(arg, key, value, attr_key=None, attr_value=None):
+ ''' This cycles through openshift node definitions
+ (from "osc get nodes -o json"), and adds a label.
+
+ If attr_key and attr_value are set, this will only set the label on
+ nodes where the attribute matches the specified value.
+
+ Ex:
+ - shell: osc get nodes -o json
+ register: output
+
+ - set_fact:
+ node_facts: "{{ output.stdout
+ | from_json
+ | oo_set_node_label('region', 'infra',
+ 'metadata.name', '172.16.17.43') }}"
+ '''
+
+ for item in arg['items']:
+ if attr_key and attr_value:
+ actual_attr_value = get_attr(item, attr_key)
+
+ if str(attr_value) != str(actual_attr_value):
+ continue # We only want to set the values on hosts with defined attributes
+
+ if 'labels' not in item['metadata']:
+ item['metadata']['labels'] = {}
+
+ item['metadata']['labels'][key] = value
+
+ return arg
+
# disabling pylint checks for too-few-public-methods and no-self-use since we
# need to expose a FilterModule object that has a filters method that returns
# a mapping of filter names to methods.
diff --git a/filter_plugins/oo_resourceconfig.py b/filter_plugins/oo_resourceconfig.py
deleted file mode 100644
index 6d1c31443..000000000
--- a/filter_plugins/oo_resourceconfig.py
+++ /dev/null
@@ -1,87 +0,0 @@
-#!/usr/bin/python
-# -*- coding: utf-8 -*-
-# vim: expandtab:tabstop=4:shiftwidth=4
-'''
-Filters for configuring resources in openshift-ansible
-'''
-
-from ansible import errors
-
-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 set_attr(item, key, value, attr_key=None, attr_value=None):
- if attr_key and attr_value:
- actual_attr_value = get_attr(item, attr_key)
-
- if str(attr_value) != str(actual_attr_value):
- continue # We only want to set the values on hosts with defined attributes
-
- kvp = item
- for attr in key.split('.'):
- if attr == key.split('.')[len(key.split('.'))-1]:
- kvp[attr] = value
- continue
- if attr not in kvp:
- kvp[attr] = {}
-
- kvp = kvp[attr]
- return item
-
-
-def set_attrs(items, key, value, attr_key=None, attr_value=None):
- for item in items:
- create_update_key(item, key, value, attr_key, attr_value)
-
- return items
-
-
-def oo_set_node_label(arg, key, value, attr_key=None, attr_value=None):
- ''' This cycles through openshift node definitions
- (from "osc get nodes -o json"), and adds a label.
-
- If attr_key and attr_value are set, this will only set the label on
- nodes where the attribute matches the specified value.
-
- Ex:
- - shell: osc get nodes -o json
- register: output
-
- - set_fact:
- node_facts: "{{ output.stdout
- | from_json
- | oo_set_node_label('region', 'infra',
- 'metadata.name', '172.16.17.43') }}"
- '''
- arg['items'] = set_attrs(arg['items'], key, value, attr_key, attr_value)
-
- return arg
-
-
-def oo_set_resource_node(arg, value):
- arg = set_attr(arg, 'template.podTemplate.nodeSelector.region', value)
-
- return arg
-
-
-class FilterModule(object):
- ''' FilterModule '''
- def filters(self):
- ''' returns a mapping of filters to methods '''
- return {
- "oo_set_node_label": oo_set_node_label,
- "oo_set_resource_node": oo_set_resource_node
- }