blob: 24c5b85faabc15429b0ef717fa7b52fbe843fff8 [file] [log] [blame]
Scott Baker7e472dd2015-07-31 12:30:28 -07001import os
2import sys
3
Tony Mackd8515472015-08-19 11:58:18 -04004from core.models import Slice,Instance,User,Flavor,Node,Image
Scott Baker7e472dd2015-07-31 12:30:28 -07005
6class XOSNodeSelector(object):
Scott Bakere2c95832015-08-10 17:06:42 -07007 def __init__(self, user, mem_size=None, num_cpus=None, disk_size=None, hostname = None):
Scott Baker7e472dd2015-07-31 12:30:28 -07008 self.user = user
Scott Bakere2c95832015-08-10 17:06:42 -07009 self.hostname = None
Scott Baker7e472dd2015-07-31 12:30:28 -070010
11 def get_allowed_nodes(self):
12 # TODO: logic to get nodes that the user can use
13 nodes = Node.objects.all()
Scott Bakere2c95832015-08-10 17:06:42 -070014
15 if self.hostname:
16 nodes = nodes.filter(name = self.hostname)
17
Scott Baker7e472dd2015-07-31 12:30:28 -070018 return nodes
19
20 def get_nodes(self, quantity):
21 nodes = self.get_allowed_nodes()
22 # TODO: sort the nodes by some useful metric to pick the best one
23 return nodes[:quantity]
24