Commit 0ea5e0fd by Belákovics Ádám

added the new algorithm to SCHEDULER_METHODs

parents 11d0ec42 e8684154
Pipeline #671 passed with stage
in 0 seconds
......@@ -574,6 +574,9 @@ SESSION_COOKIE_NAME = "csessid%x" % (((getnode() // 139) ^
(getnode() % 983)) & 0xffff)
MAX_NODE_RAM = get_env_variable("MAX_NODE_RAM", 1024)
MAX_NODE_CPU_CORE = get_env_variable("MAX_NODE_CPU_CORE", 10)
SCHEDULER_METHOD = get_env_variable("SCHEDULER_METHOD", 'random')
# Url to download the client: (e.g. http://circlecloud.org/client/download/)
CLIENT_DOWNLOAD_URL = get_env_variable('CLIENT_DOWNLOAD_URL', 'http://circlecloud.org/client/download/')
......
......@@ -59,7 +59,7 @@ from storage.models import DataStore, Disk
from django.contrib.admin.widgets import FilteredSelectMultiple
from django.contrib.auth.models import Permission
from .models import Profile, GroupProfile, Message
from circle.settings.base import LANGUAGES, MAX_NODE_RAM
from circle.settings.base import LANGUAGES, MAX_NODE_RAM, MAX_NODE_CPU_CORE
from django.utils.translation import string_concat
from .validators import domain_validator
......@@ -118,10 +118,10 @@ class VmCustomizeForm(forms.Form):
cpu_count = forms.IntegerField(widget=forms.NumberInput(attrs={
'class': "form-control input-tags cpu-count-input",
'min': 1,
'max': 10,
'max': MAX_NODE_CPU_CORE,
'required': "",
}),
min_value=1, max_value=10,
min_value=1, max_value=MAX_NODE_CPU_CORE,
)
ram_size = forms.IntegerField(widget=forms.TextInput(attrs={
......@@ -466,10 +466,10 @@ class TemplateForm(forms.ModelForm):
num_cores = forms.IntegerField(widget=forms.NumberInput(attrs={
'class': "form-control input-tags cpu-count-input",
'min': 1,
'max': 10,
'max': MAX_NODE_CPU_CORE,
'required': "",
}),
min_value=1, max_value=10,
min_value=1, max_value=MAX_NODE_CPU_CORE,
)
ram_size = forms.IntegerField(widget=forms.NumberInput(attrs={
......@@ -1508,10 +1508,10 @@ class VmResourcesForm(forms.ModelForm):
num_cores = forms.IntegerField(widget=forms.NumberInput(attrs={
'class': "form-control input-tags cpu-count-input",
'min': 1,
'max': 10,
'max': MAX_NODE_CPU_CORE,
'required': "",
}),
min_value=1, max_value=10,
min_value=1, max_value=MAX_NODE_CPU_CORE,
)
ram_size = forms.IntegerField(widget=forms.NumberInput(attrs={
......
......@@ -73,7 +73,9 @@
{% if l.ipv4 %}
<tr>
<td>
{% autoescape off %}
{% display_portforward4 l %}
{% endautoescape %}
</td>
<td><i class="fa fa-long-arrow-right"></i></td>
<td>
......
......@@ -23,6 +23,10 @@ from django.conf import settings
from common.models import HumanReadableException
from circle.settings.base import SCHEDULER_METHOD
import random
logger = getLogger(__name__)
......@@ -52,9 +56,7 @@ class TraitsUnsatisfiableException(SchedulerError):
"new virtual machine currently.")
def select_node(instance, nodes):
''' Select a node for hosting an instance based on its requirements.
'''
def common_select(instance, nodes):
# check required traits
nodes = [n for n in nodes
if n.schedule_enabled and n.online and
......@@ -71,9 +73,40 @@ def select_node(instance, nodes):
# sort nodes first by sorting_key, then priority
nodes.sort(key=lambda n: n.priority, reverse=True)
return nodes
def common_evenly(instance, nodes):
nodes = common_select(instance, nodes)
nodes.sort(key=free_cpu_time, reverse=True)
result = nodes[0]
return result
def common_random(instance, nodes):
nodes = common_select(instance, nodes)
result = random.choice(nodes)
return result
def advanced_with_time_stamp(instance, nodes):
nodes = common_select(instance, nodes)
nodes.sort(key=sorting_key, reverse=True)
result = nodes[0]
return result
def select_node(instance, nodes):
''' Select a node for hosting an instance based on its requirements.
'''
if SCHEDULER_METHOD == 'evenly':
result = common_evenly(instance, nodes)
elif SCHEDULER_METHOD == 'random':
result = common_random(instance, nodes)
elif SCHEDULER_METHOD == 'advanced':
result = advanced_with_time_stamp(instance, nodes)
else: # Default method is the random
result = common_random(instance, nodes)
logger.info('Scheduler method: %s selected', unicode(SCHEDULER_METHOD))
logger.info('select_node: %s for %s', unicode(result), unicode(instance))
result.time_stamp = timezone.now()
......
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