Skip to content

Commit

Permalink
chore(pylint): Rebase to branch black
Browse files Browse the repository at this point in the history
  • Loading branch information
lperdereau committed Dec 12, 2024
1 parent d054d4f commit a52973d
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/pvecontrol/actions/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def _get_disk_output():
print(output)


def action_sanitycheck(proxmox, _args):
def action_sanitycheck(proxmox, args):
"""Check status of proxmox Cluster"""
# More checks to implement
# VM is started but 'startonboot' not set
Expand Down
9 changes: 4 additions & 5 deletions src/pvecontrol/cluster.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import re
import logging

from proxmoxer import ProxmoxAPI

from pvecontrol.node import PVENode
from pvecontrol.storage import PVEStorage, StorageShared
from pvecontrol.storage import PVEStorage
from pvecontrol.task import PVETask


Expand All @@ -30,9 +29,9 @@ def _initstatus(self):
self.storages.append(PVEStorage(storage.pop("node"), storage.pop("id"), storage.pop("shared"), **storage))

self.ha = {
"groups": self._api.cluster.ha.groups.get(),
"manager_status": self._api.cluster.ha.status.manager_status.get(),
"resources": self._api.cluster.ha.resources.get(),
"groups": self.api.cluster.ha.groups.get(),
"manager_status": self.api.cluster.ha.status.manager_status.get(),
"resources": self.api.cluster.ha.resources.get(),
}

self.tasks = []
Expand Down
5 changes: 3 additions & 2 deletions src/pvecontrol/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self, api, node, status, kwargs=None):

self.node = node
self.status = NodeStatus[status.upper()]
self.api = api
self._api = api
self.cpu = kwargs.get("cpu", 0)
self.allocatedcpu = 0
self.maxcpu = kwargs.get("maxcpu", 0)
Expand Down Expand Up @@ -52,7 +52,8 @@ def _init_vms(self):
self.vms = []
if self.status == NodeStatus.ONLINE:
self.vms = [
PVEVm(self.api, self.node, vm["vmid"], vm["status"], vm) for vm in self.api.nodes(self.node).qemu.get()
PVEVm(self._api, self.node, vm["vmid"], vm["status"], vm)
for vm in self._api.nodes(self.node).qemu.get()
]

def _init_allocatedmem(self):
Expand Down
15 changes: 8 additions & 7 deletions src/pvecontrol/sanitycheck/checks.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from abc import ABC, abstractmethod
from enum import Enum

from pvecontrol.utils import fonts, teminal_support_utf_8, terminal_support_colors
from pvecontrol.utils import Fonts, teminal_support_utf_8, terminal_support_colors


class CheckType(Enum):
HA = "HIGH_AVAILABILITY"
Node = "NODE"
NODE = "NODE"


class CheckCode(Enum):
Expand All @@ -31,10 +31,10 @@ class CheckCode(Enum):
}

ICONS_COLORED_ASCII = {
CheckCode.CRIT.value: f"{fonts.RED}[CRIT]{fonts.END}",
CheckCode.WARN.value: f"{fonts.YELLOW}[WARN]{fonts.END}",
CheckCode.INFO.value: f"{fonts.BLUE}[INFO]{fonts.END}",
CheckCode.OK.value: f"{fonts.GREEN}[OK]{fonts.END}",
CheckCode.CRIT.value: f"{Fonts.RED}[CRIT]{Fonts.END}",
CheckCode.WARN.value: f"{Fonts.YELLOW}[WARN]{Fonts.END}",
CheckCode.INFO.value: f"{Fonts.BLUE}[INFO]{Fonts.END}",
CheckCode.OK.value: f"{Fonts.GREEN}[OK]{Fonts.END}",
}


Expand Down Expand Up @@ -73,6 +73,7 @@ def __init__(self, proxmox, messages=None):
messages = []
self.proxmox = proxmox
self.messages = messages
self.code = ""

@abstractmethod
def run(self):
Expand Down Expand Up @@ -107,7 +108,7 @@ def set_code(self, code: CheckCode):

def display(self, padding_max_size):
if terminal_support_colors():
name = f"{fonts.BOLD}{self.name}{fonts.END}\n"
name = f"{Fonts.BOLD}{self.name}{Fonts.END}\n"
else:
name = f"{self.name}\n"
print(name)
Expand Down
7 changes: 3 additions & 4 deletions src/pvecontrol/sanitycheck/sanitychecks.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def run(self, checks):
)
return 1

for id in checks:
check = DEFAULT_CHECKS[id](self._proxmox)
for key in checks:
check = DEFAULT_CHECKS[key](self._proxmox)
check.run()
self._checks.append(check)

Expand All @@ -39,8 +39,7 @@ def _get_longest_message(self):
size = 0
for check in self._checks:
for msg in check.messages:
if len(msg) > size:
size = len(msg)
size = max(size, len(msg))
return size + 1

def display(self):
Expand Down
6 changes: 3 additions & 3 deletions src/pvecontrol/sanitycheck/tests/ha_vms.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ def run(self):
ha_resources = [r for r in self.proxmox.ha["resources"] if r["type"] in ["vm"]]
ha_vms = []
for resource in ha_resources:
id = resource["sid"].split(":")[1] # "sid = vm:100"
vmid = resource["sid"].split(":")[1] # "sid = vm:100"
if resource["type"] == "vm":
ha_vms.append(self.proxmox.get_vm(id))
ha_vms.append(self.proxmox.get_vm(vmid))

self.add_messages(self._check_disk_ha_consistency(ha_vms))
self.add_messages(self._check_cpu_ha_consistency(ha_vms))
Expand All @@ -37,7 +37,7 @@ def _check_disk_ha_consistency(self, ha_vms):
continue
if regex_result := re.search(regex, v):
storage = self.proxmox.get_storage(regex_result.group(1))
if storage != None and StorageShared[storage.shared] != StorageShared.shared:
if storage is not None and StorageShared[storage.shared] != StorageShared.shared:
result["disks"].append(k)
if result["disks"]:
vms_not_consistent.append(result)
Expand Down
2 changes: 1 addition & 1 deletion src/pvecontrol/sanitycheck/tests/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class Nodes(Check):

id = "nodes"
type = CheckType.Node
type = CheckType.NODE
name = "Check Node capacity"

def run(self):
Expand Down
6 changes: 3 additions & 3 deletions src/pvecontrol/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class PVETask:
def __init__(self, api, upid):
task = Tasks.decode_upid(upid)

self.api = api
self._api = api
self.upid = upid
self.node = task["node"]
self.starttime = task["starttime"]
Expand All @@ -41,7 +41,7 @@ def __init__(self, api, upid):
self.refresh()

def log(self, limit=0, start=0):
return self.api.nodes(self.node).tasks(self.upid).log.get(limit=limit, start=start)
return self._api.nodes(self.node).tasks(self.upid).log.get(limit=limit, start=start)

def running(self):
return self.runningstatus == TaskRunningStatus.RUNNING
Expand All @@ -54,7 +54,7 @@ def refresh(self):
# if self.node != NodeStatus.online:
# return
try:
status = self.api.nodes(self.node).tasks(self.upid).status.get()
status = self._api.nodes(self.node).tasks(self.upid).status.get()
# Some task information can be vanished over time (tasks status files removed from the node filesystem)
# In this case API return an error and we consider this tasks vanished and don't get more informations
except proxmoxer.core.ResourceException:
Expand Down
12 changes: 4 additions & 8 deletions src/pvecontrol/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from prettytable import PrettyTable


class fonts:
class Fonts:
BLUE = "\033[94m"
GREEN = "\033[92m"
YELLOW = "\033[93m"
Expand All @@ -26,13 +26,9 @@ def terminal_support_colors():
curses.start_color()
if curses.has_colors():
_num_colors = curses.color_pair(1)
if curses.COLORS > 0:
return True
else:
return False
else:
return False
except Exception as e:
return curses.COLORS > 0
return False
except Exception: # pylint: disable=broad-exception-caught
return False
finally:
curses.endwin()
Expand Down
8 changes: 4 additions & 4 deletions src/pvecontrol/vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, api, node, vmid, status, kwargs=None):
self.vmid = vmid
self.status = VmStatus[status.upper()]
self.node = node
self.api = api
self._api = api

self.name = kwargs.get("name", "")
self.lock = kwargs.get("lock", "")
Expand All @@ -32,7 +32,7 @@ def __init__(self, api, node, vmid, status, kwargs=None):
self.tags = kwargs.get("tags", "")
self.template = kwargs.get("template", 0)

self.config = self.api.nodes(self.node).qemu(vmid).config.get()
self.config = self._api.nodes(self.node).qemu(vmid).config.get()

def __str__(self):
str_keys = [
Expand All @@ -56,11 +56,11 @@ def migrate(self, target, online=False):
options = {}
options["node"] = self.node
options["target"] = target
check = self.api.nodes(self.node).qemu(self.vmid).migrate.get(**options)
check = self._api.nodes(self.node).qemu(self.vmid).migrate.get(**options)
# logging.debug("Migration check: %s"%check)
options["online"] = int(online)
if len(check["local_disks"]) > 0:
options["with-local-disks"] = int(True)

upid = self.api.nodes(self.node).qemu(self.vmid).migrate.post(**options)
upid = self._api.nodes(self.node).qemu(self.vmid).migrate.post(**options)
return upid

0 comments on commit a52973d

Please sign in to comment.