-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(sanitychecks): Refacto Checks run with classes
- Loading branch information
1 parent
cf72417
commit 983e7fd
Showing
8 changed files
with
133 additions
and
141 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1 +1 @@ | ||
from .sanitychecks import SanityCheck, DEFAULT_CHECKS_ORDER | ||
from .sanitychecks import SanityCheck |
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
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
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 |
---|---|---|
@@ -1,15 +1,11 @@ | ||
from pvecontrol.sanitycheck.checks import Check, CheckType, CheckMessage, CheckCode | ||
from .nodes import Nodes | ||
from .ha_groups import HaGroups | ||
from .ha_vms import HaVms | ||
|
||
# Check HA groups | ||
def get_checks(sanity): | ||
check = Check(CheckType.HA, "Check HA groups") | ||
for group in sanity._ha['groups']: | ||
num_nodes = len(group['nodes'].split(",")) | ||
if num_nodes < 2: | ||
msg = f"Group {group['group']} contain only {num_nodes} node" | ||
check.add_messages(CheckMessage(CheckCode.WARN, msg)) | ||
DEFAULT_CHECKS = { | ||
Nodes.id: Nodes, | ||
HaGroups.id: HaGroups, | ||
HaVms.id: HaVms | ||
} | ||
|
||
if not check.messages: | ||
msg = "HA Group checked" | ||
check.add_messages(CheckMessage(CheckCode.OK, msg)) | ||
return check | ||
DEFAULT_CHECK_IDS = DEFAULT_CHECKS.keys() |
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 |
---|---|---|
@@ -1,16 +1,19 @@ | ||
from pvecontrol.sanitycheck.checks import Check, CheckType, CheckMessage, CheckCode | ||
|
||
|
||
# Check HA groups | ||
def get_checks(sanity): | ||
check = Check(CheckType.HA, "Check HA groups") | ||
for group in sanity._ha['groups']: | ||
num_nodes = len(group['nodes'].split(",")) | ||
if num_nodes < 2: | ||
msg = f"Group {group['group']} contain only {num_nodes} node" | ||
check.add_messages(CheckMessage(CheckCode.WARN, msg)) | ||
class HaGroups(Check): | ||
|
||
if not check.messages: | ||
msg = "HA Group checked" | ||
check.add_messages(CheckMessage(CheckCode.OK, msg)) | ||
return [check] | ||
id = "ha_groups" | ||
type = CheckType.HA | ||
name = "Check HA groups" | ||
|
||
def run(self): | ||
for group in self.proxmox.ha()['groups']: | ||
num_nodes = len(group['nodes'].split(",")) | ||
if num_nodes < 2: | ||
msg = f"Group {group['group']} contain only {num_nodes} node" | ||
self.add_messages(CheckMessage(CheckCode.WARN, msg)) | ||
|
||
if not self.messages: | ||
msg = "HA Group checked" | ||
self.add_messages(CheckMessage(CheckCode.OK, msg)) |
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
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 |
---|---|---|
@@ -1,28 +1,36 @@ | ||
from pvecontrol.sanitycheck.checks import Check, CheckType, CheckMessage, CheckCode | ||
|
||
def _check_cpu_overcommit(maxcpu, cpufactor, allocated_cpu): | ||
return (maxcpu * cpufactor) <= allocated_cpu | ||
|
||
def _check_mem_overcommit(max_mem, min_mem, allocated_mem): | ||
return (allocated_mem + min_mem) >= max_mem | ||
|
||
# Check nodes capacity | ||
def get_checks(sanitity): | ||
node_config = sanitity._proxmox.config['node'] | ||
check = Check(CheckType.Node, "Check Node capacity") | ||
for node in sanitity._proxmox.nodes: | ||
if _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)) | ||
|
||
for node in sanitity._proxmox.nodes: | ||
if _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] | ||
from pvecontrol.sanitycheck.checks import Check, CheckCode, CheckType, CheckMessage | ||
|
||
|
||
class Nodes(Check): | ||
|
||
id = "nodes" | ||
type = CheckType.Node | ||
name = "Check Node capacity" | ||
|
||
def run(self): | ||
self._check_cpu_overcommit() | ||
self._check_mem_overcommit() | ||
|
||
def _check_mem_overcommit(self): | ||
for node in self.proxmox.nodes: | ||
if self._mem_is_overcommited(node.allocatedmem, self.proxmox.config['node']['memoryminimum'], node.maxmem): | ||
msg = f"Node '{node.node}' is in mem overcommit status: {node.allocatedmem} allocated but {node.maxmem} available" | ||
self.add_messages(CheckMessage(CheckCode.CRIT, msg)) | ||
else: | ||
msg = f"Node '{node.node}' isn't in cpu overcommit" | ||
self.add_messages(CheckMessage(CheckCode.OK, msg)) | ||
|
||
def _check_cpu_overcommit(self): | ||
for node in self.proxmox.nodes: | ||
if self._cpu_is_overcommited(node.maxcpu, self.proxmox.config['node']['cpufactor'], node.allocatedcpu): | ||
msg = f"Node {node.node} is in cpu overcommit status: {node.allocatedcpu} allocated but {node.maxcpu} available" | ||
self.add_messages(CheckMessage(CheckCode.CRIT, msg)) | ||
else: | ||
msg = f"Node '{node.node}' isn't in cpu overcommit" | ||
self.add_messages(CheckMessage(CheckCode.OK, msg)) | ||
|
||
def _cpu_is_overcommited(self, maxcpu, cpufactor, allocated_cpu): | ||
return (maxcpu * cpufactor) <= allocated_cpu | ||
|
||
def _mem_is_overcommited(self, max_mem, min_mem, allocated_mem): | ||
return (allocated_mem + min_mem) >= max_mem |