summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWesley Hearn <whearn@redhat.com>2015-05-20 15:45:09 -0400
committerWesley Hearn <whearn@redhat.com>2015-05-20 15:45:09 -0400
commitd04ddc76227db51fda8b1850a09a9c3cfd9125db (patch)
tree0e4a1197fe0c6b4c4c8e4d1956a732444aca14f7
parent8dedb32348549d8aa279201cfb89c50d5dc83ba5 (diff)
downloadopenshift-d04ddc76227db51fda8b1850a09a9c3cfd9125db.tar.gz
openshift-d04ddc76227db51fda8b1850a09a9c3cfd9125db.tar.bz2
openshift-d04ddc76227db51fda8b1850a09a9c3cfd9125db.tar.xz
openshift-d04ddc76227db51fda8b1850a09a9c3cfd9125db.zip
oo_filters.py: oo_set_node_label
-rw-r--r--filter_plugins/oo_filters.py35
1 files changed, 34 insertions, 1 deletions
diff --git a/filter_plugins/oo_filters.py b/filter_plugins/oo_filters.py
index 097038450..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.
@@ -192,5 +224,6 @@ class FilterModule(object):
"oo_pdb": oo_pdb,
"oo_prepend_strings_in_list": oo_prepend_strings_in_list,
"oo_ami_selector": oo_ami_selector,
- "oo_ec2_volume_definition": oo_ec2_volume_definition
+ "oo_ec2_volume_definition": oo_ec2_volume_definition,
+ "oo_set_node_label": oo_set_node_label
}