diff --git a/frontend/templates/frontend/dashboard.html b/frontend/templates/frontend/dashboard.html index 49f522e..4175fbd 100644 --- a/frontend/templates/frontend/dashboard.html +++ b/frontend/templates/frontend/dashboard.html @@ -282,12 +282,9 @@ $.get("{% url 'frontend:current_container_details' %}", {'ids': id}, function (container) { container = container[0] if (container.is_low) { - $('[data-crow="' + id + '"]').addClass( - 'status-low' - ).attr( - 'title', - 'Low Warning: Disk: ' + container.disk_percent + '%, Memory: ' + container.mem_percent + '%' - ); + $('[data-crow="' + id + '"]') + .addClass('status-low') + .attr('title', 'Low Warning: Disk: ' + container.disk_percent + '%, Memory: ' + container.mem_percent + '%'); } let lxc_status = $('.lxc_status_' + id); let lease_status = $('.lease_status_' + id); diff --git a/frontend/views.py b/frontend/views.py index 7360187..ef81b8b 100644 --- a/frontend/views.py +++ b/frontend/views.py @@ -107,7 +107,11 @@ def dashboard(request): class ContainerStatus: low_limit = 80 - def __init__(self, **kwargs): + def __init__(self, dev_container:DevContainer): + self._devcontainer = dev_container + self.vmid = dev_container.lxc.vmid + self.lxc_status = dev_container.lxc.synced_status + kwargs = dev_container.statuscache or {} self.cpus = kwargs.get('cpus', 0) self.cpu = kwargs.get('cpu', 0) self.maxmem = kwargs.get('maxmem', 256) @@ -117,9 +121,7 @@ class ContainerStatus: self.maxswap = kwargs.get('maxswap', 0) self.swap = kwargs.get('swap', 0) self.status = kwargs.get('status') - self.vmid = kwargs.get('vmid') self.lease_status = kwargs.get('lease_status', 'waiting') - self.lxc_status = kwargs.get('lxc_status', 'stopped') def __hash__(self): return int(self.vmid) @@ -171,7 +173,7 @@ def container_details(request): with Proxmox() as pm: for id in ids: container = DevContainer.objects.get(internal_id=id) - ret.append(ContainerStatus(**(container.statuscache or {})).to_json) + ret.append(ContainerStatus(container).to_json) return HttpResponse(json.dumps(ret), content_type='application/json') diff --git a/proxmox/models.py b/proxmox/models.py index 3e657af..0a51a9e 100644 --- a/proxmox/models.py +++ b/proxmox/models.py @@ -97,6 +97,9 @@ class ProxmoxAbstractModel(BaseModel, TaskAwareModelMixin): return self.write(**params) else: return params + @property + def vmstatus(self): + raise NotImplemented('vmstatus not implemented') class Lxc(ProxmoxAbstractModel): @@ -123,6 +126,13 @@ class Lxc(ProxmoxAbstractModel): 'rootfs': ('size', 'disksize', lambda x: int(no_int_re.sub('', x) or 0)), } + @property + def synced_status(self): + with Proxmox() as pm: + if statusresponse := pm.lxc_get(f'{self.vmid}/status/current'): + self.write(status=statusresponse['status']) + return self.status + @property def proxmox_console_url(self): return (