Skip to content

Commit

Permalink
split ram and storage checks
Browse files Browse the repository at this point in the history
  • Loading branch information
juanvallejo committed Feb 28, 2017
1 parent 0deaaa8 commit 2420583
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# pylint: disable=missing-docstring
from openshift_checks import OpenShiftCheck, get_var
from openshift_checks.mixins import NotContainerizedMixin

import json


class DiskAvailability(OpenShiftCheck):
"""Check that recommended disk space is available."""

name = "disk_availability"
tags = ["preflight"]

recommended_node_diskspace_gb = 15.0
recommended_master_diskspace_gb = 40.0

def run(self, tmp, task_vars):
is_containerized = get_var(task_vars, "openshift", "common", "is_containerized")
group_names = get_var(task_vars, "group_names", default=[])
ansible_mounts = get_var(task_vars, "ansible_mounts")
diskfree = self.to_gigabytes(self.get_disk_space(ansible_mounts, is_containerized))

return {"failed": True, "msg": "ansible mounts %s" % json.dumps(ansible_mounts)}

recommended_diskspace_gb = self.recommended_master_diskspace_gb

if "nodes" in group_names:
recommended_diskspace_gb = self.recommended_node_diskspace_gb

if float(diskfree) < recommended_diskspace_gb:
return {"failed": True, "msg": "Available disk space for %s (%s) below recommended storage. Minimum required disk space: %s GB" % ("node" if "nodes" in group_names else "master", str(diskfree) + " GB", recommended_diskspace_gb)}

# if filesystem containing /var meets recommended diskspace,
# iterate through remaining mounted filesystems and output
# a warning if any are more than 90% full
check_mountpoints(ansible_mounts)

return {"changed": False}

@staticmethod
def get_disk_space(ansible_mounts, is_containerized):
if len(ansible_mounts):
for mnt in ansible_mounts:
if mnt.get("mount") == "/":
return mnt.get("size_available")

return None

@staticmethod
def check_mountpoints(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
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# pylint: disable=missing-docstring
from openshift_checks import OpenShiftCheck, get_var
from openshift_checks.mixins import NotContainerizedMixin


class MemoryAvailability(OpenShiftCheck):
"""Check that recommended memory is available."""

name = "memory_availability"
tags = ["preflight"]

recommended_node_memory_gb = 8.0
recommended_master_memory_gb = 16.0

def run(self, tmp, task_vars):
group_names = get_var(task_vars, "group_names", default=[])
memoryfree = get_var(task_vars, "facter_memoryfree")

recommended_memory_gb = self.recommended_master_memory_gb

if "nodes" in group_names:
recommended_memory_gb = self.recommended_node_memory_gb

if self.mem_to_float(memoryfree) < recommended_memory_gb:
return {"failed": True, "msg": "Available memory for %s (%s) below recommended storage. Minimum required memory: %s GB" % ("node" if "nodes" in group_names else "master", memoryfree, recommended_memory_gb)}

return {"changed": False}

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

This file was deleted.

0 comments on commit 2420583

Please sign in to comment.