Skip to content

Commit

Permalink
fix: PEP8 compliance update private method
Browse files Browse the repository at this point in the history
  • Loading branch information
lperdereau committed Nov 4, 2024
1 parent 0c94bc2 commit a79c2ec
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 33 deletions.
10 changes: 5 additions & 5 deletions src/pvecontrol/actions/cluster.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import logging

from pvecontrol.config import get_config
from pvecontrol.utils import _filter_keys, _print_tableoutput
from pvecontrol.utils import filter_keys, print_tableoutput


def action_clusterstatus(proxmox, args):
logging.debug(proxmox.status)
logging.debug(proxmox.resources)
status = _filter_keys(proxmox.status[0], ['name', 'nodes', 'quorate'])
nodes = [ _filter_keys(n, ['name', 'ip', 'online']) for n in proxmox.status[1:] ]
status = filter_keys(proxmox.status[0], ['name', 'nodes', 'quorate'])
nodes = [ filter_keys(n, ['name', 'ip', 'online']) for n in proxmox.status[1:] ]
# FIXME get cluster maxmem
# FIXME get cluster maxcpu
# FIXME get cluster allocatedmem
# FIXME get cluster allocatedcpu
_print_tableoutput([status])
_print_tableoutput(nodes)
print_tableoutput([status])
print_tableoutput(nodes)

def action_sanitycheck(proxmox, args):
"""Check status of proxmox Cluster"""
Expand Down
12 changes: 6 additions & 6 deletions src/pvecontrol/actions/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
from pvecontrol.node import NodeStatus
from pvecontrol.vm import VmStatus
from pvecontrol.utils import (
_filter_keys, _print_tableoutput, _print_task, _print_taskstatus
filter_keys, print_tableoutput, print_task, print_taskstatus
)


def action_nodelist(proxmox, args):
"""List proxmox nodes in the cluster using proxmoxer api"""
nodes = [ _filter_keys(n.__dict__, ['node', 'status', 'allocatedcpu', 'maxcpu', 'mem', 'allocatedmem', 'maxmem']) for n in proxmox.nodes ]
_print_tableoutput(nodes, sortby='node')
nodes = [ filter_keys(n.__dict__, ['node', 'status', 'allocatedcpu', 'maxcpu', 'mem', 'allocatedmem', 'maxmem']) for n in proxmox.nodes ]
print_tableoutput(nodes, sortby='node')

def action_nodeevacuate(proxmox, args):
"""Evacuate a node by migrating all it's VM out"""
Expand Down Expand Up @@ -97,15 +97,15 @@ def action_nodeevacuate(proxmox, args):
proxmox.refresh()
task = proxmox.find_task(upid)
if args.follow:
_print_task(proxmox, upid, args.follow)
print_task(proxmox, upid, args.follow)
else:
_print_taskstatus(task)
print_taskstatus(task)
# wait for task completion
while task.running():
logging.debug("Task status: %s", task.runningstatus)
task.refresh()
time.sleep(1)
_print_taskstatus(task)
print_taskstatus(task)

else:
print("Dry run, skipping migration")
8 changes: 4 additions & 4 deletions src/pvecontrol/actions/task.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from pvecontrol.utils import _print_task, _print_tableoutput, _filter_keys
from pvecontrol.utils import print_task, print_tableoutput, filter_keys


def action_tasklist(proxmox, args):
tasks = [ _filter_keys(t.__dict__, ['upid', 'exitstatus', 'node', 'type', 'starttime', 'endtime', 'runningstatus', 'description']) for t in proxmox.tasks ]
_print_tableoutput(tasks, sortby='starttime')
tasks = [ filter_keys(t.__dict__, ['upid', 'exitstatus', 'node', 'type', 'starttime', 'endtime', 'runningstatus', 'description']) for t in proxmox.tasks ]
print_tableoutput(tasks, sortby='starttime')

def action_taskget(proxmox, args):
_print_task(proxmox, args.upid, args.follow)
print_task(proxmox, args.upid, args.follow)
12 changes: 6 additions & 6 deletions src/pvecontrol/actions/vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import time

from pvecontrol.utils import (
_print_task, _print_taskstatus, _print_tableoutput, _filter_keys
print_task, print_taskstatus, print_tableoutput, filter_keys
)


Expand Down Expand Up @@ -58,20 +58,20 @@ def action_vmmigrate(proxmox, args):
proxmox.refresh()
task = proxmox.find_task(upid)
if args.follow:
_print_task(proxmox, upid, args.follow)
print_task(proxmox, upid, args.follow)
else:
_print_taskstatus(task)
print_taskstatus(task)
# wait for task completion
while task.running():
logging.debug("Task status: %s", task.runningstatus)
task.refresh()
time.sleep(1)
_print_taskstatus(task)
print_taskstatus(task)

else:
print("Dry run, skipping migration")

def action_vmlist(proxmox, args):
"""List VMs in the Proxmox Cluster"""
vms = [ _filter_keys(n.__dict__, ['vmid', 'name', 'status', 'node', 'cpus', 'maxmem', 'maxdisk']) for n in proxmox.vms() ]
_print_tableoutput(vms, sortby='vmid')
vms = [ filter_keys(n.__dict__, ['vmid', 'name', 'status', 'node', 'cpus', 'maxmem', 'maxdisk']) for n in proxmox.vms() ]
print_tableoutput(vms, sortby='vmid')
6 changes: 3 additions & 3 deletions src/pvecontrol/test_pvecontrol.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pvecontrol.utils import _filter_keys
from pvecontrol.utils import filter_keys

def test_filter_keys():
def testfilter_keys():
input = {'test': "toto", 'none': "noninclude"}
filter = ["test"]
assert _filter_keys(input, filter) == {'test': "toto"}
assert filter_keys(input, filter) == {'test': "toto"}
18 changes: 9 additions & 9 deletions src/pvecontrol/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# Pretty output a table from a table of dicts
# We assume all dicts have the same keys and are sorted by key
def _print_tableoutput(table, sortby=None, filter=[]):
def print_tableoutput(table, sortby=None, filter=[]):
x = PrettyTable()
x.align = 'l'
x.field_names = table[0].keys()
Expand All @@ -19,21 +19,21 @@ def _print_tableoutput(table, sortby=None, filter=[]):
x.add_row( line.values() )
print(x.get_string(sortby=sortby))

def _filter_keys(input, keys):
def filter_keys(input, keys):
# Filter keys from input dict
output = OrderedDict()
for key in keys:
output[key] = input[key]
return output

def _print_taskstatus(task):
output = [ _filter_keys(task.__dict__, ['upid', 'exitstatus', 'node', 'runningstatus', 'type', 'user', 'starttime']) ]
_print_tableoutput(output)
def print_taskstatus(task):
output = [ filter_keys(task.__dict__, ['upid', 'exitstatus', 'node', 'runningstatus', 'type', 'user', 'starttime']) ]
print_tableoutput(output)

def _print_task(proxmox, upid, follow = False):
def print_task(proxmox, upid, follow = False):
task = proxmox.find_task(upid)
logging.debug("Task: %s", task)
_print_taskstatus(task)
print_taskstatus(task)
log = task.log(limit=0)
logging.debug("Task Log: %s", log)
if task.running() and follow:
Expand All @@ -49,6 +49,6 @@ def _print_task(proxmox, upid, follow = False):
if line['n'] > lastline:
lastline = line['n']
time.sleep(1)
_print_taskstatus(task)
print_taskstatus(task)
else:
_print_tableoutput([{"log output": task.decode_log()}])
print_tableoutput([{"log output": task.decode_log()}])

0 comments on commit a79c2ec

Please sign in to comment.