commit e407f1599aa9d3dc3e7cbb139a5c0e373c615c1a
Author: Ilias Tsitsimpis <iliastsi@grnet.gr>
Date:   Fri Oct 4 12:50:53 2013 +0300

    snf-cyclades-app: Use the new AstakosClient
    
    Change AstakosClient to use ASTAKOS_AUTH_URL as entry point to the
    Astakos service, instead of ASTAKOS_BASE_URL it was using until now.
    
    Remove ASTAKOS_BASE_URL from Cyclades settings, replace it with
    ASTAKOS_AUTH_URL. Modify Cyclades to determine ASTAKOS_ACCOUNT_URL and
    ASTAKOS_UI_URL with calls to astakosclient.

diff --git a/snf-cyclades-app/synnefo/cyclades_settings.py b/snf-cyclades-app/synnefo/cyclades_settings.py
index 17e79e1..6a3c899 100644
--- a/snf-cyclades-app/synnefo/cyclades_settings.py
+++ b/snf-cyclades-app/synnefo/cyclades_settings.py
@@ -36,16 +36,18 @@ from synnefo.lib import join_urls, parse_base_url
 from synnefo.util.keypath import get_path, set_path
 from synnefo.api.services import cyclades_services as vanilla_cyclades_services
 from synnefo.lib.services import fill_endpoints
-from astakosclient import astakos_services as vanilla_astakos_services
+from astakosclient import AstakosClient
 
 from copy import deepcopy
 
 
+# --------------------------------------------------------------------
 # Process Cyclades settings
 
 BASE_URL = getattr(settings, 'CYCLADES_BASE_URL',
                    'https://compute.example.synnefo.org/compute/')
 BASE_HOST, BASE_PATH = parse_base_url(BASE_URL)
+SERVICE_TOKEN = getattr(settings, 'CYCLADES_SERVICE_TOKEN', "")
 
 CUSTOMIZE_SERVICES = getattr(settings, 'CYCLADES_CUSTOMIZE_SERVICES', ())
 cyclades_services = deepcopy(vanilla_cyclades_services)
@@ -64,33 +66,44 @@ ADMIN_PREFIX = get_path(cyclades_services, 'cyclades_admin.prefix')
 COMPUTE_ROOT_URL = join_urls(BASE_URL, COMPUTE_PREFIX)
 
 
+# --------------------------------------------------------------------
 # Process Astakos settings
 
-ASTAKOS_BASE_URL = getattr(settings, 'ASTAKOS_BASE_URL',
-                           'https://accounts.example.synnefo.org/astakos/')
-ASTAKOS_BASE_HOST, ASTAKOS_BASE_PATH = parse_base_url(ASTAKOS_BASE_URL)
-
-# Patch astakosclient directly, otherwise it will not see any customization
-#astakos_services = deepcopy(vanilla_astakos_services)
-CUSTOMIZE_ASTAKOS_SERVICES = \
-    getattr(settings, 'CYCLADES_CUSTOMIZE_ASTAKOS_SERVICES', ())
-
-astakos_services = deepcopy(vanilla_astakos_services)
-fill_endpoints(astakos_services, ASTAKOS_BASE_URL)
-for path, value in CUSTOMIZE_ASTAKOS_SERVICES:
-    set_path(astakos_services, path, value, createpath=True)
-
-ASTAKOS_ACCOUNTS_PREFIX = get_path(astakos_services, 'astakos_account.prefix')
-ASTAKOS_VIEWS_PREFIX = get_path(astakos_services, 'astakos_ui.prefix')
-ASTAKOS_KEYSTONE_PREFIX = get_path(astakos_services, 'astakos_identity.prefix')
-
-
-# Proxy Astakos settings
-
-BASE_ASTAKOS_PROXY_PATH = getattr(settings,
-                                  'CYCLADES_BASE_ASTAKOS_PROXY_PATH',
-                                  ASTAKOS_BASE_PATH)
-BASE_ASTAKOS_PROXY_PATH = join_urls(BASE_PATH, BASE_ASTAKOS_PROXY_PATH)
-BASE_ASTAKOS_PROXY_PATH = BASE_ASTAKOS_PROXY_PATH.strip('/')
-
-PROXY_USER_SERVICES = getattr(settings, 'CYCLADES_PROXY_USER_SERVICES', True)
+ASTAKOS_AUTH_URL = getattr(
+    settings, 'ASTAKOS_AUTH_URL',
+    'https://accounts.example.synnefo.org/astakos/identity/v2.0/')
+
+
+# --------------------------------------
+# Define a LazyAstakosUrl
+class LazyAstakosUrl(object):
+    def __init__(self, endpoints_name):
+        self.endpoints_name = endpoints_name
+
+    def __str__(self):
+        if not hasattr(self, 'str'):
+            try:
+                astakos_client = \
+                    AstakosClient(SERVICE_TOKEN, ASTAKOS_AUTH_URL)
+                self.str = getattr(astakos_client, self.endpoints_name)
+            except:
+                return None
+        return self.str
+
+# --------------------------------------
+# Define ASTAKOS_UI_URL and ASTAKOS_ACCOUNT_URL as LazyAstakosUrl
+ASTAKOS_ACCOUNT_URL = LazyAstakosUrl('account_url')
+ASTAKOS_UI_URL = LazyAstakosUrl('ui_url')
+
+# --------------------------------------
+# Define Astakos prefixes
+ASTAKOS_PROXY_PREFIX = getattr(settings, 'CYCLADES_PROXY_PREFIX', '_astakos')
+ASTAKOS_AUTH_PREFIX = join_urls('/', ASTAKOS_PROXY_PREFIX, 'identity')
+ASTAKOS_ACCOUNT_PREFIX = join_urls('/', ASTAKOS_PROXY_PREFIX, 'account')
+ASTAKOS_UI_PREFIX = join_urls('/', ASTAKOS_PROXY_PREFIX, 'ui')
+
+# --------------------------------------
+# Define Astakos proxy paths
+ASTAKOS_AUTH_PROXY_PATH = join_urls(BASE_PATH, ASTAKOS_AUTH_PREFIX)
+ASTAKOS_ACCOUNT_PROXY_PATH = join_urls(BASE_PATH, ASTAKOS_ACCOUNT_PREFIX)
+ASTAKOS_UI_PROXY_PATH = join_urls(BASE_PATH, ASTAKOS_UI_PREFIX)
