Commit 79f2ca3b authored by Georgios D. Tsoukalas's avatar Georgios D. Tsoukalas

make synnefo URLs consistent and configurable

https://service.deployment.vendor.tld/service-base/api-prefix/hard/path
|___________________________________| |__________| |________| |_______|
             BASE_HOST                  BASE_PATH    PREFIX    Hardcoded
|_________________________________________________|
             SERVICE_BASE_URL

- Introduce <SERVICE>_BASE_URL setting, and <API>_PREFIX constants
  for all services. Extract BASE_HOST, BASE_PATH from the setting.

- Use settings and constants to construct top-level patterns
  (base-path/api-prefix) in services' urls.py

- Refactor/extend proxy() to be compatible with the above.

- Change URLs passed around (ui, e-mails) to be compatible.
  (needs more work)

Notes:

This configuration REQUIRES that any rewriting and proxying on the
front-end must eventually result in the application server (gunicorn)
getting the original path of the request, otherwise the view-generated
URLs will be different.

Changes:
- set top-level urlpatterns from <SERVICE>_BASE_URL
- rename setting: APP_INSTALL_URL to CYCLADES_BASE_URL
- rename setting: ASTAKOS_URL to ASTAKOS_BASE_URL everywhere
- introduce setting: PITHOS_BASE_URL
- update shipped .confs, quick install admin guide, upgrade guide
- fix urls/views/reverse()/other that were broken
- (more not listed)
parent d14a3233
......@@ -45,20 +45,29 @@ from astakosclient.errors import \
NoUserName, NoUUID, BadValue, QuotaLimit, InvalidResponse
def join_urls(a, b):
"""join_urls from synnefo.lib"""
return a.rstrip("/") + "/" + b.lstrip("/")
# --------------------------------------------------------------------
# Astakos API urls
API_AUTHENTICATE = "/astakos/api/authenticate"
API_USERCATALOGS = "/astakos/api/user_catalogs"
API_SERVICE_USERCATALOGS = "/astakos/api/service/user_catalogs"
API_GETSERVICES = "/astakos/api/get_services"
API_RESOURCES = "/astakos/api/resources"
API_QUOTAS = "/astakos/api/quotas"
API_SERVICE_QUOTAS = "/astakos/api/service_quotas"
API_COMMISSIONS = "/astakos/api/commissions"
API_COMMISSIONS_ACTION = API_COMMISSIONS + "/action"
API_FEEDBACK = "/astakos/api/feedback"
API_TOKENS = "/astakos/api/tokens"
TOKENS_ENDPOINTS = "endpoints"
ACCOUNTS_PREFIX = 'accounts'
API_AUTHENTICATE = join_urls(ACCOUNTS_PREFIX, "authenticate")
API_USERCATALOGS = join_urls(ACCOUNTS_PREFIX, "user_catalogs")
API_SERVICE_USERCATALOGS = join_urls(ACCOUNTS_PREFIX, "service/user_catalogs")
API_GETSERVICES = join_urls(ACCOUNTS_PREFIX, "get_services")
API_RESOURCES = join_urls(ACCOUNTS_PREFIX, "resources")
API_QUOTAS = join_urls(ACCOUNTS_PREFIX, "quotas")
API_SERVICE_QUOTAS = join_urls(ACCOUNTS_PREFIX, "service_quotas")
API_COMMISSIONS = join_urls(ACCOUNTS_PREFIX, "commissions")
API_COMMISSIONS_ACTION = join_urls(API_COMMISSIONS, "action")
API_FEEDBACK = join_urls(ACCOUNTS_PREFIX, "feedback")
# --------------------------------------------------------------------
# Astakos Keystone API urls
KEYSTONE_PREFIX = 'keystone'
API_TOKENS = join_urls(KEYSTONE_PREFIX, "tokens")
TOKENS_ENDPOINTS = join_urls(API_TOKENS, "endpoints")
# --------------------------------------------------------------------
......
......@@ -581,10 +581,10 @@ For astakos specific configuration, edit the following options in
ASTAKOS_COOKIE_DOMAIN = '.example.com'
ASTAKOS_BASEURL = 'https://node1.example.com'
ASTAKOS_BASE_URL = 'https://node1.example.com'
The ``ASTAKOS_COOKIE_DOMAIN`` should be the base url of our domain (for all
services). ``ASTAKOS_BASEURL`` is the astakos home page.
services). ``ASTAKOS_BASE_URL`` is the astakos top-level URL.
``ASTAKOS_DEFAULT_ADMIN_EMAIL`` refers to the administrator's email.
Every time a new account is created a notification is sent to this email.
......@@ -834,7 +834,7 @@ this options:
.. code-block:: console
ASTAKOS_URL = 'https://node1.example.com/'
ASTAKOS_BASE_URL = 'https://node1.example.com/'
PITHOS_BACKEND_DB_CONNECTION = 'postgresql://synnefo:example_passw0rd@node1.example.com:5432/snf_pithos'
PITHOS_BACKEND_BLOCK_PATH = '/srv/pithos/data'
......@@ -857,8 +857,8 @@ the Pithos backend data. Above we tell Pithos to store its data under
``/srv/pithos/data``, which is visible by both nodes. We have already setup this
directory at node1's "Pithos data directory setup" section.
The ``ASTAKOS_URL`` option tells to the Pithos app in which URI
is available the astakos authentication api.
The ``ASTAKOS_BASE_URL`` option informs the Pithos app where Astakos is.
The Astakos service is used for user management (authentication, quotas, etc.)
The ``PITHOS_SERVICE_TOKEN`` should be the Pithos token returned by running on
the Astakos node (node1 in our case):
......@@ -1682,14 +1682,17 @@ Edit ``/etc/synnefo/20-snf-cyclades-app-api.conf``:
.. code-block:: console
ASTAKOS_URL = 'https://node1.example.com/'
CYCLADES_BASE_URL = 'https://node1.example.com/cyclades'
ASTAKOS_BASE_URL = 'https://node1.example.com/astakos'
# Set to False if astakos & cyclades are on the same host
CYCLADES_PROXY_USER_SERVICES = False
The ``ASTAKOS_URL`` denotes the authentication endpoint for Cyclades and is set
to point to Astakos (this should have the same value with Pithos's
``ASTAKOS_URL``, setup :ref:`previously <conf-pithos>`).
The ``ASTAKOS_BASE_URL`` denotes the Astakos endpoint for Cyclades,
which is used for all user management, including authentication.
Since our Astakos, Cyclades, and Pithos installations belong together,
they should all have identical ``ASTAKOS_BASE_URL`` setting
(see also, :ref:`previously <conf-pithos>`).
.. warning::
......
......@@ -44,7 +44,7 @@ In `/etc/synnefo/astakos.conf` add:
ASTAKOS_IM_MODULES = ['local']
ASTAKOS_BASEURL = 'https://accounts.example.com'
ASTAKOS_BASE_URL = 'https://accounts.example.com'
ASTAKOS_SITENAME = '~okeanos @ example.com'
ASTAKOS_RECAPTCHA_PUBLIC_KEY = '6LeFidMSAAAAAM7Px7a96YQzsBcKYeXCI_sFz0Gk'
......
......@@ -51,7 +51,7 @@ In `/etc/synnefo/cyclades.conf` add:
GANETI_DISK_TEMPLATES = ('blockdev', 'diskless', 'drbd', 'file', 'plain',
'rbd', 'sharedfile', 'ext')
ASTAKOS_URL = 'https://accounts.example.com/'
ASTAKOS_BASE_URL = 'https://accounts.example.synnefo.org/'
SECRET_ENCRYPTION_KEY= "oEs0pt7Di1mkxA0P6FiK"
......
......@@ -56,7 +56,7 @@ In `/etc/synnefo/pithos.conf` add:
.. code-block:: console
ASTAKOS_URL = 'https:/accounts.example.com/'
ASTAKOS_BASE_URL = 'https://accounts.example.com/'
PITHOS_BACKEND_DB_CONNECTION = 'postgresql://synnefo:example_passw0rd@db.example.com:5432/snf_pithos'
PITHOS_BACKEND_BLOCK_PATH = '/srv/pithos/data'
......
......@@ -23,9 +23,9 @@ Usage
::
snf-burnin --token=TOKEN \
--api=CYCLADES_URL
--pithos=PITHOS_URL \
--astakos=ASTAKOS_URL \
--api=CYCLADES_BASE_URL
--pithos=PITHOS_BASE_URL \
--astakos=ASTAKOS_BASE_URL \
--plankton=PLANKTON_URL \
--plankton-user=PLANKTON_SYSTEM_USER \
--image-id=IMAGE_ID \
......
......@@ -46,6 +46,25 @@ The bulk of the upgrade to v0.14 is about resource and quota migrations.
cyclades-host$ snf-manage migrate
2.3 Configure Base URL settings for all services
------------------------------------------------
In order to make all services' URLs configurable and discoverable from
a single endpoint in Astakos through the Openstack Keystone API,
every service has a ``XXXXX_BASE_URL`` setting, or it's old corresponding
setting was renamed to this. Therefore:
* Rename ``ASTAKOS_URL`` setting to ``ASTAKOS_BASE_URL``
everywhere in your settings, in all nodes and all config files.
This must point to the top-level Astakos URL.
* In Cyclades settings, rename the ``APP_INSTALL_URL`` setting
to ``CYCLADES_BASE_URL``. If no such setting has been configured,
you must set it. It must point to the top-level Cyclades URL.
* In Pithos settings, introduce a ``PITHOS_BASE_URL`` setting.
It must point to the top-level Pithos URL.
3 Quota-related steps
=====================
......
......@@ -81,7 +81,8 @@ def send_verification(user, template_name='im/activation_email.txt'):
"""
Send email to user to verify his/her email and activate his/her account.
"""
url = join_urls(settings.BASEURL, user.get_activation_url(nxt=reverse('index')))
url = join_urls(settings.BASE_HOST,
user.get_activation_url(nxt=reverse('index')))
message = render_to_string(template_name, {
'user': user,
'url': url,
......
from django.conf import settings
from synnefo_branding import settings as synnefo_settings
from synnefo.lib import parse_base_url
BASE_URL = getattr(settings, 'ASTAKOS_BASE_URL',
'https://accounts.example.synnefo.org')
BASE_HOST, BASE_PATH = parse_base_url(BASE_URL)
ACCOUNTS_PREFIX = getattr(settings, 'ASTAKOS_ACCOUNTS_PREFIX', 'accounts')
VIEWS_PREFIX = getattr(settings, 'ASTAKOS_VIEWS_PREFIX', 'im')
KEYSTONE_PREFIX = getattr(settings, 'ASTAKOS_ACCOUNTS_PREFIX', 'keystone')
# Set the expiration time of newly created auth tokens
# to be this many hours after their creation time.
......@@ -45,7 +56,7 @@ IM_STATIC_URL = getattr(settings, 'ASTAKOS_IM_STATIC_URL', '/static/im/')
MODERATION_ENABLED = getattr(settings, 'ASTAKOS_MODERATION_ENABLED', True)
# Set baseurl
BASEURL = getattr(settings, 'ASTAKOS_BASEURL', 'https://accounts.example.synnefo.org')
BASEURL = getattr(settings, 'ASTAKOS_BASE_URL', 'https://accounts.example.synnefo.org')
# Set service name
SITENAME = getattr(settings, 'ASTAKOS_SITENAME', synnefo_settings.SERVICE_NAME)
......
......@@ -18,7 +18,7 @@ DATABASES = {
HOST = 'http://127.0.0.1'
ASTAKOS_URL = HOST + ':8000/astakos/api/authenticate'
ASTAKOS_BASEURL = HOST + ':8000/'
# FIXME: ASTAKOS_URL = HOST + ':8000/astakos/api/authenticate'
ASTAKOS_BASE_URL = HOST + ':8000/'
ASTAKOS_IM_MODULES = ['local']
ASTAKOS_RECAPTCHA_ENABLED = False
......@@ -32,17 +32,32 @@
# or implied, of GRNET S.A.
from django.conf.urls.defaults import include, patterns
from synnefo.lib import join_urls
from astakos.im.settings import (
BASE_PATH, ACCOUNTS_PREFIX, VIEWS_PREFIX, KEYSTONE_PREFIX
)
from snf_django.lib.api.utils import prefix_pattern
urlpatterns = patterns(
astakos_patterns = patterns(
'',
(r'^im/', include('astakos.im.urls')),
(r'^astakos/api/', include('astakos.api.urls')),
(r'^login/?$', 'astakos.im.views.target.redirect.login')
(prefix_pattern(VIEWS_PREFIX), include('astakos.im.urls')),
(prefix_pattern(ACCOUNTS_PREFIX), include('astakos.api.urls')),
#(prefix_pattern(KEYSTONE_PREFIX), include('astakos.api.keystone_urls')),
)
# Compatibility: expose some API URLs at top-level
compatibility_patterns = patterns(
'astakos',
(r'^login/?$', 'im.views.target.redirect.login'),
(r'^feedback/?$', 'api.user.send_feedback'),
(r'^user_catalogs/?$', 'api.user.get_uuid_displayname_catalogs'),
(r'^service/api/user_catalogs/?$',
'api.service.get_uuid_displayname_catalogs'),
)
urlpatterns += patterns(
'astakos.api',
(r'^feedback/?$', 'user.send_feedback'),
(r'^user_catalogs/?$', 'user.get_uuid_displayname_catalogs'),
(r'^service/api/user_catalogs/?$', 'service.get_uuid_displayname_catalogs')
astakos_patterns += compatibility_patterns
urlpatterns = patterns(
'',
(prefix_pattern(BASE_PATH), include(astakos_patterns)),
)
......@@ -33,7 +33,7 @@
#ASTAKOS_MODERATION_ENABLED = True
# Set baseurl
#ASTAKOS_BASEURL = 'https://accounts.example.synnefo.org'
#ASTAKOS_BASE_URL = 'https://accounts.example.synnefo.org'
# Set service name
#ASTAKOS_SITENAME = 'Synnefo Cloud'
......
......@@ -31,6 +31,8 @@
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.
from urlparse import urlparse
def join_urls(a, b):
"""
......@@ -56,6 +58,25 @@ def join_urls(a, b):
"""
return a.rstrip("/") + "/" + b.lstrip("/")
def parse_base_url(base_url):
"""
>>> parse_base_url("https://one.two.three/four/five")
('https://one.two.three', '/four/five')
>>> parse_base_url("https://one.two.three/four/five/")
('https://one.two.three', '/four/five/')
>>> parse_base_url("https://one.two.three/")
('https://one.two.three', '/')
>>> parse_base_url("https://one.two.three")
('https://one.two.three', '/')
"""
parsed = urlparse(base_url)
base_path = parsed.path.strip('/')
base_host = parsed.scheme + '://' + parsed.netloc
return base_host, base_path
if __name__ == "__main__":
import doctest
doctest.testmod()
......@@ -7,11 +7,11 @@
#DEBUG = False
#
## Top-level URL for deployment. Numerous other URLs depend on this.
#APP_INSTALL_URL = "https://host:port"
#CYCLADES_BASE_URL = "https://host:port/cyclades"
#
## The API implementation needs to accept and return absolute references
## to its resources. Thus, it needs to know its public URL.
#API_ROOT_URL = APP_INSTALL_URL + '/api'
#API_ROOT_URL = CYCLADES_BASE_URL.rstrip('/') + '/api'
#
## The API will return HTTP Bad Request if the ?changes-since
## parameter refers to a point in time more than POLL_LIMIT seconds ago.
......@@ -95,8 +95,8 @@
# 'rbd', 'sharedfile')
#DEFAULT_GANETI_DISK_TEMPLATE = 'drbd'
#
## The URL of an astakos instance that will be used for user authentication
#ASTAKOS_URL = 'https://accounts.example.org/'
## Top-level URL of the astakos instance to be used for user management
#ASTAKOS_BASE_URL = 'https://accounts.example.synnefo.org/'
#
## Key for password encryption-decryption. After changing this setting, synnefo
## will be unable to decrypt all existing Backend passwords. You will need to
......
......@@ -40,11 +40,11 @@ from django.conf import settings
from synnefo.lib import join_urls
ASTAKOS_URL = getattr(settings, 'ASTAKOS_URL', None)
USER_QUOTA_URL = join_urls(ASTAKOS_URL, "astakos/api/quotas")
RESOURCES_URL = join_urls(ASTAKOS_URL, "astakos/api/resources")
USER_CATALOG_URL = join_urls(ASTAKOS_URL, "astakos/api/user_catalogs")
USER_FEEDBACK_URL = join_urls(ASTAKOS_URL, "astakos/api/feedback")
ASTAKOS_BASE_URL = getattr(settings, 'ASTAKOS_BASE_URL', None)
USER_QUOTA_URL = join_urls(ASTAKOS_BASE_URL, "astakos/api/quotas")
RESOURCES_URL = join_urls(ASTAKOS_BASE_URL, "astakos/api/resources")
USER_CATALOG_URL = join_urls(ASTAKOS_BASE_URL, "astakos/api/user_catalogs")
USER_FEEDBACK_URL = join_urls(ASTAKOS_BASE_URL, "astakos/api/feedback")
from objpool.http import PooledHTTPConnection
......
......@@ -36,7 +36,7 @@ from optparse import make_option
from synnefo.webproject.management.commands import ListCommand
from synnefo.db.models import Network
from synnefo.settings import (CYCLADES_ASTAKOS_SERVICE_TOKEN as ASTAKOS_TOKEN,
ASTAKOS_URL)
ASTAKOS_BASE_URL)
from logging import getLogger
log = getLogger(__name__)
......@@ -61,7 +61,7 @@ class Command(ListCommand):
object_class = Network
deleted_field = "deleted"
user_uuid_field = "userid"
astakos_url = ASTAKOS_URL
astakos_url = ASTAKOS_BASE_URL
astakos_token = ASTAKOS_TOKEN
def get_machines(network):
......
......@@ -41,7 +41,7 @@ from synnefo.logic.rapi import GanetiApiError
from synnefo.management.common import Omit
from synnefo.management import common
from synnefo.settings import (CYCLADES_ASTAKOS_SERVICE_TOKEN as ASTAKOS_TOKEN,
ASTAKOS_URL)
ASTAKOS_BASE_URL)
# Fields to print from a gnt-instance info
......@@ -82,7 +82,7 @@ class Command(BaseCommand):
displayname = options['displayname']
ucache = UserCache(ASTAKOS_URL, ASTAKOS_TOKEN)
ucache = UserCache(ASTAKOS_BASE_URL, ASTAKOS_TOKEN)
try:
image = common.get_image(vm.imageid, vm.userid)['name']
......
......@@ -38,7 +38,7 @@ from synnefo.db.models import VirtualMachine
from synnefo.management.common import get_backend
from synnefo.api.util import get_image
from synnefo.settings import (CYCLADES_ASTAKOS_SERVICE_TOKEN as ASTAKOS_TOKEN,
ASTAKOS_URL)
ASTAKOS_BASE_URL)
from logging import getLogger
log = getLogger(__name__)
......@@ -74,7 +74,7 @@ class Command(ListCommand):
object_class = VirtualMachine
deleted_field = "deleted"
user_uuid_field = "userid"
astakos_url = ASTAKOS_URL
astakos_url = ASTAKOS_BASE_URL
astakos_token = ASTAKOS_TOKEN
def get_public_ip(vm):
......
......@@ -37,7 +37,7 @@ from synnefo.management.common import (format_vm_state, get_vm,
get_image)
from snf_django.lib.astakos import UserCache
from synnefo.settings import (CYCLADES_ASTAKOS_SERVICE_TOKEN as ASTAKOS_TOKEN,
ASTAKOS_URL)
ASTAKOS_BASE_URL)
from synnefo.webproject.management import utils
......@@ -61,11 +61,12 @@ class Command(SynnefoCommand):
image_name = "None"
image = '%s (%s)' % (imageid, image_name)
usercache = UserCache(ASTAKOS_BASE_URL, ASTAKOS_TOKEN)
kv = {
'id': server.id,
'name': server.name,
'owner_uuid': userid,
'owner_name': UserCache(ASTAKOS_URL, ASTAKOS_TOKEN).get_name(userid),
'owner_name': usercache.get_name(userid),
'created': utils.format_date(server.created),
'updated': utils.format_date(server.updated),
'image': image,
......
......@@ -37,6 +37,7 @@ from django.conf import settings
from django.http import HttpResponse
from django.template.loader import render_to_string
from django.utils import simplejson as json
from synnefo.cyclades_settings import COMPUTE_ROOT_URL
from snf_django.lib import api
......@@ -51,7 +52,7 @@ VERSION_1_1 = {
'links': [
{
'rel': 'self',
'href': settings.API_ROOT_URL,
'href': COMPUTE_ROOT_URL,
}
]
}
......
......@@ -7,11 +7,7 @@
DEBUG = False
# Top-level URL for deployment. Numerous other URLs depend on this.
APP_INSTALL_URL = "https://host:port"
# The API implementation needs to accept and return absolute references
# to its resources. Thus, it needs to know its public URL.
API_ROOT_URL = APP_INSTALL_URL + '/api'
CYCLADES_BASE_URL = "https://host:port/cyclades/"
# The API will return HTTP Bad Request if the ?changes-since
# parameter refers to a point in time more than POLL_LIMIT seconds ago.
......@@ -95,8 +91,8 @@ GANETI_DISK_TEMPLATES = ('blockdev', 'diskless', 'drbd', 'file', 'plain',
'rbd', 'sharedfile')
DEFAULT_GANETI_DISK_TEMPLATE = 'drbd'
# The URL of an astakos instance that will be used for user authentication
ASTAKOS_URL = 'https://accounts.synnefo.org/'
# Top-level URL of the astakos instance to be used for user management
ASTAKOS_BASE_URL = 'https://accounts.example.synnefo.org/'
# Tune the size of the Astakos http client connection pool
# This limit the number of concurrent requests to Astakos.
......
......@@ -4,7 +4,7 @@
###################
# API URL
COMPUTE_API_URL = '/api/v1.1'
#COMPUTE_API_URL = '/api/v1.1'
# base url for ui static files
# if not set, defaults to MEDIA_URL + 'snf-<latest_ui_version>/'
......@@ -24,7 +24,7 @@ IMAGE_ICONS = ["redhat", "ubuntu", "debian", "windows", "gentoo", "archlinux",
# How often should the UI request changes from the API
UI_UPDATE_INTERVAL = 5000
# Milieconds to increase the interval after
# Milieconds to increase the interval after
# UI_UPDATE_INTERVAL_INCREASE_AFTER_CALLS_COUNT calls
# of recurrent api requests
UI_UPDATE_INTERVAL_INCREASE = UI_UPDATE_INTERVAL / 4
......@@ -190,7 +190,7 @@ UI_GROUPED_PUBLIC_NETWORK_NAME = 'Internet'
###############
# Glance images API endpoint
UI_GLANCE_API_URL = '/plankton'
#UI_GLANCE_API_URL = '/plankton'
# Whether or not UI should display images from the Glance API
# set in UI_GLANCE_API_URL, if setting is set to False, ui will
......
......@@ -34,29 +34,52 @@
from django.conf.urls.defaults import *
from django.conf import settings
from snf_django.lib.api.proxy import proxy
from snf_django.lib.api.utils import prefix_pattern
from synnefo.cyclades_settings import (
BASE_URL, BASE_HOST, BASE_PATH,
COMPUTE_PREFIX, VMAPI_PREFIX, PLANKTON_PREFIX, HELPDESK_PREFIX,
ASTAKOS_BASE_URL, ASTAKOS_BASE_PATH, BASE_ASTAKOS_PROXY_PATH,
ASTAKOS_ACCOUNTS_PREFIX, ASTAKOS_VIEWS_PREFIX,
PROXY_USER_SERVICES)
from urlparse import urlparse
from functools import partial
astakos_proxy = partial(proxy, target=settings.ASTAKOS_URL)
urlpatterns = patterns('',
(r'^ui/', include('synnefo.ui.urls')),
astakos_proxy = partial(proxy, proxy_base=BASE_ASTAKOS_PROXY_PATH,
target_base=ASTAKOS_BASE_URL)
cyclades_patterns = patterns('',
(prefix_pattern('ui'), include('synnefo.ui.urls')),
url(r'^machines/console$', 'synnefo.ui.views.machines_console',
name='ui_machines_console'),
url(r'^machines/connect$', 'synnefo.ui.views.machines_connect',
name='ui_machines_connect'),
(r'^vmapi/', include('synnefo.vmapi.urls')),
(r'^api/', include('synnefo.api.urls')),
(r'^plankton/', include('synnefo.plankton.urls')),
(r'^helpdesk/', include('synnefo.helpdesk.urls')),
(prefix_pattern(VMAPI_PREFIX), include('synnefo.vmapi.urls')),
(prefix_pattern(PLANKTON_PREFIX), include('synnefo.plankton.urls')),
(prefix_pattern(HELPDESK_PREFIX), include('synnefo.helpdesk.urls')),
(prefix_pattern(COMPUTE_PREFIX), include('synnefo.api.urls')),
)
PROXY_USER_SERVICES = getattr(settings, 'CYCLADES_PROXY_USER_SERVICES', True)
urlpatterns = patterns(
'',
(prefix_pattern(BASE_PATH), include(cyclades_patterns)),
)
if PROXY_USER_SERVICES:
urlpatterns += patterns(
astakos_proxy = partial(proxy, proxy_base=BASE_ASTAKOS_PROXY_PATH,
target_base=ASTAKOS_BASE_URL)
proxy_patterns = patterns(
'',
(r'^login/?$', astakos_proxy),
(r'^feedback/?$', astakos_proxy),
(r'^user_catalogs/?$', astakos_proxy),
(r'^astakos/api/', astakos_proxy),
(prefix_pattern(ASTAKOS_VIEWS_PREFIX), astakos_proxy),
(prefix_pattern(ASTAKOS_ACCOUNTS_PREFIX), astakos_proxy),
)
urlpatterns += patterns(
'',
(prefix_pattern(BASE_ASTAKOS_PROXY_PATH), include(proxy_patterns)),
)
# Copyright 2013 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
# conditions are met:
#
# 1. Redistributions of source code must retain the above
# copyright notice, this list of conditions and the following
# disclaimer.
#
# 2. Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and
# documentation are those of the authors and should not be
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
from django.conf import settings
from synnefo.lib import join_urls, parse_base_url
BASE_URL = getattr(settings, 'CYCLADES_BASE_URL',
'https://compute.example.synnefo.org/compute/')
BASE_HOST, BASE_PATH = parse_base_url(BASE_URL)
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)
COMPUTE_PREFIX = getattr(settings, 'CYCLADES_COMPUTE_PREFIX', 'compute')
VMAPI_PREFIX = getattr(settings, 'CYCLADES_VMAPI_PREFIX', 'vmapi')
PLANKTON_PREFIX = getattr(settings, 'CYCLADES_PLANKTON_PREFIX', 'plankton')
HELPDESK_PREFIX = getattr(settings, 'CYCLADES_HELPDESK_PREFIX', 'helpdesk')
# The API implementation needs to accept and return absolute references
# to its resources. Thus, it needs to know its public URL.
COMPUTE_ROOT_URL = join_urls(BASE_URL, COMPUTE_PREFIX)
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('/')
ASTAKOS_ACCOUNTS_PREFIX = getattr(settings,
'ASTAKOS_ACCOUNTS_PREFIX', 'accounts').strip('/')
ASTAKOS_VIEWS_PREFIX = getattr(settings,
'ASTAKOS_VIEWS_PREFIX', 'im').strip('/')
ASTAKOS_KEYSTONE_PREFIX = getattr(settings,
'ASTAKOS_KEYSTONE_PREFIX',
'keystone').strip('/')
PROXY_USER_SERVICES = getattr(settings, 'CYCLADES_PROXY_USER_SERVICES', True)
......@@ -113,7 +113,7 @@ def helpdesk_user_required(func, permitted_groups=PERMITTED_GROUPS):
raise Http404
token = get_token_from_cookie(request, AUTH_COOKIE_NAME)
astakos.get_user(request, settings.ASTAKOS_URL,
astakos.get_user(request, settings.ASTAKOS_BASE_URL,
fallback_token=token, logger=logger)
if hasattr(request, 'user') and request.user:
groups = request.user.get('groups', [])
......@@ -200,8 +200,9 @@ def account(request, search_query):
account = None
search_query = vmid
astakos_client = astakosclient.AstakosClient(settings.ASTAKOS_URL, retry=2,
use_pool=True, logger=logger)
astakos_client = astakosclient.AstakosClient(settings.ASTAKOS_BASE_URL,
retry=2, use_pool=True,
logger=logger)
if is_uuid:
account = search_query
......
......@@ -43,7 +43,7 @@ from synnefo.db.models import (Backend, BackendNetwork,
from synnefo.logic.rapi import GanetiApiError
from snf_django.lib.astakos import UserCache
from synnefo.settings import (CYCLADES_ASTAKOS_SERVICE_TOKEN as ASTAKOS_TOKEN,
ASTAKOS_URL)
ASTAKOS_BASE_URL)
from util import pool_map_chunks
......@@ -66,7 +66,7 @@ class Command(BaseCommand):
net = get_network(args[0])
ucache = UserCache(ASTAKOS_URL, ASTAKOS_TOKEN)
ucache = UserCache(ASTAKOS_BASE_URL, ASTAKOS_TOKEN)
displayname = options['displayname']
......
......@@ -76,7 +76,7 @@ POOL_SIZE = 8
_pithos_backend_pool = \
PithosBackendPool(
POOL_SIZE,
astakos_url=settings.ASTAKOS_URL,
astakos_url=settings.ASTAKOS_BASE_URL,
service_token=settings.CYCLADES_ASTAKOS_SERVICE_TOKEN,
astakosclient_poolsize=settings.ASTAKOS_POOLSIZE,
db_connection=settings.BACKEND_DB_CONNECTION,
......
......@@ -34,7 +34,7 @@ from snf_django.lib.api import faults
from synnefo.db.models import QuotaHolderSerial, VirtualMachine, Network
from synnefo.settings import (CYCLADES_ASTAKOS_SERVICE_TOKEN as ASTAKOS_TOKEN,
ASTAKOS_URL)
ASTAKOS_BASE_URL)
from astakosclient import AstakosClient
from astakosclient.errors import AstakosClientException, QuotaLimit
from functools import wraps
......@@ -59,7 +59,7 @@ class Quotaholder(object):
def get(cls):
if cls._object is None:
cls._object = AstakosClient(
ASTAKOS_URL,
ASTAKOS_BASE_URL,
use_pool=True,
logger=log)
return cls._object
......
......@@ -77,7 +77,7 @@ class View(object):
Main entry point for a request-response process.
"""
def view(request, *args, **kwargs):
get_user(request, settings.ASTAKOS_URL)
get_user(request, settings.ASTAKOS_BASE_URL)
if not request.user_uniq:
return HttpResponse(status=401)
self = cls(*initargs, **initkwargs)
......
......@@ -69,7 +69,7 @@ def generate_key_pair(request):
Response to generate private/public RSA key pair
"""