Commit 81e0fa0f authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

apache-frontend: fix read of JSON file to not override current JSON

parent 9a6e913d
...@@ -77,7 +77,11 @@ sla-{{ parameter }} = {{ slapparameter_dict.pop( sla_key + parameter ) }} ...@@ -77,7 +77,11 @@ sla-{{ parameter }} = {{ slapparameter_dict.pop( sla_key + parameter ) }}
{% set slave_test_list = [] %} {% set slave_test_list = [] %}
{% set slave_configuration_path = slave_list_parameter.get('configuration-path') %} {% set slave_configuration_path = slave_list_parameter.get('configuration-path') %}
{% set slave_configuration_json = builtin.open(slave_configuration_path, 'w+').read() %} {% if os.path.exists(slave_configuration_path) %}
{% set slave_configuration_json = builtin.open(slave_configuration_path, 'r').read() %}
{% else %}
{% set slave_configuration_json = '' %}
{% endif %}
{% if slave_configuration_json == '' %} {% if slave_configuration_json == '' %}
{% set slave_configuration = {} %} {% set slave_configuration = {} %}
{% else %} {% else %}
...@@ -86,7 +90,7 @@ sla-{{ parameter }} = {{ slapparameter_dict.pop( sla_key + parameter ) }} ...@@ -86,7 +90,7 @@ sla-{{ parameter }} = {{ slapparameter_dict.pop( sla_key + parameter ) }}
{% for slave in slave_instance_list %} {% for slave in slave_instance_list %}
{% set slave_reference = slave.get('slave_reference') %} {% set slave_reference = slave.get('slave_reference') %}
## Update slave information if slave is new or have changed ## Update slave information if slave is new or have changed
{% if slave_configuration.has_key(slave_reference) %} {% if slave_reference in slave_configuration %}
{% if slave.get('timestamp') != slave_configuration.get(slave_reference).get('timestamp') %} {% 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__('timestamp', slave.get('timestamp')) %}
{% do slave_configuration.get(slave_reference).__setitem__('configuration', slave) %} {% do slave_configuration.get(slave_reference).__setitem__('configuration', slave) %}
......
...@@ -46,6 +46,7 @@ filename = instance-apache-replicate.cfg ...@@ -46,6 +46,7 @@ filename = instance-apache-replicate.cfg
extensions = jinja2.ext.do extensions = jinja2.ext.do
extra-context = extra-context =
import builtin __builtin__ import builtin __builtin__
import os os
key root_directory buildout:directory key root_directory buildout:directory
section slave_list_parameter slave-list-parameter 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}
......
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