fix label filtering
Change-Id: Ic25d3a029beee19065bfc5ef801cb0826934ccc7
diff --git a/xos/core/models/service.py b/xos/core/models/service.py
index df91e8c..a9b3aea 100644
--- a/xos/core/models/service.py
+++ b/xos/core/models/service.py
@@ -582,17 +582,24 @@
def pick(self):
from core.models import Node
- if not self.slice.default_node:
- nodes = list(Node.objects.all())
- nodes = sorted(nodes, key=lambda node: node.instances.all().count())
- else:
- nodes = list(Node.objects.filter(name = self.slice.default_node))
+ # start with all nodes
+ nodes = Node.objects.all()
+
+ # if a label is set, then filter by label
if self.label:
nodes = nodes.filter(nodelabels__name=self.label)
+ # if slice.default_node is set, then filter by default_node
+ if self.slice.default_node:
+ nodes = nodes.filter(name = self.slice.default_node)
+
+ # convert to list
nodes = list(nodes)
+ # sort so that we pick the least-loaded node
+ nodes = sorted(nodes, key=lambda node: node.instances.all().count())
+
if not nodes:
raise Exception(
"LeastLoadedNodeScheduler: No suitable nodes to pick from")