commit f15bf3d90069c4a497db602507d298420e4e8cc5
Author: Christos Stavrakakis <cstavr@grnet.gr>
Date:   Mon Sep 30 15:17:28 2013 +0300

    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.

diff --git a/Changelog b/Changelog
index 6c2176c..2555ee0 100644
--- a/Changelog
+++ b/Changelog
@@ -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
 ------
diff --git a/snf-cyclades-app/conf/20-snf-cyclades-app-api.conf b/snf-cyclades-app/conf/20-snf-cyclades-app-api.conf
index 298294f..d56c33c 100644
--- a/snf-cyclades-app/conf/20-snf-cyclades-app-api.conf
+++ b/snf-cyclades-app/conf/20-snf-cyclades-app-api.conf
@@ -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.
diff --git a/snf-cyclades-app/synnefo/app_settings/default/api.py b/snf-cyclades-app/synnefo/app_settings/default/api.py
index bb2bd88..37a1e17 100644
--- a/snf-cyclades-app/synnefo/app_settings/default/api.py
+++ b/snf-cyclades-app/synnefo/app_settings/default/api.py
@@ -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.
diff --git a/snf-cyclades-app/synnefo/logic/backend_allocator.py b/snf-cyclades-app/synnefo/logic/backend_allocator.py
index eea0384..01233aa 100644
--- a/snf-cyclades-app/synnefo/logic/backend_allocator.py
+++ b/snf-cyclades-app/synnefo/logic/backend_allocator.py
@@ -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):
