Closed sjmc7 closed 10 years ago
YAML already provides an aliasing mechanism using &
to create an anchor and *
as an alias for the value/blob of the matching anchor.
Would something like this work for you?
E.g.
# Config Scopes
# =============
# Note that these are defined in the config file *before* they are referenced
# in the server definitions below.
elasticsearch_logging: &elasticsearch_logging
cluster_name: logging
# Second set of elasticsearch config options
elasticsearch_documents:
cluster_name: documents
# Resource Definitions
# ====================
servers:
logging_servers:
config_scopes:
- elasticsearch: *elasticsearch_logging
monitoring:
config_scopes:
- elasticsearch: *elasticsearch_logging
which would get parsed into the following Python object:
{'elasticsearch_documents': {'cluster_name': 'documents'},
'elasticsearch_logging': {'cluster_name': 'logging'},
'servers': [{'config_scopes': [{'elasticsearch': {'cluster_name': 'logging'}}],
'name': 'logging_servers'},
{'config_scopes': [{'elasticsearch': {'cluster_name': 'logging'}}],
'name': 'monitoring'}]}
Yep, that'll do it - I subsequently read up on my yaml and did as you suggest.
It'd be useful to be able to rename a global config in the local scope. This would allow multiple server roles to share a local config_scope without copy and pasting; a mixture of reusing globally defined config sections with the flexibility of local config_scopes.
For example: