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 251f2e1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
5 changes: 0 additions & 5 deletions src/pvecontrol/actions/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ def action_clusterstatus(proxmox, args):

def action_sanitycheck(proxmox, args):
"""Check status of proxmox Cluster"""
for node in proxmox.nodes:
if (node.maxcpu * proxmox.config['node']['cpufactor']) <= node.allocatedcpu:
print("Node %s is in cpu overcommit status: %s allocated but %s available"%(node.node, node.allocatedcpu, node.maxcpu))
if (node.allocatedmem + proxmox.config['node']['memoryminimum']) >= node.maxmem:
print("Node %s is in mem overcommit status: %s allocated but %s available"%(node.node, node.allocatedmem, node.maxmem))
# More checks to implement
# VM is started but 'startonboot' not set
# VM is running in cpu = host
Expand Down
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 251f2e1

Please sign in to comment.