Commit 52aa3a62 authored by Vincent Pelletier's avatar Vincent Pelletier Committed by Kazuhiko Shiozaki

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 8ce0b4e3
......@@ -25,14 +25,8 @@
#
##############################################################################
import slapos.slap
import json
from ConfigParser import RawConfigParser
cast_dict = {
'json': (True, json.dumps),
'str': (False, str),
}
class Recipe(object):
"""
Retrieves slap partition parameters, and makes them available to other
......@@ -59,33 +53,22 @@ class Recipe(object):
Partition identifier.
Example:
${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:
slap-software-type.<format>
Current partition's software type, serialised in each available format.
<format>
All partition parameters serialised in that format as values.
Example:
json = {"foo": "bar"}
<format>.key
One key per partition parameter, prefixed with serialisation format
followed by a dot. Example:
json.foo = "bar"
Supported serialisation formats:
json (safe)
JavaScript Object Notation
str (unsafe)
Python string representation.
slap-software-type
Current partition's software type.
configuration
Dict of all parameters.
configuration.<key>
One key per partition parameter.
Partition parameter whose name cannot be represented unambiguously in
buildout syntax are ignored. They cannot be accessed from buildout syntax
anyway, and are available through "configuration" output key.
"""
# XXX: used to detect if a configuration key is a valid section key. This
# assumes buildout uses ConfigParser - which is currently the case.
OPTCRE = RawConfigParser.OPTCRE
OPTCRE_match = RawConfigParser.OPTCRE.match
def __init__(self, buildout, name, options):
slap = slapos.slap.slap()
......@@ -100,21 +83,14 @@ class Recipe(object):
).getInstanceParameterDict()
# XXX: those are not partition parameters, strictly speaking.
# 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']
allow_unsafe = bool(int(options.get('unsafe', '0')))
match = self.OPTCRE.match
for name, (safe, cast) in cast_dict.iteritems():
if not safe and not allow_unsafe:
continue
options['slap-software-type.' + name] = cast(slap_software_type)
options[name] = cast(parameter_dict)
options['configuration'] = parameter_dict
match = self.OPTCRE_match
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)
options['configuration.' + key] = value
install = update = lambda self: []
......@@ -21,8 +21,8 @@ extra-context =
context =
key eggs_directory buildout:eggs-directory
key develop_eggs_directory buildout:develop-eggs-directory
jsonkey slap_software_type slap-parameters:slap-software-type.json
jsonkey slapparameter_dict slap-parameters:json
key slap_software_type slap-parameters:slap-software-type
key slapparameter_dict slap-parameters:configuration
${:extra-context}
[dynamic-template-tidstorage-parameters]
......
......@@ -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
filename = template.cfg
template = ${:_profile_base_location_}/instance.cfg.in
md5sum = 0f3dcf0e156025d6b8f5f3efdd161282
md5sum = 19a9d18674848128bb358eceff728a1d
extra-context =
key apache_location apache: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