Commit 0a580d1d by Chif Gergő

Aggregate nodes in error message

Each node, which has unreachable monitor info shown in one error message.
parent 01039675
......@@ -193,7 +193,6 @@ class NodeList(LoginRequiredMixin, GraphMixin, SingleTableView):
def get(self, *args, **kwargs):
if not self.request.user.has_perm('vm.view_statistics'):
raise PermissionDenied()
self.wrong_nodes_message()
if self.request.is_ajax():
nodes = Node.objects.all()
nodes = [{
......@@ -211,14 +210,20 @@ class NodeList(LoginRequiredMixin, GraphMixin, SingleTableView):
return super(NodeList, self).get(*args, **kwargs)
def get_queryset(self):
self.wrong_nodes_message()
return Node.objects.annotate(
number_of_VMs=Count('instance_set')).select_related('host')
def wrong_nodes_message(self):
wrong_nodes = ''
for node in Node.objects.all():
if node.monitor_info is None:
if wrong_nodes != '':
wrong_nodes += ','
wrong_nodes += ' ' + node.name
if wrong_nodes != '':
messages.error(self.request,
"Can't reach " + node.name + " monitor info")
"Can't reach" + wrong_nodes + " monitor info")
class NodeCreate(LoginRequiredMixin, SuperuserRequiredMixin, TemplateView):
......
......@@ -364,6 +364,8 @@ class Node(OperatedMixin, TimeStampedModel):
return self.info.get('driver_version')
def get_monitor_info(self, metric):
# return with the metric value if the monitor info not none
# or return 0 if its None or the metric unreachable
if self.monitor_info is None:
return 0
elif self.monitor_info.get(metric) is None:
......
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