diff --git a/src/pvecontrol/actions/cluster.py b/src/pvecontrol/actions/cluster.py index 580fbd6..9e6d120 100644 --- a/src/pvecontrol/actions/cluster.py +++ b/src/pvecontrol/actions/cluster.py @@ -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""" diff --git a/src/pvecontrol/actions/node.py b/src/pvecontrol/actions/node.py index 68abd96..a46c99b 100644 --- a/src/pvecontrol/actions/node.py +++ b/src/pvecontrol/actions/node.py @@ -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""" @@ -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") diff --git a/src/pvecontrol/actions/task.py b/src/pvecontrol/actions/task.py index 1835958..6d1ad1c 100644 --- a/src/pvecontrol/actions/task.py +++ b/src/pvecontrol/actions/task.py @@ -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) diff --git a/src/pvecontrol/actions/vm.py b/src/pvecontrol/actions/vm.py index 604971c..056857a 100644 --- a/src/pvecontrol/actions/vm.py +++ b/src/pvecontrol/actions/vm.py @@ -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 ) @@ -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') diff --git a/src/pvecontrol/test_pvecontrol.py b/src/pvecontrol/test_pvecontrol.py index befc9f5..ca46f5c 100644 --- a/src/pvecontrol/test_pvecontrol.py +++ b/src/pvecontrol/test_pvecontrol.py @@ -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"} diff --git a/src/pvecontrol/utils.py b/src/pvecontrol/utils.py index 6797eac..4348132 100644 --- a/src/pvecontrol/utils.py +++ b/src/pvecontrol/utils.py @@ -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() @@ -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: @@ -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()}])