Commit 0c3be3e9 by Guba Sándor Committed by Őry Máté

node: add decorator to check no availablity

parent 01eb957e
......@@ -25,6 +25,17 @@ from django.utils import timezone
logger = getLogger(__name__)
def node_available(function):
"""Decorate methods to ignore disabled Nodes.
def decorate(self, *args, **kwargs):
if self.enabled is True and is True:
return function(self, *args, **kwargs)
return None
return decorate
class Node(TimeStampedModel):
"""A VM host machine, a hypervisor.
......@@ -68,6 +79,7 @@ class Node(TimeStampedModel):
online = property(get_online)
def get_num_cores(self):
"""Number of CPU threads available to the virtual machines.
......@@ -106,6 +118,7 @@ class Node(TimeStampedModel):
def get_ram_size(self):
"""Bytes of total memory in the node.
......@@ -115,6 +128,7 @@ class Node(TimeStampedModel):
ram_size = property(get_ram_size)
def ram_size_with_overcommit(self):
"""Bytes of total memory including overcommit margin.
......@@ -198,6 +212,7 @@ class Node(TimeStampedModel):
return default
def get_monitor_info(self):
handler = GraphiteHandler()
......@@ -229,17 +244,21 @@ class Node(TimeStampedModel):
return collected
def cpu_usage(self):
return float(self.get_monitor_info()["cpu.usage"]) / 100
def ram_usage(self):
return float(self.get_monitor_info()["memory.usage"]) / 100
def byte_ram_usage(self):
return self.ram_usage * self.ram_size
def update_vm_states(self):
"""Update state of Instances running on this Node.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment