From a097f30c6bdb590a8aef1187c6f41e0c4a200fd1 Mon Sep 17 00:00:00 2001 From: Joe Abbate Date: Sun, 18 Jun 2023 19:10:22 -0400 Subject: [PATCH 1/4] Fix 500 on IDE Drives --- proxstar/vm.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/proxstar/vm.py b/proxstar/vm.py index e8c716f..17777d8 100644 --- a/proxstar/vm.py +++ b/proxstar/vm.py @@ -261,7 +261,10 @@ def disks(self): disk_size = val.split(',') for split in disk_size: if 'size' in split: - disk_size = split.split('=')[1].rstrip('G') + size = split.split('=')[1] + if size[-1] == 'M': + size = f'{int(size.rstrip("M")) / 1000}G' + disk_size = size.rstrip('G') disks.append([key, disk_size]) disks = sorted(disks, key=lambda x: x[0]) return disks @@ -280,11 +283,10 @@ def cdroms(self): @lazy_property def isos(self): isos = [] - for iso in filter(lambda interface: 'ide' in interface, self.config.keys()): + for iso in filter(lambda interface: interface in self.cdroms, self.config.keys()): iso_info = self.config[iso] if iso_info: if 'cloudinit' in iso_info: - isos.append((iso, 'Clountinit Drive')) continue if iso_info.split(',')[0] == 'none': isos.append((iso, 'None')) From bb88e64aadb0d586028ad2a9afbf728f4deafc9a Mon Sep 17 00:00:00 2001 From: Joe Abbate Date: Sun, 18 Jun 2023 19:22:23 -0400 Subject: [PATCH 2/4] Fix Nesting --- proxstar/vm.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/proxstar/vm.py b/proxstar/vm.py index 17777d8..99e668e 100644 --- a/proxstar/vm.py +++ b/proxstar/vm.py @@ -251,6 +251,11 @@ def get_disk_size(self, name='virtio0'): disk_size = split.split('=')[1].rstrip('G') return disk_size + def check_in_gb(size): + if size[-1] == 'M': + size = f'{int(size.rstrip("M")) / 1000}G' + return size + @lazy_property def disks(self): disks = [] @@ -261,9 +266,7 @@ def disks(self): disk_size = val.split(',') for split in disk_size: if 'size' in split: - size = split.split('=')[1] - if size[-1] == 'M': - size = f'{int(size.rstrip("M")) / 1000}G' + size = check_in_gb(split.split('=')[1]) disk_size = size.rstrip('G') disks.append([key, disk_size]) disks = sorted(disks, key=lambda x: x[0]) From 35165a38c5bc420d6b2753597fb9319a315fdc6b Mon Sep 17 00:00:00 2001 From: Joe Abbate Date: Sun, 18 Jun 2023 19:41:42 -0400 Subject: [PATCH 3/4] Debug MB to GB Function --- proxstar/user.py | 4 +++- proxstar/vm.py | 9 ++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/proxstar/user.py b/proxstar/user.py index 96ff819..230dae7 100644 --- a/proxstar/user.py +++ b/proxstar/user.py @@ -1,3 +1,5 @@ +from math import ceil + from proxmoxer.core import ResourceException from rq.registry import StartedJobRegistry @@ -88,7 +90,7 @@ def usage(self): usage['cpu'] += int(vm.cpu) usage['mem'] += int(vm.mem) / 1024 for disk in vm.disks: - usage['disk'] += int(disk[1]) + usage['disk'] += int(ceil(disk[1])) return usage @lazy_property diff --git a/proxstar/vm.py b/proxstar/vm.py index 99e668e..6468c11 100644 --- a/proxstar/vm.py +++ b/proxstar/vm.py @@ -10,6 +10,10 @@ from proxstar.starrs import get_ip_for_mac from proxstar.util import lazy_property, default_repr +def check_in_gb(size): + if size[-1] == 'M': + size = f'{int(size.rstrip("M")) / 1000}G' + return size @default_repr class VM: @@ -251,11 +255,6 @@ def get_disk_size(self, name='virtio0'): disk_size = split.split('=')[1].rstrip('G') return disk_size - def check_in_gb(size): - if size[-1] == 'M': - size = f'{int(size.rstrip("M")) / 1000}G' - return size - @lazy_property def disks(self): disks = [] From d16858e4d5d2d3cf0d6e713340df98f645948d3b Mon Sep 17 00:00:00 2001 From: Joe Abbate Date: Sun, 18 Jun 2023 19:43:44 -0400 Subject: [PATCH 4/4] Black Linting --- proxstar/vm.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/proxstar/vm.py b/proxstar/vm.py index 6468c11..289daa4 100644 --- a/proxstar/vm.py +++ b/proxstar/vm.py @@ -10,11 +10,13 @@ from proxstar.starrs import get_ip_for_mac from proxstar.util import lazy_property, default_repr + def check_in_gb(size): if size[-1] == 'M': size = f'{int(size.rstrip("M")) / 1000}G' return size + @default_repr class VM: def __init__(self, vmid):