Skip to content

Commit

Permalink
add ram and storage preflight check
Browse files Browse the repository at this point in the history
  • Loading branch information
juanvallejo committed Feb 27, 2017
1 parent 0550138 commit 0deaaa8
Showing 1 changed file with 42 additions and 0 deletions.
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(total_bytes):
return total_bytes / 1073741824

@staticmethod
def mem_to_float(mem):
return float(mem.rstrip(" GB"))

0 comments on commit 0deaaa8

Please sign in to comment.