From 2025705b40576fe69338ad9a159364b956cdea5f Mon Sep 17 00:00:00 2001
From: Tristan Cavelier <tristan.cavelier@nexedi.com>
Date: Mon, 4 Jul 2016 18:55:00 +0200
Subject: [PATCH] cloudooo: allow to configure the software

---
 software/cloudooo/instance-cloudoo.cfg.in | 26 +++++++++++++++++++----
 software/cloudooo/instance.cfg.in         |  1 +
 software/cloudooo/software.cfg            | 15 +++++++++++--
 3 files changed, 36 insertions(+), 6 deletions(-)

diff --git a/software/cloudooo/instance-cloudoo.cfg.in b/software/cloudooo/instance-cloudoo.cfg.in
index 5afa9bc10..d2157385e 100644
--- a/software/cloudooo/instance-cloudoo.cfg.in
+++ b/software/cloudooo/instance-cloudoo.cfg.in
@@ -1,8 +1,26 @@
 {% set ipv4 = (ipv4_set | list)[0] -%}
 {% if ipv6_set %}{% set ipv6 = (ipv6_set | list)[0] %}{% endif -%}
-{% set next_port = slapparameter_dict.get('tcpv4-port', 8000) | int -%}
-{% set backend_count = slapparameter_dict.get('backend-count', 1) | int -%}
-{% set ssl_parameter_dict = slapparameter_dict.get('ssl', {}) %}
+{% set instance_parameter_dict = parameter_dict['instance-parameter-dict'] -%}
+{% macro assert(x) %}{{ ("",)[not x] }}{% endmacro -%}
+
+{% set publish_url_name = instance_parameter_dict.get('publish-url-name') or 'url' -%}
+
+{% set next_port = instance_parameter_dict['port'] | int -%}
+{% if instance_parameter_dict.get('port-parameter-name') -%}
+{%   set next_port = slapparameter_dict.get(instance_parameter_dict['port-parameter-name'], next_port) | int -%}
+{% endif -%}
+{% do assert(next_port > 0) -%}
+
+{% set backend_count = instance_parameter_dict['backend-count'] | int -%}
+{% if instance_parameter_dict.get('backend-count-parameter-name') -%}
+{%   set backend_count = slapparameter_dict.get(instance_parameter_dict['backend-count-parameter-name'], backend_count) | int -%}
+{% endif -%}
+{% do assert(backend_count > 0) -%}
+
+{% set ssl_parameter_dict = instance_parameter_dict.get('ssl', {}) %}
+{% if instance_parameter_dict.get('ssl-dict-parameter-name') -%}
+{%   set ssl_parameter_dict = slapparameter_dict.get(instance_parameter_dict['ssl-dict-parameter-name'], ssl_parameter_dict) -%}
+{% endif -%}
 
 {% set apache_port = next_port -%}
 {% set haproxy_port = next_port + 1 -%}
@@ -13,7 +31,7 @@
 {%   do apache_ip_list.append('[' ~ ipv6 ~ ']') -%}
 {% endif -%}
 {% set apache_dict = {} -%}
-{% do apache_dict.__setitem__("cloudooo", (apache_port, "https", 'http://' ~ ipv4 ~ ':' ~ haproxy_port)) -%}
+{% do apache_dict.__setitem__(publish_url_name, (apache_port, "https", 'http://' ~ ipv4 ~ ':' ~ haproxy_port)) -%}
 
 {% set bin_directory = parameter_dict['buildout-bin-directory'] -%}
 {% set section_list = [] -%}
diff --git a/software/cloudooo/instance.cfg.in b/software/cloudooo/instance.cfg.in
index dd6d1b5ea..f72e638b4 100644
--- a/software/cloudooo/instance.cfg.in
+++ b/software/cloudooo/instance.cfg.in
@@ -42,6 +42,7 @@ glib = {{ glib_location }}
 glu = {{ glu_location }}
 haproxy = {{ haproxy_location }}
 imagemagick = {{ imagemagick_location }}
+instance-parameter-dict = {{ dumps(cloudooo_parameter_dict) }}
 libICE = {{ libICE_location }}
 libSM = {{ libSM_location }}
 libX11 = {{ libX11_location }}
diff --git a/software/cloudooo/software.cfg b/software/cloudooo/software.cfg
index f41f10f0b..77831be4a 100644
--- a/software/cloudooo/software.cfg
+++ b/software/cloudooo/software.cfg
@@ -1,3 +1,13 @@
+[cloudooo-software-parameter-dict]
+publish-url-name = cloudooo
+port-parameter-name = tcpv4-port
+port = 8000
+backend-count-parameter-name = backend-count
+backend-count = 1
+ssl-dict-parameter-name = ssl
+#ssl-dict =
+
+
 [buildout]
 extends =
   ../../stack/cloudooo.cfg
@@ -31,6 +41,7 @@ context =
     key bin_directory buildout:bin-directory
     key develop_eggs_directory buildout:develop-eggs-directory
     key eggs_directory buildout:eggs-directory
+    section cloudooo_parameter_dict cloudooo-software-parameter-dict
     ${:extra-context}
 
 [template]
@@ -38,7 +49,7 @@ context =
 # XXX: "template.cfg" is hardcoded in instanciation recipe
 filename = template.cfg
 template = ${:_profile_base_location_}/instance.cfg.in
-md5sum = 295c1f58e761732fcc430dd5cd6467b1
+md5sum = 918c97636fa56768ac01eb20cee6b7bc
 extra-context =
     key apache_location apache:location
     key buildout_bin_directory buildout:bin-directory
@@ -85,5 +96,5 @@ extra-context =
 [template-cloudooo]
 recipe = slapos.recipe.build:download
 url = ${:_profile_base_location_}/instance-cloudoo.cfg.in
-md5sum = afb0ec2b44baa40814075f917c02aa0d
+md5sum = 5e8fb5070c873f8405ba72573a68854f
 mode = 640
-- 
2.30.9