Revision 347b2ba1

b/docs/upgrade/upgrade-0.14.6.rst
6 6
1. Set default container quota policy to unlimited for the containers
7 7
   created prior to 0.14
8 8

  
9
2. Re-register services in astakos
10

  
9 11
1. Set default container quota policy to unlimited in old containers
10 12
====================================================================
11 13

  
......
25 27
   In order to massively change the quota of ``images`` container
26 28
   (in all the accounts)::
27 29
    $ pithos-manage-accounts set-container-quota images 0
30

  
31
2. Re-register services in astakos
32
==================================
33

  
34
Service definitions have changed; you will thus need to register their new
35
version. In astakos node, run::
36

  
37
    astakos-host$ snf-component-register
38

  
39
This will detect that the Synnefo components are already registered and ask
40
to update the registered services. Answer positively. You need to enter the
41
base URL for each component; give the same value as in the initial
42
registration.
b/snf-astakos-app/astakos/urls.py
36 36
from astakos.im.settings import (
37 37
    BASE_PATH, ACCOUNTS_PREFIX, VIEWS_PREFIX, KEYSTONE_PREFIX, WEBLOGIN_PREFIX)
38 38
from snf_django.lib.api.utils import prefix_pattern
39
from snf_django.utils.urls import extend_with_root_redirects
40
from astakos.im import settings
39
from snf_django.utils.urls import \
40
    extend_with_root_redirects, extend_endpoint_with_slash
41
from astakos.im.settings import astakos_services
42

  
43
urlpatterns = []
44

  
45
# Redirects should be first, otherwise they may get overridden by wildcards
46
extend_endpoint_with_slash(urlpatterns, astakos_services, 'astakos_ui')
47
extend_endpoint_with_slash(urlpatterns, astakos_services, 'astakos_weblogin')
41 48

  
42 49
astakos_patterns = patterns(
43 50
    '',
......
48 55
)
49 56

  
50 57

  
51
urlpatterns = patterns(
58
urlpatterns += patterns(
52 59
    '',
53 60
    (prefix_pattern(BASE_PATH), include(astakos_patterns)),
54 61
)
55 62

  
56 63
# set utility redirects
57
extend_with_root_redirects(urlpatterns, settings.astakos_services,
64
extend_with_root_redirects(urlpatterns, astakos_services,
58 65
                           'astakos_ui', BASE_PATH)
b/snf-common/synnefo/lib/services.py
47 47
            if publicURL is not None:
48 48
                continue
49 49

  
50
            publicURL = join_urls(base_url, prefix, version).rstrip('/') + '/'
50
            publicURL = join_urls(base_url, prefix, version).rstrip('/')
51 51
            set_path(endpoint, 'publicURL', publicURL)
52 52

  
53 53

  
......
84 84

  
85 85
def get_service_path(services, service_type, version=None):
86 86
    service_url = get_public_endpoint(services, service_type, version=version)
87
    return urlparse(service_url).path.rstrip('/') + '/'
87
    return urlparse(service_url).path.rstrip('/')
b/snf-cyclades-app/synnefo/api/test/versions.py
45 45
        path = get_service_path(cyclades_services,
46 46
                                'compute', version='v2.0')
47 47
        with astakos_user('user'):
48
            response = self.client.get(path)
48
            response = self.client.get(path.rstrip('/') + '/')
49 49
        self.assertEqual(response.status_code, 200)
50 50
        api_version = json.loads(response.content)['version']
51 51
        self.assertEqual(api_version['id'], 'v2.0')
b/snf-cyclades-app/synnefo/app_settings/urls.py
35 35
from django.conf import settings
36 36
from snf_django.lib.api.proxy import proxy
37 37
from snf_django.lib.api.utils import prefix_pattern
38
from snf_django.utils.urls import extend_with_root_redirects
38
from snf_django.utils.urls import \
39
    extend_with_root_redirects, extend_endpoint_with_slash
39 40
from snf_django.lib.api.urls import api_patterns
40 41
from synnefo.cyclades_settings import (
41 42
    BASE_URL, BASE_HOST, BASE_PATH, COMPUTE_PREFIX, VMAPI_PREFIX,
......
47 48
from functools import partial
48 49

  
49 50

  
51
urlpatterns = []
52

  
53
# Redirects should be first, otherwise they may get overridden by wildcards
54
extend_endpoint_with_slash(urlpatterns, cyclades_services, 'cyclades_ui')
55
extend_endpoint_with_slash(urlpatterns, cyclades_services, 'cyclades_helpdesk')
56
extend_endpoint_with_slash(urlpatterns, cyclades_services, 'admin')
57
extend_endpoint_with_slash(urlpatterns, cyclades_services, 'cyclades_userdata')
58

  
50 59
astakos_proxy = partial(proxy, proxy_base=BASE_ASTAKOS_PROXY_PATH,
51 60
                        target_base=ASTAKOS_BASE_URL)
52 61

  
......
63 72
    (prefix_pattern(HELPDESK_PREFIX), include('synnefo.helpdesk.urls')),
64 73
)
65 74

  
66
urlpatterns = patterns(
75
urlpatterns += patterns(
67 76
    '',
68 77
    (prefix_pattern(BASE_PATH), include(cyclades_patterns)),
69 78
)
b/snf-django-lib/snf_django/lib/api/utils.py
107 107
        raise faults.BadRequest("Unsupported Content-type: '%s'" % content_type)
108 108

  
109 109

  
110
def prefix_pattern(prefix):
110
def prefix_pattern(prefix, append_slash=True):
111 111
    """Return a reliable urls.py pattern from a prefix"""
112 112
    prefix = prefix.strip('/')
113
    if prefix:
113
    if prefix and append_slash:
114 114
        prefix += '/'
115 115
    pattern = '^' + prefix
116 116
    return pattern
b/snf-django-lib/snf_django/utils/urls.py
34 34

  
35 35
from django.conf.urls.defaults import url, patterns
36 36
from snf_django.lib.api.utils import prefix_pattern
37
from synnefo.lib.services import get_public_endpoint
37
from synnefo.lib.services import get_service_path
38 38
from synnefo.lib import join_urls
39 39

  
40 40

  
41
def extend_path_with_slash(patterns_obj, path):
42
    if not path.endswith('/'):
43
        pattern = prefix_pattern(path, append_slash=False) + '$'
44
        entry = url(pattern, 'redirect_to', {'url': path + '/'})
45
        patterns_obj += patterns('django.views.generic.simple', entry)
46

  
47

  
48
def extend_endpoint_with_slash(patterns_obj, filled_services, service_type,
49
                               version=None):
50
    path = get_service_path(filled_services, service_type, version)
51
    extend_path_with_slash(patterns_obj, path)
52

  
53

  
41 54
def extend_with_root_redirects(patterns_obj, filled_services, service_type,
42
                               base_path):
55
                               base_path, with_slash=True):
43 56
    """
44 57
    Append additional redirect url entries for `/` and `/<base_path>` paths.
45 58

  
......
50 63
    redirects to the chosen service url.
51 64

  
52 65
    """
53
    service_url = get_public_endpoint(filled_services, service_type)
66
    service_path = get_service_path(filled_services, service_type)
67
    if with_slash:
68
        service_path = service_path.rstrip('/') + '/'
69

  
54 70
    root_url_entry = None
55 71
    if base_path and base_path != '/':
56 72
        # redirect slash to /<base_path>/
......
61 77
    base_path_pattern = prefix_pattern(base_path) + '$'
62 78
    base_path_pattern_no_slash = prefix_pattern(base_path).rstrip('/') + '$'
63 79

  
64
    # redirect /<base_path> and /<base_path>/ to service_url public endpoint
80
    # redirect /<base_path> and /<base_path>/ to service_path public endpoint
65 81
    base_url_entry = url(base_path_pattern, 'redirect_to', {'url':
66
                                                            service_url})
82
                                                            service_path})
67 83
    base_url_entry_no_slash = url(base_path_pattern_no_slash,
68
                                  'redirect_to', {'url': service_url})
84
                                  'redirect_to', {'url': service_path})
69 85
    # urls order matter. Setting base_url_entry first allows us to avoid
70 86
    # redirect loops when base_path is empty or `/`
71 87
    patterns_obj += patterns('django.views.generic.simple',
b/snf-pithos-app/pithos/api/urls.py
37 37
from snf_django.lib.api.utils import prefix_pattern
38 38
from snf_django.lib.api.urls import api_patterns
39 39
from snf_django.lib.api import api_endpoint_not_found
40
from snf_django.utils.urls import extend_endpoint_with_slash
40 41
from pithos.api.settings import (
42
    pithos_services,
41 43
    BASE_PATH, ASTAKOS_BASE_URL, BASE_ASTAKOS_PROXY_PATH,
42 44
    ASTAKOS_ACCOUNTS_PREFIX, PROXY_USER_SERVICES,
43 45
    PITHOS_PREFIX, PUBLIC_PREFIX, UI_PREFIX)
44 46

  
45 47

  
48
urlpatterns = []
49

  
50
# Redirects should be first, otherwise they may get overridden by wildcards
51
extend_endpoint_with_slash(urlpatterns, pithos_services, "pithos_ui")
52
extend_endpoint_with_slash(urlpatterns, pithos_services, "pithos_public")
53

  
46 54
# TODO: This only works when in this order.
47 55
pithos_api_patterns = api_patterns(
48 56
    'pithos.api.functions',
......
69 77
    (r'{0}'.format(prefix_pattern(UI_PREFIX)),
70 78
        include(pithos_view_patterns)))
71 79

  
72
urlpatterns = patterns(
80
urlpatterns += patterns(
73 81
    '',
74 82
    (prefix_pattern(BASE_PATH), include(pithos_patterns)),
75 83
)

Also available in: Unified diff