Skip to content

Commit

Permalink
fix: Transpose existing sanity checks to new class
Browse files Browse the repository at this point in the history
  • Loading branch information
lperdereau committed Nov 28, 2024
1 parent 470cb8b commit 16ee6c0
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/pvecontrol/sanitycheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,14 @@ def display(self, padding_max_size):
class SanityCheck():

check_methods = (
"_validate_nodes_capacity",
"_validate_ha_groups",
"_validate_ha_vms",
)

check_display_order = [
CheckType.HA,
CheckType.Node,
]

def __init__(self, proxmox: PVECluster):
Expand Down Expand Up @@ -97,6 +99,32 @@ def display(self):
print(f"{dash_size*'-'} {check.type.value} {dash_size*'-'}\n")
check.display(size)

def _check_cpu_overcommit(self, maxcpu, cpufactor, allocated_cpu):
return (maxcpu * cpufactor) <= allocated_cpu

def _check_mem_overcommit(self, max_mem, min_mem, allocated_mem):
return (allocated_mem + min_mem) >= max_mem

# Check nodes capacity
def _validate_nodes_capacity(self):
node_config = self._proxmox.config['node']
check = Check(CheckType.Node, "Check Node capacity")
for node in self._proxmox.nodes:
if self._check_cpu_overcommit(node.maxcpu, node_config['cpufactor'], node.allocatedcpu):
msg = "Node %s is in cpu overcommit status: %s allocated but %s available"%(node.node, node.allocatedcpu, node.maxcpu)
check.add_messages(CheckMessage(CheckCode.CRIT, msg))
else:
msg = f"Node '{node.node}' isn't in cpu overcommit"
check.add_messages(CheckMessage(CheckCode.OK, msg))

if self._check_mem_overcommit(node.allocatedmem, node_config['memoryminimum'], node.maxmem):
msg = f"Node '{node.node}' is in mem overcommit status: {node.allocatedmem} allocated but {node.maxmem} available"
check.add_messages(CheckMessage(CheckCode.CRIT, msg))
else:
msg = f"Node '{node.node}' isn't in cpu overcommit"
check.add_messages(CheckMessage(CheckCode.OK, msg))
return check

# Check HA groups
def _validate_ha_groups(self):
check = Check(CheckType.HA, "Check HA groups")
Expand Down

0 comments on commit 16ee6c0

Please sign in to comment.