Commit 3bf3920a authored by Christos Stavrakakis's avatar Christos Stavrakakis

Allocate VMs based on enabled disk-templates

Remove the ARCHIPELAGO_BACKENDS setting. Instead allocate VMs based on
the disk-templates that are enabled and allowed in ipolicy for each
backend. The command 'snf-manage backend-update-status' can be used to
update the list of enabled disk templates for each backend.
parent b603c1b7
......@@ -60,6 +60,9 @@ Cyclades
setting.
* Change --dhcp option of network management commands from a flag to a boolean
value, e.g. --dhcp=True
* Remove 'ARCHIPELAGO_BACKENDS' setting used to distinquish between backends
that hosted only archipelago backends. Instead allocation is based on which
disk-templates are enabled in each backend.
Pithos
------
......
......@@ -62,9 +62,6 @@
## e.g. BACKEND_PER_USER = {'example@synnefo.org': 2}
#BACKEND_PER_USER = {}
#
## List of backend IDs used *only* for archipelago.
#ARCHIPELAGO_BACKENDS = []
#
#
## URL templates for the stat graphs.
## The API implementation replaces '%s' with the encrypted backend id.
......
......@@ -61,9 +61,6 @@ DEFAULT_FIREWALL_PROFILE = 'DISABLED'
# e.g. BACKEND_PER_USER = {'example@synnefo.org': 2}
BACKEND_PER_USER = {}
# List of backend IDs used *only* for archipelago.
ARCHIPELAGO_BACKENDS = []
# URL templates for the stat graphs.
# The API implementation replaces '%s' with the encrypted backend id.
......
......@@ -32,7 +32,7 @@ import datetime
from django.utils import importlib
from synnefo.settings import (BACKEND_ALLOCATOR_MODULE, BACKEND_REFRESH_MIN,
BACKEND_PER_USER, ARCHIPELAGO_BACKENDS,
BACKEND_PER_USER,
DEFAULT_INSTANCE_NETWORKS)
from synnefo.db.models import Backend
from synnefo.logic.backend import update_backend_resources
......@@ -72,11 +72,8 @@ class BackendAllocator():
log.debug("Allocating VM: %r", vm)
# Get available backends
available_backends = get_available_backends()
available_backends = get_available_backends(flavor)
# Temporary fix for distinquishing archipelagos capable backends
available_backends = filter_archipelagos_backends(available_backends,
flavor.disk_template)
# Refresh backends, if needed
refresh_backends_stats(available_backends)
......@@ -96,27 +93,26 @@ class BackendAllocator():
return backend
def get_available_backends():
"""Get available backends from db.
def get_available_backends(flavor):
"""Get the list of available backends that can host a new VM of a flavor.
The list contains the backends that are online and that have enabled
the disk_template of the new VM.
Also, if the new VM will be automatically connected to a public network,
the backends that do not have an available public IPv4 address are
excluded.
"""
backends = list(Backend.objects.select_for_update().filter(drained=False,
offline=False))
backends = Backend.objects.select_for_update()
backends = backends.filter(offline=False, drained=False,
disk_templates__contains=flavor.disk_template)
backends = list(backends)
if "SNF:ANY_PUBLIC" in DEFAULT_INSTANCE_NETWORKS:
backends = filter(lambda x: has_free_ip(x), backends)
return backends
def filter_archipelagos_backends(available_backends, disk_template):
if disk_template == "ext":
available_backends = filter(lambda x: x.id in ARCHIPELAGO_BACKENDS,
available_backends)
else:
available_backends = filter(lambda x: x.id not in ARCHIPELAGO_BACKENDS,
available_backends)
return available_backends
def has_free_ip(backend):
"""Find if Backend has any free public IP."""
for network in backend_public_networks(backend):
......
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 to comment