From d2955189066364461a846e0e34d344c94b26a16b Mon Sep 17 00:00:00 2001 From: juanvallejo Date: Mon, 27 Feb 2017 17:52:02 -0500 Subject: add ram and storage preflight check --- .../openshift_checks/memory_availability.py | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 roles/openshift_health_checker/openshift_checks/memory_availability.py (limited to 'roles/openshift_health_checker/openshift_checks/memory_availability.py') diff --git a/roles/openshift_health_checker/openshift_checks/memory_availability.py b/roles/openshift_health_checker/openshift_checks/memory_availability.py new file mode 100644 index 000000000..aa54b9535 --- /dev/null +++ b/roles/openshift_health_checker/openshift_checks/memory_availability.py @@ -0,0 +1,35 @@ +# pylint: disable=missing-docstring +from openshift_checks import OpenShiftCheck, get_var + + +class MemoryAvailability(OpenShiftCheck): + """Check that recommended memory is available.""" + + name = "memory_availability" + tags = ["preflight"] + + recommended_memory_mb = { + "nodes": 8 * 1000, + "masters": 16 * 1000, + "etcd": 10 * 1000, + } + + @classmethod + def is_active(cls, task_vars): + """Skip hosts that do not have recommended memory space requirements.""" + group_names = get_var(task_vars, "group_names", default=[]) + has_mem_space_recommendation = bool(set(group_names).intersection(cls.recommended_memory_mb)) + return super(MemoryAvailability, cls).is_active(task_vars) and has_mem_space_recommendation + + def run(self, tmp, task_vars): + group_names = get_var(task_vars, "group_names", default=[]) + total_memory = get_var(task_vars, "ansible_memtotal_mb") + + recommended_memory_mb = max(self.recommended_memory_mb.get(group, 0) for group in group_names) + + if total_memory < recommended_memory_mb: + msg = ("Available memory ({available} MB) below recommended storage. " + "Minimum required memory: {recommended} MB") + return {"failed": True, "msg": msg.format(available=total_memory, recommended=recommended_memory_mb)} + + return {"changed": False} -- cgit v1.2.3