root / snf-common / synnefo / settings / default / services.py @ 32401481
History | View | Annotate | Download (6.3 kB)
1 |
# Copyright 2013 GRNET S.A. All rights reserved.
|
---|---|
2 |
#
|
3 |
# Redistribution and use in source and binary forms, with or
|
4 |
# without modification, are permitted provided that the following
|
5 |
# conditions are met:
|
6 |
#
|
7 |
# 1. Redistributions of source code must retain the above
|
8 |
# copyright notice, this list of conditions and the following
|
9 |
# disclaimer.
|
10 |
#
|
11 |
# 2. Redistributions in binary form must reproduce the above
|
12 |
# copyright notice, this list of conditions and the following
|
13 |
# disclaimer in the documentation and/or other materials
|
14 |
# provided with the distribution.
|
15 |
#
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 |
# POSSIBILITY OF SUCH DAMAGE.
|
28 |
#
|
29 |
# The views and conclusions contained in the software and
|
30 |
# documentation are those of the authors and should not be
|
31 |
# interpreted as representing official policies, either expressed
|
32 |
# or implied, of GRNET S.A.
|
33 |
|
34 |
from synnefo.util.entry_points import extend_dict_from_entry_point |
35 |
from synnefo.util.keypath import customize_from_items |
36 |
from synnefo.lib.services import fill_endpoints |
37 |
from synnefo.lib import parse_base_url |
38 |
|
39 |
from synnefo.settings.setup import Setting, Mandatory, Auto, Default |
40 |
|
41 |
CUSTOMIZE_SERVICES = Default( |
42 |
default_value=(), |
43 |
example_value={'cyclades_ui.prefix': 'view', |
44 |
'astakos_ui.prefix': 'view'}, |
45 |
export=0,
|
46 |
#dependencies=('SYNNEFO_SERVICES',) #uncomment this to test cycle
|
47 |
description=("A list of key-path and value pairs that would be applied to "
|
48 |
"the services registry after its automatic initialization."),
|
49 |
) |
50 |
|
51 |
services = {} |
52 |
extend_dict_from_entry_point(services, 'synnefo', 'services') |
53 |
|
54 |
from sys import modules |
55 |
module = modules[__name__] |
56 |
|
57 |
components = {} |
58 |
for service_name, service in services.items(): |
59 |
component_name = service['component']
|
60 |
if component_name not in components: |
61 |
components[component_name] = {} |
62 |
components[component_name][service_name] = service |
63 |
|
64 |
base_url_names = [] |
65 |
for component_name in components: |
66 |
name_upper = component_name.upper() |
67 |
|
68 |
base_url_name = name_upper + '_BASE_URL'
|
69 |
base_url_names.append(base_url_name) |
70 |
base_url_example_value = "https://{comp}.example.synnefo.org/{comp}/"
|
71 |
base_url_example_value = base_url_example_value.format(comp=component_name) |
72 |
base_url_description = ( |
73 |
"The HTTP URL prefix (scheme, host, and path) beneath which all "
|
74 |
"services for component {comp} reside.")
|
75 |
base_url_description = base_url_description.format(comp=component_name) |
76 |
base_url_setting = Mandatory( |
77 |
example_value=base_url_example_value, |
78 |
description=base_url_description, |
79 |
) |
80 |
setattr(module, base_url_name, base_url_setting)
|
81 |
|
82 |
def mk_auto_configure_base_host(base_url_name): |
83 |
def auto_configure_base_host(setting, value, deps): |
84 |
Setting.enforce_not_configurable(setting, value) |
85 |
base_url = deps[base_url_name] |
86 |
base_host, base_path = parse_base_url(base_url) |
87 |
return base_host
|
88 |
return auto_configure_base_host
|
89 |
|
90 |
base_host_name = name_upper + '_BASE_HOST'
|
91 |
base_host_description = "The host part of {base}. Cannot be configured."
|
92 |
base_host_description = base_host_description.format(base=base_url_name) |
93 |
base_host_setting = Auto( |
94 |
configure_callback=mk_auto_configure_base_host(base_url_name), |
95 |
export=0,
|
96 |
dependencies=(base_url_name,), |
97 |
description=base_host_description, |
98 |
) |
99 |
setattr(module, base_host_name, base_host_setting)
|
100 |
|
101 |
def mk_auto_configure_base_path(base_url_name): |
102 |
def auto_configure_base_path(setting, value, deps): |
103 |
Setting.enforce_not_configurable(setting, value) |
104 |
base_url = deps[base_url_name] |
105 |
base_host, base_path = parse_base_url(base_url) |
106 |
return base_path
|
107 |
return auto_configure_base_path
|
108 |
|
109 |
base_path_name = name_upper + '_BASE_PATH'
|
110 |
base_path_description = "The path part of {base}. Cannot be configured."
|
111 |
base_path_description = base_path_description.format(base=base_url_name) |
112 |
base_path_setting = Auto( |
113 |
configure_callback=mk_auto_configure_base_path(base_url_name), |
114 |
export=0,
|
115 |
dependencies=(base_url_name,), |
116 |
description=base_path_description, |
117 |
) |
118 |
setattr(module, base_path_name, base_path_setting)
|
119 |
|
120 |
|
121 |
SYNNEFO_COMPONENTS = Auto( |
122 |
configure_callback=Setting.enforce_not_configurable, |
123 |
export=0,
|
124 |
default_value=components, |
125 |
description=("A list with the names of all synnefo components currently "
|
126 |
"installed. Initialized from SYNNEFO_SERVICES. "
|
127 |
"It is dynamically generated and cannot be configured."),
|
128 |
dependencies=('SYNNEFO_SERVICES',),
|
129 |
) |
130 |
|
131 |
|
132 |
def auto_configure_services(setting, value, deps): |
133 |
Setting.enforce_not_configurable(setting, value) |
134 |
services = setting.default_value |
135 |
customization = deps['CUSTOMIZE_SERVICES']
|
136 |
if isinstance(customization, dict): |
137 |
customization = customization.items() |
138 |
customize_from_items(services, customization) |
139 |
for service_name, service in services.iteritems(): |
140 |
component_name = service['component']
|
141 |
base_url_name = component_name.upper() + '_BASE_URL'
|
142 |
base_url = deps[base_url_name] |
143 |
fill_endpoints(service, base_url) |
144 |
return services
|
145 |
|
146 |
|
147 |
SYNNEFO_SERVICES = Auto( |
148 |
configure_callback=auto_configure_services, |
149 |
export=0,
|
150 |
default_value=services, |
151 |
dependencies=('CUSTOMIZE_SERVICES',) + tuple(base_url_names), |
152 |
description=("An auto-generated registry of all services provided by all "
|
153 |
"currently installed Synnefo components. "
|
154 |
"It is dynamically generated and cannot be configured. "
|
155 |
"For service customization use CUSTOMIZE_SERVICES."),
|
156 |
) |