Scott Baker | 7e472dd | 2015-07-31 12:30:28 -0700 | [diff] [blame] | 1 | import os |
| 2 | import sys |
| 3 | |
Tony Mack | d851547 | 2015-08-19 11:58:18 -0400 | [diff] [blame] | 4 | from core.models import Slice,Instance,User,Flavor,Node,Image |
Scott Baker | 7e472dd | 2015-07-31 12:30:28 -0700 | [diff] [blame] | 5 | |
| 6 | class XOSNodeSelector(object): |
Scott Baker | e2c9583 | 2015-08-10 17:06:42 -0700 | [diff] [blame] | 7 | def __init__(self, user, mem_size=None, num_cpus=None, disk_size=None, hostname = None): |
Scott Baker | 7e472dd | 2015-07-31 12:30:28 -0700 | [diff] [blame] | 8 | self.user = user |
Scott Baker | e2c9583 | 2015-08-10 17:06:42 -0700 | [diff] [blame] | 9 | self.hostname = None |
Scott Baker | 7e472dd | 2015-07-31 12:30:28 -0700 | [diff] [blame] | 10 | |
| 11 | def get_allowed_nodes(self): |
| 12 | # TODO: logic to get nodes that the user can use |
| 13 | nodes = Node.objects.all() |
Scott Baker | e2c9583 | 2015-08-10 17:06:42 -0700 | [diff] [blame] | 14 | |
| 15 | if self.hostname: |
| 16 | nodes = nodes.filter(name = self.hostname) |
| 17 | |
Scott Baker | 7e472dd | 2015-07-31 12:30:28 -0700 | [diff] [blame] | 18 | 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 | |