Merge pull request #22 from tcpcloud/syndic

Refactored salt-syndic features
diff --git a/README.rst b/README.rst
index c079750..68aab70 100644
--- a/README.rst
+++ b/README.rst
@@ -102,26 +102,38 @@
                 address: https://git.openstack.org/openstack/salt-formula-keystone
                 revision: refs/changes/56/123456/1
 
-Salt master syndicate master of masters
+Salt syndic: Master of masters
 
 .. code-block:: yaml
 
     salt:
       master:
         enabled: true
-        syndicate:
-          mode: master
+        order_masters: True
 
-Salt master syndicate (client) master
+Salt syndic: Lower master
 
 .. code-block:: yaml
 
     salt:
-      master:
+      syndic:
         enabled: true
-        syndicate:
-          mode: client
-          host: master-master
+        master:
+          host: master-of-master-host
+        timeout: 5
+
+Salt syndic: Lower master with multi-master of masters
+
+.. code-block:: yaml
+
+    salt:
+      syndic:
+        enabled: true
+        masters:
+        - host: master-of-master-host1
+        - host: master-of-master-host2
+        timeout: 5
+
 
 Salt master with custom handlers
 
diff --git a/salt/files/_syndic.conf b/salt/files/_syndic.conf
new file mode 100644
index 0000000..cd8d251
--- /dev/null
+++ b/salt/files/_syndic.conf
@@ -0,0 +1,11 @@
+{%- from "salt/map.jinja" import syndic with context %}
+
+{%- if syndic.masters is defined %}
+syndic_master:
+{%- for master in syndic.masters %}
+- {{ master.host }}
+{%- endfor %}
+{%- else %}
+syndic_master: {{ syndic.master.host }}
+{%- endif %}
+syndic_wait: {{ syndic.get('timeout', '5') }}
diff --git a/salt/files/master.conf b/salt/files/master.conf
index 481aeca..954454a 100644
--- a/salt/files/master.conf
+++ b/salt/files/master.conf
@@ -81,14 +81,6 @@
 
 {%- endfor %}
 
-{%- if master.syndic is defined %}
-
-{% if master.syndic.mode == 'master' %}
+{%- if master.order_masters %}
 order_masters: True
 {%- endif %}
-
-{% if master.syndic.mode == 'client' %}
-syndic_master: {{ master.syndic.host }}
-{%- endif %}
-
-{%- endif %}
diff --git a/salt/map.jinja b/salt/map.jinja
index ba8a816..fdb3a4a 100644
--- a/salt/map.jinja
+++ b/salt/map.jinja
@@ -47,6 +47,18 @@
 {%- endif %}
 
 
+{%- load_yaml as syndic_defaults %}
+Debian:
+  pkgs:
+  - salt-syndic
+RedHat:
+  pkgs:
+  - salt-syndic
+{%- endload %}
+
+{%- set syndic = salt['grains.filter_by'](syndic_defaults, merge=salt['pillar.get']('salt:syndic')) %}
+
+
 {%- load_yaml as minion_common %}
 default:
   graph_pkgs:
diff --git a/salt/syndic.sls b/salt/syndic.sls
new file mode 100644
index 0000000..68b8f27
--- /dev/null
+++ b/salt/syndic.sls
@@ -0,0 +1,19 @@
+{%- from "salt/map.jinja" import syndic with context %}
+{%- if syndic.enabled %}
+
+include:
+- salt.master.service
+
+salt_syndic_packages:
+  pkg.installed:
+  - names: {{ syndic.pkgs }}
+
+/etc/salt/master.d/_syndic.conf:
+  file.managed:
+  - source: salt://salt/files/_syndic.conf
+  - user: root
+  - template: jinja
+  - watch_in:
+    - service: salt_master_service
+
+{%- endif %}