Commit d039ad8a by Dudás Ádám

vm: make the employed scheduler a config parameter

parent a262e19a
...@@ -301,3 +301,5 @@ VM_ACCESS_PROTOCOLS = loads(get_env_variable('DJANGO_VM_ACCESS_PROTOCOLS', ...@@ -301,3 +301,5 @@ VM_ACCESS_PROTOCOLS = loads(get_env_variable('DJANGO_VM_ACCESS_PROTOCOLS',
'''{"nx": ["nx", 22, "tcp"], '''{"nx": ["nx", 22, "tcp"],
"rdp": ["rdp", 3389, "tcp"], "rdp": ["rdp", 3389, "tcp"],
"ssh": ["ssh", 22, "tcp"]}''')) "ssh": ["ssh", 22, "tcp"]}'''))
VM_SCHEDULER = 'manager.scheduler'
def get_node(instance): def get_node(instance, nodes):
''' Select a node for an hosting an instance ''' Select a node for hosting an instance based on its requirements.
based on requirements.
''' '''
# Return first Node or None # Return first Node or None
models = __import__('vm.models')
try: try:
return models.models.Node.objects.all()[0] return nodes[0]
except: except:
return None return None
from datetime import timedelta from datetime import timedelta
from importlib import import_module
import django.conf
import logging import logging
import django.conf.settings
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.db import models from django.db import models
from django.db.models.signals import pre_delete from django.db.models.signals import pre_delete
...@@ -13,12 +14,13 @@ from netaddr import EUI ...@@ -13,12 +14,13 @@ from netaddr import EUI
from . import tasks from . import tasks
from firewall.models import Vlan, Host from firewall.models import Vlan, Host
from manager import vm_manager, scheduler from manager import vm_manager
from storage.models import Disk from storage.models import Disk
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
pwgen = User.objects.make_random_password pwgen = User.objects.make_random_password
scheduler = import_module(name=django.conf.settings.VM_SCHEDULER)
ACCESS_PROTOCOLS = django.conf.settings.VM_ACCESS_PROTOCOLS ACCESS_PROTOCOLS = django.conf.settings.VM_ACCESS_PROTOCOLS
ACCESS_METHODS = [(k, ap[0]) for k, ap in ACCESS_PROTOCOLS.iteritems()] ACCESS_METHODS = [(k, ap[0]) for k, ap in ACCESS_PROTOCOLS.iteritems()]
...@@ -443,7 +445,7 @@ class Instance(BaseResourceConfigModel, TimeStampedModel): ...@@ -443,7 +445,7 @@ class Instance(BaseResourceConfigModel, TimeStampedModel):
# Schedule # Schedule
act.update_state("PENDING") act.update_state("PENDING")
self.node = scheduler.get_node(self) self.node = scheduler.get_node(self, Node.objects.all())
self.save() self.save()
# Create virtual images # Create virtual images
......
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