@@ -16,16 +16,13 @@ class NodeStatus(Enum):
16
16
class PVENode :
17
17
"""A proxmox VE Node"""
18
18
19
- _api = None
20
-
21
- def __init__ (self , api , node , status , node_resources , kwargs = None ):
19
+ def __init__ (self , cluster , node , status , kwargs = None ):
22
20
if not kwargs :
23
21
kwargs = {}
24
22
25
23
self .node = node
26
- self .resources = node_resources
27
24
self .status = NodeStatus [status .upper ()]
28
- self ._api = api
25
+ self .cluster = cluster
29
26
self .cpu = kwargs .get ("cpu" , 0 )
30
27
self .allocatedcpu = 0
31
28
self .maxcpu = kwargs .get ("maxcpu" , 0 )
@@ -52,7 +49,7 @@ def __str__(self):
52
49
def _init_vms (self ):
53
50
self .vms = []
54
51
if self .status == NodeStatus .ONLINE :
55
- self .vms = [PVEVm (self ._api , self .node , vm ["vmid" ], vm ["status" ], vm ) for vm in self .resources_vms ]
52
+ self .vms = [PVEVm (self .api , self .node , vm ["vmid" ], vm ["status" ], vm ) for vm in self .resources_vms ]
56
53
57
54
def _init_allocatedmem (self ):
58
55
"""Compute the amount of memory allocated to running VMs"""
@@ -70,6 +67,14 @@ def _init_allocatedcpu(self):
70
67
continue
71
68
self .allocatedcpu += vm .cpus
72
69
70
+ @property
71
+ def api (self ):
72
+ return self .cluster .api
73
+
74
+ @property
75
+ def resources (self ):
76
+ return [resource for resource in self .cluster .resources if resource .get ("node" ) == self .node ]
77
+
73
78
@property
74
79
def resources_vms (self ):
75
80
return [resource for resource in self .resources if resource ["type" ] == "qemu" ]
0 commit comments