From 507993c4ffed84f95434cdb4fa85c60ac9bbfbeb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=81ukasz=20Nowak?= <luke@nexedi.com>
Date: Mon, 2 May 2011 15:38:08 +0000
Subject: [PATCH] Use declarative way to install Zeo cluster.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@45775 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 .../erp5/src/slapos/recipe/erp5/__init__.py   | 65 ++++++++++++-------
 .../slapos/recipe/erp5/template/zeo.conf.in   |  4 +-
 2 files changed, 42 insertions(+), 27 deletions(-)

diff --git a/slapos/recipe/erp5/src/slapos/recipe/erp5/__init__.py b/slapos/recipe/erp5/src/slapos/recipe/erp5/__init__.py
index be6cf40a4a..37cda1c0ad 100644
--- a/slapos/recipe/erp5/src/slapos/recipe/erp5/__init__.py
+++ b/slapos/recipe/erp5/src/slapos/recipe/erp5/__init__.py
@@ -499,30 +499,47 @@ class Recipe(BaseSlapRecipe):
                              bt5_repository_list]))
     return []
 
-  def installZeo(self, ip, port, name, path):
-    zeo_event_log = os.path.join(self.log_directory, 'zeo.log')
-    zeo_pid = os.path.join(self.run_directory, 'zeo.pid')
-    self.registerLogRotation('zeo', [zeo_event_log],
-        self.killpidfromfile + ' ' + zeo_pid + ' SIGUSR2')
-    config = dict(
-      zeo_ip=ip,
-      zeo_port=port,
-      zeo_storagename=name,
-      zeo_event_log=zeo_event_log,
-      zeo_pid=zeo_pid,
-      zeo_zodb=path
-    )
-    zeo_conf_path = self.createConfigurationFile('zeo.conf',
-      self.substituteTemplate(self.getTemplateFilename('zeo.conf.in'), config))
-    self.path_list.append(zeo_conf_path)
-    wrapper = zc.buildout.easy_install.scripts([('zeo', __name__ + '.execute',
-      'execute')], self.ws, sys.executable, self.wrapper_directory, arguments=[
-        self.options['runzeo_binary'].strip(), '-C', zeo_conf_path]
-      )[0]
-    self.path_list.append(wrapper)
-    return dict(
-      zeo_address='%s:%s' % (config['zeo_ip'], config['zeo_port']),
-      zeo_storagename=config['zeo_storagename'])
+  def installZeo(self, ip):
+    zodb_dir = os.path.join(self.data_root_directory, 'zodb')
+    self._createDirectory(zodb_dir)
+    zeo_configuration_list = []
+    zeo_number = 0
+    for zeo_server in sorted(self._zeo_storage_dict.iterkeys()):
+      zeo_number += 1
+      zeo_event_log = os.path.join(self.log_directory, 'zeo-%s.log'% zeo_number)
+      zeo_pid = os.path.join(self.run_directory, 'zeo-%s.pid'% zeo_number)
+      self.registerLogRotation('zeo', [zeo_event_log],
+          self.killpidfromfile + ' ' + zeo_pid + ' SIGUSR2')
+      config = dict(
+        zeo_ip=ip,
+        zeo_port=self._zeo_storage_port_dict[zeo_server],
+        zeo_event_log=zeo_event_log,
+        zeo_pid=zeo_pid,
+      )
+      storage_number = 0
+      storage_definition_list = []
+      for storage_name in sorted(self._zeo_storage_dict[zeo_server]):
+        storage_number += 1
+        path = os.path.join(zodb_dir, 'zodb_%s.fs' % storage_number)
+        storage_definition_list.append("""<filestorage %(storage_name)s>
+  path %(path)s
+</filestorage>"""% dict(storage_name=storage_name, path=path))
+        zeo_configuration_list.append(dict(
+          ip=ip,
+          port=config['zeo_port'],
+          path=path,
+          storage_name=storage_name,
+          ))
+      config['zeo_filestorage_snippet'] = '\n'.join(storage_definition_list)
+      zeo_conf_path = self.createConfigurationFile('zeo-%s.conf' % zeo_number,
+        self.substituteTemplate(self.getTemplateFilename('zeo.conf.in'), config))
+      self.path_list.append(zeo_conf_path)
+      wrapper = zc.buildout.easy_install.scripts([('zeo', __name__ + '.execute',
+        'execute')], self.ws, sys.executable, self.wrapper_directory, arguments=[
+          self.options['runzeo_binary'].strip(), '-C', zeo_conf_path]
+        )[0]
+      self.path_list.append(wrapper)
+    return zeo_configuration_list
 
   def installZope(self, ip, port, name, zeo_address=None, zeo_storagename=None,
       zodb_root_path=None, with_timerservice=False):
diff --git a/slapos/recipe/erp5/src/slapos/recipe/erp5/template/zeo.conf.in b/slapos/recipe/erp5/src/slapos/recipe/erp5/template/zeo.conf.in
index 9a88787bd4..a37dd6cd78 100644
--- a/slapos/recipe/erp5/src/slapos/recipe/erp5/template/zeo.conf.in
+++ b/slapos/recipe/erp5/src/slapos/recipe/erp5/template/zeo.conf.in
@@ -6,9 +6,7 @@
   pid-filename %(zeo_pid)s
 </zeo>
 
-<filestorage %(zeo_storagename)s>
-  path %(zeo_zodb)s
-</filestorage>
+%(zeo_filestorage_snippet)s
 
 <eventlog>
   <logfile>
-- 
2.30.9