summaryrefslogtreecommitdiffstats
path: root/roles/lib_utils
diff options
context:
space:
mode:
Diffstat (limited to 'roles/lib_utils')
-rw-r--r--roles/lib_utils/action_plugins/generate_pv_pvcs_list.py8
-rw-r--r--roles/lib_utils/action_plugins/sanity_checks.py19
-rw-r--r--roles/lib_utils/filter_plugins/oo_filters.py50
3 files changed, 73 insertions, 4 deletions
diff --git a/roles/lib_utils/action_plugins/generate_pv_pvcs_list.py b/roles/lib_utils/action_plugins/generate_pv_pvcs_list.py
index eb13a58ba..c60742dd3 100644
--- a/roles/lib_utils/action_plugins/generate_pv_pvcs_list.py
+++ b/roles/lib_utils/action_plugins/generate_pv_pvcs_list.py
@@ -118,10 +118,16 @@ class ActionModule(ActionBase):
create_pvc = self._templar.template(create_pvc)
if kind != 'object' and create_pv and create_pvc:
volume, size, _, access_modes = self.build_common(varname=varname)
+ storageclass = self.task_vars.get(str(varname) + '_storageclass')
+ if storageclass:
+ storageclass = self._templar.template(storageclass)
+ elif storageclass is None and kind != 'dynamic':
+ storageclass = ''
return dict(
name="{0}-claim".format(volume),
capacity=size,
- access_modes=access_modes)
+ access_modes=access_modes,
+ storageclass=storageclass)
return None
def run(self, tmp=None, task_vars=None):
diff --git a/roles/lib_utils/action_plugins/sanity_checks.py b/roles/lib_utils/action_plugins/sanity_checks.py
index 09ce55e8f..ce54debc2 100644
--- a/roles/lib_utils/action_plugins/sanity_checks.py
+++ b/roles/lib_utils/action_plugins/sanity_checks.py
@@ -54,6 +54,12 @@ class ActionModule(ActionBase):
def template_var(self, hostvars, host, varname):
"""Retrieve a variable from hostvars and template it.
If undefined, return None type."""
+ # We will set the current host and variable checked for easy debugging
+ # if there are any unhandled exceptions.
+ # pylint: disable=W0201
+ self.last_checked_var = varname
+ # pylint: disable=W0201
+ self.last_checked_host = host
res = hostvars[host].get(varname)
if res is None:
return None
@@ -156,6 +162,11 @@ class ActionModule(ActionBase):
# pylint: disable=W0201
self.task_vars = task_vars or {}
+ # pylint: disable=W0201
+ self.last_checked_host = "none"
+ # pylint: disable=W0201
+ self.last_checked_var = "none"
+
# self._task.args holds task parameters.
# check_hosts is a parameter to this plugin, and should provide
# a list of hosts.
@@ -172,7 +183,13 @@ class ActionModule(ActionBase):
# We loop through each host in the provided list check_hosts
for host in check_hosts:
- self.run_checks(hostvars, host)
+ try:
+ self.run_checks(hostvars, host)
+ except Exception as uncaught_e:
+ msg = "last_checked_host: {}, last_checked_var: {};"
+ msg = msg.format(self.last_checked_host, self.last_checked_var)
+ msg += str(uncaught_e)
+ raise errors.AnsibleModuleError(msg)
result["changed"] = False
result["failed"] = False
diff --git a/roles/lib_utils/filter_plugins/oo_filters.py b/roles/lib_utils/filter_plugins/oo_filters.py
index 574743ff1..ed6bb4c28 100644
--- a/roles/lib_utils/filter_plugins/oo_filters.py
+++ b/roles/lib_utils/filter_plugins/oo_filters.py
@@ -126,7 +126,7 @@ def lib_utils_oo_collect(data_list, attribute=None, filters=None):
raise errors.AnsibleFilterError(
"lib_utils_oo_collect expects filter to be a dict")
retval.extend([get_attr(d, attribute) for d in data if (
- all([d.get(key, None) == filters[key] for key in filters]))])
+ all([get_attr(d, key) == filters[key] for key in filters]))])
else:
retval.extend([get_attr(d, attribute) for d in data])
@@ -660,6 +660,50 @@ def map_from_pairs(source, delim="="):
return dict(item.split(delim) for item in source.split(","))
+def lib_utils_oo_get_node_labels(source, hostvars=None):
+ ''' Return a list of labels assigned to schedulable nodes '''
+ labels = list()
+
+ # Filter out the unschedulable nodes
+ for host in source:
+ if host not in hostvars:
+ return
+ node_vars = hostvars[host]
+
+ # All nodes are considered schedulable,
+ # unless explicitly marked so
+ schedulable = node_vars.get('openshift_schedulable')
+ if schedulable is None:
+ schedulable = True
+ try:
+ if not strtobool(str(schedulable)):
+ # explicitly marked as unschedulable
+ continue
+ except ValueError:
+ # Incorrect value in openshift_schedulable, skip node
+ continue
+
+ # Get a list of labels from the node
+ node_labels = node_vars.get('openshift_node_labels')
+ if node_labels:
+ labels.append(node_labels)
+
+ return labels
+
+
+def lib_utils_oo_has_no_matching_selector(source, selector=None):
+ ''' Return True when selector cannot be placed
+ on nodes with labels from source '''
+ # Empty selector means any node
+ if not selector:
+ return False
+ for item in source:
+ if selector.items() <= item.items():
+ # Matching selector found
+ return False
+ return True
+
+
class FilterModule(object):
""" Custom ansible filter mapping """
@@ -691,5 +735,7 @@ class FilterModule(object):
"lib_utils_oo_selector_to_string_list": lib_utils_oo_selector_to_string_list,
"lib_utils_oo_filter_sa_secrets": lib_utils_oo_filter_sa_secrets,
"lib_utils_oo_l_of_d_to_csv": lib_utils_oo_l_of_d_to_csv,
- "map_from_pairs": map_from_pairs
+ "lib_utils_oo_has_no_matching_selector": lib_utils_oo_has_no_matching_selector,
+ "lib_utils_oo_get_node_labels": lib_utils_oo_get_node_labels,
+ "map_from_pairs": map_from_pairs,
}