-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0550138
commit 2ee2091
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
roles/openshift_health_checker/openshift_checks/ram_diskspace_availability.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# pylint: disable=missing-docstring | ||
from openshift_checks import OpenShiftCheck, get_var | ||
from openshift_checks.mixins import NotContainerizedMixin | ||
|
||
|
||
class RamDiskspaceAvailability(NotContainerizedMixin, OpenShiftCheck): | ||
"""Check that recommended memory and disk-space are available.""" | ||
|
||
name = "ram_diskspace_availability" | ||
tags = ["preflight"] | ||
|
||
# attempt to pull required docker images and fail if | ||
# any images are missing, or error occurs during pull | ||
def run(self, tmp, task_vars): | ||
ansible_mounts = get_var(task_vars, "ansible_mounts") | ||
diskfree = self.to_gigabytes(self.get_disk_space(ansible_mounts)) | ||
memoryfree = get_var(task_vars, "facter_memoryfree") | ||
|
||
recommended_memory = get_var(task_vars, "min_memory_gb") | ||
recommended_storage = get_var(task_vars, "min_diskspace_gb") | ||
|
||
if self.mem_to_float(memoryfree) < float(recommended_memory) or float(diskfree) < float(recommended_storage): | ||
return {"failed": True, "msg": "Available memory (%s) or disk space (%s) below recommended storage. Minimum required memory: %s GB, Minimum required disk space: %s GB" % (memoryfree, str(diskfree) + " GB", recommended_memory, recommended_storage)} | ||
|
||
return {"changed": False} | ||
|
||
@staticmethod | ||
def get_disk_space(ansible_mounts): | ||
if len(ansible_mounts): | ||
for mnt in ansible_mounts: | ||
if mnt.get("mount") == "/": | ||
return mnt.get("size_available") | ||
|
||
return None | ||
|
||
@staticmethod | ||
def to_gigabytes(totalBytes): | ||
return totalBytes / 1073741824 | ||
|
||
@staticmethod | ||
def mem_to_float(mem): | ||
return float(mem.rstrip(" GB")) |