Commit 4e295a79 authored by Vincent Pelletier's avatar Vincent Pelletier

Rely on buildout serialisation.

No generic and readable serialisation mechanism protect us against the
appearance of the following strings:
- "${"
- " ;"
As those have a special meaning for buildout, they need to be escaped.
So we must use a buildout-specific serialisation format taking care of
those.
parent 7338e460
...@@ -25,14 +25,8 @@ ...@@ -25,14 +25,8 @@
# #
############################################################################## ##############################################################################
import slapos.slap import slapos.slap
import json
from ConfigParser import RawConfigParser from ConfigParser import RawConfigParser
cast_dict = {
'json': (True, json.dumps),
'str': (False, str),
}
class Recipe(object): class Recipe(object):
""" """
Retrieves slap partition parameters, and makes them available to other Retrieves slap partition parameters, and makes them available to other
...@@ -59,33 +53,22 @@ class Recipe(object): ...@@ -59,33 +53,22 @@ class Recipe(object):
Partition identifier. Partition identifier.
Example: Example:
${slap-connection:partition-id} ${slap-connection:partition-id}
unsafe (optional, 0 by default)
Enables formats which are unsafe when represented back into a buildout
text file. Set to 0 to explicitly disable unsafe formats, any other
integer value to enable them.
Output: Output:
slap-software-type.<format> slap-software-type
Current partition's software type, serialised in each available format. Current partition's software type.
<format> configuration
All partition parameters serialised in that format as values. Dict of all parameters.
Example: configuration.<key>
json = {"foo": "bar"} One key per partition parameter.
<format>.key Partition parameter whose name cannot be represented unambiguously in
One key per partition parameter, prefixed with serialisation format buildout syntax are ignored. They cannot be accessed from buildout syntax
followed by a dot. Example: anyway, and are available through "configuration" output key.
json.foo = "bar"
Supported serialisation formats:
json (safe)
JavaScript Object Notation
str (unsafe)
Python string representation.
""" """
# XXX: used to detect if a configuration key is a valid section key. This # XXX: used to detect if a configuration key is a valid section key. This
# assumes buildout uses ConfigParser - which is currently the case. # assumes buildout uses ConfigParser - which is currently the case.
OPTCRE = RawConfigParser.OPTCRE OPTCRE_match = RawConfigParser.OPTCRE.match
def __init__(self, buildout, name, options): def __init__(self, buildout, name, options):
slap = slapos.slap.slap() slap = slapos.slap.slap()
...@@ -100,21 +83,14 @@ class Recipe(object): ...@@ -100,21 +83,14 @@ class Recipe(object):
).getInstanceParameterDict() ).getInstanceParameterDict()
# XXX: those are not partition parameters, strictly speaking. # XXX: those are not partition parameters, strictly speaking.
# Discard them, and make them available as separate section keys. # Discard them, and make them available as separate section keys.
slap_software_type = parameter_dict.pop('slap_software_type') options['slap-software-type'] = parameter_dict.pop(
'slap_software_type')
del parameter_dict['ip_list'] del parameter_dict['ip_list']
allow_unsafe = bool(int(options.get('unsafe', '0'))) options['configuration'] = parameter_dict
match = self.OPTCRE.match match = self.OPTCRE_match
for name, (safe, cast) in cast_dict.iteritems(): for key, value in parameter_dict.iteritems():
if not safe and not allow_unsafe: if match(key) is not None:
continue continue
options['slap-software-type.' + name] = cast(slap_software_type) options['configuration.' + key] = value
options[name] = cast(parameter_dict)
for key, value in parameter_dict.iteritems():
if match(key) is not None:
# It should be OK to skip silently and unconditionally: such
# parameter cannot be accessed in a well-formed buildout
# config.
continue
options[name + '.' + key] = cast(value)
install = update = lambda self: [] install = update = lambda self: []
...@@ -21,8 +21,8 @@ extra-context = ...@@ -21,8 +21,8 @@ extra-context =
context = context =
key eggs_directory buildout:eggs-directory key eggs_directory buildout:eggs-directory
key develop_eggs_directory buildout:develop-eggs-directory key develop_eggs_directory buildout:develop-eggs-directory
jsonkey slap_software_type slap-parameters:slap-software-type.json key slap_software_type slap-parameters:slap-software-type
jsonkey slapparameter_dict slap-parameters:json key slapparameter_dict slap-parameters:configuration
${:extra-context} ${:extra-context}
[dynamic-template-tidstorage-parameters] [dynamic-template-tidstorage-parameters]
......
...@@ -149,7 +149,7 @@ configurator_bt5_list = erp5_core_proxy_field_legacy erp5_full_text_myisam_catal ...@@ -149,7 +149,7 @@ configurator_bt5_list = erp5_core_proxy_field_legacy erp5_full_text_myisam_catal
# XXX: "template.cfg" is hardcoded in instanciation recipe # XXX: "template.cfg" is hardcoded in instanciation recipe
filename = template.cfg filename = template.cfg
template = ${:_profile_base_location_}/instance.cfg.in template = ${:_profile_base_location_}/instance.cfg.in
md5sum = 0f3dcf0e156025d6b8f5f3efdd161282 md5sum = 19a9d18674848128bb358eceff728a1d
extra-context = extra-context =
key apache_location apache:location key apache_location apache:location
key aspell_location aspell:location key aspell_location aspell:location
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment