Commit b3938bf6 authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

apache-frontend: Root: slave configuration is read and saved in instance

parent e2f33e64
...@@ -57,6 +57,52 @@ sla-{{ parameter }} = {{ slapparameter_dict.pop( sla_key + parameter ) }} ...@@ -57,6 +57,52 @@ sla-{{ parameter }} = {{ slapparameter_dict.pop( sla_key + parameter ) }}
{% endif -%} {% endif -%}
{% endfor -%} {% endfor -%}
# Prepare states
{% set slave_deploy = slave_list_parameter.get('deploy') %}
{% set slave_test = slave_list_parameter.get('test') %}
{% set slave_ignore = slave_list_parameter.get('ignore') %}
{% set slave_stop = slave_list_parameter.get('stop') %}
{% set default_slave_state = slapparameter_dict.pop('default-slave-state', slave_deploy ) %}
# Prepare slave list
{% set slave_deploy_list = [] %}
{% set slave_test_list = [] %}
{% set slave_configuration_path = slave_list_parameter.get('configuration-path') %}
{% set slave_configuration_json = builtin.open(slave_configuration_path, 'w+').read() %}
{% if slave_configuration_json == '' %}
{% set slave_configuration = {} %}
{% else %}
{% set slave_configuration = json_module.loads(slave_configuration_json) %}
{% endif %}
{% for slave in slave_instance_list %}
{% set slave_reference = slave.get('slave_reference') %}
## Update slave information if slave is new or have changed
{% if slave_configuration.has_key(slave_reference) %}
{% if slave.get('timestamp') != slave_configuration.get(slave_reference).get('timestamp') %}
{% do slave_configuration.get(slave_reference).__setitem__('timestamp', slave.get('timestamp')) %}
{% do slave_configuration.get(slave_reference).__setitem__('configuration', slave) %}
{% do slave_configuration.get(slave_reference).__setitem__('status', default_slave_state) %}
{% endif %}
{% else %}
{% do slave_configuration.__setitem__(slave_reference, {}) %}
{% do slave_configuration.get(slave_reference).__setitem__('timestamp', slave.get('timestamp')) %}
{% do slave_configuration.get(slave_reference).__setitem__('configuration', slave) %}
{% do slave_configuration.get(slave_reference).__setitem__('state', default_slave_state) %}
{% endif %}
## Put slave in the list according to its status
{% set slave_state = slave_configuration.get(slave_reference).get('state') %}
{% if slave_state == slave_deploy %}
{% do slave_configuration.get(slave_reference).__setitem__('deploy_configuration', slave_configuration.get(slave_reference).get('configuration')) %}
{% elif slave_state == slave_test %}
{% do slave_test_list.append(slave_configuration.get(slave_reference, 'configuration')) %}
{% endif %}
{% if slave_state != slave_stop and slave_configuration.get(slave_reference).has_key('deploy_configuration') %}
{% do slave_deploy_list.append(slave_configuration.get(slave_reference, 'configuration')) %}
{% endif %}
{% endfor %}
{% do json_module.dump(slave_configuration, builtin.open(slave_configuration_path, 'w')) %}
[replicate] [replicate]
<= slap-connection <= slap-connection
recipe = slapos.cookbook:requestoptional recipe = slapos.cookbook:requestoptional
...@@ -67,7 +113,7 @@ config = {{ ' '.join(slapparameter_dict.keys()) + ' ' + slave_list_name }} ...@@ -67,7 +113,7 @@ config = {{ ' '.join(slapparameter_dict.keys()) + ' ' + slave_list_name }}
{% for parameter, value in slapparameter_dict.iteritems() -%} {% for parameter, value in slapparameter_dict.iteritems() -%}
config-{{parameter}} = {{ value }} config-{{parameter}} = {{ value }}
{% endfor -%} {% endfor -%}
config-{{ slave_list_name }} = {{ json_module.dumps(slave_instance_list) }} config-{{ slave_list_name }} = {{ json_module.dumps(slave_deploy_list) }}
connection-monitor_url = connection-monitor_url =
[publish-information] [publish-information]
......
...@@ -44,6 +44,17 @@ template = ${template-apache-replicate:target} ...@@ -44,6 +44,17 @@ template = ${template-apache-replicate:target}
filename = instance-apache-replicate.cfg filename = instance-apache-replicate.cfg
extensions = jinja2.ext.do extensions = jinja2.ext.do
extra-context = extra-context =
import builtin __builtin__
import configparser_module ConfigParser
key root_directory buildout:directory
section slave_list_parameter slave-list-parameter
raw template_publish_slave_information ${template-replicate-publish-slave-information:target} raw template_publish_slave_information ${template-replicate-publish-slave-information:target}
# Must match the key id in [switch-softwaretype] which uses this section. # Must match the key id in [switch-softwaretype] which uses this section.
raw software_type RootSoftwareInstance-default-custom-personal-custom-group-replicate raw software_type RootSoftwareInstance-default-custom-personal-custom-group-replicate
[slave-list-parameter]
configuration-path = $${buildout:directory}/slave_configuration.json
deploy = DEPLOY
test = TEST
ignore = IGNORE
stop = STOP
\ No newline at end of file
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