Merge "Fix formula for newer contrail with systemd"
diff --git a/opencontrail/collector.sls b/opencontrail/collector.sls
index ca5333d..9a0dd28 100644
--- a/opencontrail/collector.sls
+++ b/opencontrail/collector.sls
@@ -65,7 +65,7 @@
   - require:
     - pkg: opencontrail_collector_packages
 
-{%- if collector.version >= 3.0 %}
+{%- if collector.version >= 3.0 and grains.get('init') != 'systemd' %}
 
 /etc/contrail/supervisord_analytics_files/contrail-analytics-nodemgr.ini:
   file.managed:
diff --git a/opencontrail/compute.sls b/opencontrail/compute.sls
index 9d5b7fd..c410cd1 100644
--- a/opencontrail/compute.sls
+++ b/opencontrail/compute.sls
@@ -69,6 +69,8 @@
 
 {%- if compute.version >= 3.0 %}
 
+{%- if compute.version <= 4.0 or grains.get('init') != 'systemd' %}
+
 /etc/contrail/supervisord_vrouter_files/contrail-vrouter-nodemgr.ini:
   file.managed:
   - source: salt://opencontrail/files/{{ compute.version }}/contrail-vrouter-nodemgr.ini
@@ -77,6 +79,8 @@
   - require_in:
     - service: opencontrail_compute_services
 
+{%- endif %}
+
 /etc/udev/rules.d/vhost-net.rules:
   file.managed:
   - contents: 'KERNEL=="vhost-net", GROUP="kvm", MODE="0660"'
@@ -101,6 +105,8 @@
   - require_in:
     - pkg: opencontrail_compute_packages
 
+{%- if compute.version <= 4.0 or grains.get('init') != 'systemd' %}
+
 /etc/contrail/supervisord_vrouter_files/contrail-vrouter-dpdk.ini:
   file.managed:
   - source: salt://opencontrail/files/{{ compute.version }}/contrail-vrouter-dpdk.ini
@@ -111,6 +117,8 @@
   - require_in:
     - service: opencontrail_compute_services
 
+{%- endif %}
+
 modules_dpdk:
   file.append:
   - name: /etc/modules
@@ -164,6 +172,8 @@
   - watch_in:
     - service: opencontrail_compute_services
 
+{%- if compute.version <= 4.0 or grains.get('init') != 'systemd' %}
+
 /etc/contrail/supervisord_vrouter_files/contrail-tor-agent-{{ agent.id }}.ini:
   file.managed:
   - source: salt://opencontrail/files/{{ compute.version }}/tor/contrail-tor-agent.ini
@@ -173,6 +183,8 @@
   - watch_in:
     - service: opencontrail_compute_services
 
+{%- endif %}
+
 {%- endfor %}
 {%- endif %}
 
diff --git a/opencontrail/config.sls b/opencontrail/config.sls
index dc035e5..84998e7 100644
--- a/opencontrail/config.sls
+++ b/opencontrail/config.sls
@@ -44,6 +44,8 @@
   - require:
     - pkg: opencontrail_config_packages
 
+{%- if grains.get('init') != 'systemd' %}
+
 /etc/contrail/supervisord_config_files/contrail-discovery.ini:
   file.managed:
   - source: salt://opencontrail/files/{{ config.version }}/config/contrail-discovery.ini
@@ -57,6 +59,8 @@
   - require:
     - pkg: opencontrail_config_packages
 
+{%- endif %}
+
 /etc/contrail/contrail-discovery.conf:
   file.managed:
   - source: salt://opencontrail/files/{{ config.version }}/contrail-discovery.conf
@@ -66,6 +70,8 @@
 
 {%- endif %}
 
+{%- if grains.get('init') != 'systemd' %}
+
 /etc/contrail/supervisord_config_files/contrail-api.ini:
   file.managed:
   - source: salt://opencontrail/files/{{ config.version }}/config/contrail-api.ini
@@ -79,6 +85,8 @@
   - require:
     - pkg: opencontrail_config_packages
 
+{%- endif %}
+
 /etc/contrail/contrail-api.conf:
   file.managed:
   - source: salt://opencontrail/files/{{ config.version }}/contrail-api.conf
@@ -143,7 +151,7 @@
   - require:
     - pkg: opencontrail_config_packages
 
-{%- if config.version >= 3.0 %}
+{%- if config.version >= 3.0 and grains.get('init') != 'systemd' %}
 
 /etc/contrail/supervisord_config_files/contrail-config-nodemgr.ini:
   file.managed:
diff --git a/opencontrail/control.sls b/opencontrail/control.sls
index e89e6f8..8de19e4 100644
--- a/opencontrail/control.sls
+++ b/opencontrail/control.sls
@@ -43,7 +43,7 @@
   - require:
     - pkg: opencontrail_control_packages
 
-{%- if control.version >= 3.0 %}
+{%- if control.version >= 3.0 and grains.get('init') != 'systemd' %}
 
 /etc/contrail/supervisord_control_files/contrail-control-nodemgr.ini:
   file.managed:
diff --git a/opencontrail/database.sls b/opencontrail/database.sls
index 036201a..7de47b5 100644
--- a/opencontrail/database.sls
+++ b/opencontrail/database.sls
@@ -113,6 +113,8 @@
     - service: opencontrail_database_services
     - service: opencontrail_zookeeper_service
 
+{%- if database.version <= 4.0 or grains.get('init') != 'systemd' %}
+
 /etc/contrail/supervisord_database_files/contrail-database-nodemgr.ini:
   file.managed:
   - source: salt://opencontrail/files/{{ database.version }}/database/contrail-database-nodemgr.ini
@@ -123,6 +125,7 @@
     - service: opencontrail_zookeeper_service
 
 {%- endif %}
+{%- endif %}
 
 {% if grains.os_family == "Debian" %}
 #Stop cassandra started by init script - replaced by contrail-database
@@ -162,7 +165,7 @@
 opencontrail_database_services:
   service.running:
   - enable: true
-{%- if common.vendor == "juniper" %}
+{%- if common.vendor == "juniper" or (database.version >= 4.0 and grains.get('init') == 'systemd') %}
   - name: contrail-database
 {%- else %}
   - name: supervisor-database
diff --git a/opencontrail/map.jinja b/opencontrail/map.jinja
index 8c95fe0..cbfae68 100644
--- a/opencontrail/map.jinja
+++ b/opencontrail/map.jinja
@@ -1,4 +1,5 @@
 {%- set vendor = salt['pillar.get']('opencontrail:common:vendor', 'opencontrail') %}
+{%- set version = salt['pillar.get']('opencontrail:common:version') %}
 
 {%- load_yaml as base_defaults %}
 {%- if vendor in ['opencontrail'] %}
@@ -19,26 +20,42 @@
         ['contrail-analytics', 'python-cassandra']
     redis_config: '/etc/redis/redis.conf'
     services:
+    {%- if grains.get('init') != 'systemd' %}
         ['supervisor-analytics', 'redis-server']
+    {%- else %}
+        ['contrail-collector', 'contrail-analytics-api', 'contrail-query-engine', 'contrail-alarm-gen', 'contrail-snmp-collector', 'contrail-topology', 'contrail-analytics-nodemgr', 'redis-server']
+    {%- endif %}
   RedHat:
     pkgs:
         ['contrail-analytics']
     redis_config: '/etc/redis.conf'
     services:
+    {%- if grains.get('init') != 'systemd' %}
         ['supervisor-analytics', 'redis']
+    {%- else %}
+        ['contrail-collector', 'contrail-analytics-api', 'contrail-query-engine', 'contrail-alarm-gen', 'contrail-snmp-collector', 'contrail-topology', 'contrail-analytics-nodemgr', 'redis']
+    {%- endif %}
 compute:
   Debian:
     pkgs:
         ['contrail-utils', 'iproute2', 'haproxy']
     services:
+    {%- if grains.get('init') != 'systemd' or version < 4.0 %}
         ['supervisor-vrouter']
+    {%- else %}
+        ['contrail-vrouter-agent', 'contrail-vrouter-nodemgr']
+    {%- endif %}
     dpdk:
         enabled: False
   RedHat:
     pkgs:
         ['contrail-openstack-vrouter', 'contrail-utils', 'haproxy', 'contrail-vrouter-source']
     services:
+    {%- if grains.get('init') != 'systemd' or version < 4.0 %}
         ['supervisor-vrouter']
+    {%- else %}
+        ['contrail-vrouter-agent', 'contrail-vrouter-nodemgr']
+    {%- endif %}
     dpdk:
         enabled: False
 config:
@@ -46,43 +63,70 @@
     pkgs:
         ['contrail-config-openstack', 'ifmap-server']
     services:
+    {%- if grains.get('init') != 'systemd' or version < 4.0 %}
         ['supervisor-config']
+    {%- else %}
+        ['contrail-api', 'contrail-schema', 'contrail-svc-monitor', 'contrail-device-manager', 'contrail-config-nodemgr']
+    {%- endif %}
   RedHat:
     pkgs:
         ['contrail-openstack-config']
     services:
+    {%- if grains.get('init') != 'systemd' %}
         ['supervisor-config']
+    {%- else %}
+        ['contrail-api', 'contrail-schema', 'contrail-svc-monitor', 'contrail-device-manager', 'contrail-config-nodemgr']
+    {%- endif %}
 control:
   Debian:
     pkgs:
         ['contrail-control', 'contrail-dns']
     services:
+    {%- if grains.get('init') != 'systemd' %}
         ['contrail-control', 'supervisor-control']
+    {%- else %}
+        ['contrail-control', 'contrail-named', 'contrail-dns', 'contrail-control-nodemgr']
+    {%- endif %}
   RedHat:
     pkgs:
          ['contrail-openstack-control']
     services:
-         ['contrail-control', 'supervisor-control']
+    {%- if grains.get('init') != 'systemd' or version < 4.0 %}
+        ['contrail-control', 'supervisor-control']
+    {%- else %}
+        ['contrail-control', 'contrail-named', 'contrail-dns', 'contrail-control-nodemgr']
+    {%- endif %}
 database:
   Debian:
     {%- if grains.get('oscodename') == 'trusty' %}
     pkgs:
          ['cassandra', 'zookeeper', 'supervisor', 'openjdk-7-jre-headless', 'contrail-database']
-    {%- else %}
+    {%- elif version < 4.0 %}
     pkgs:
          ['cassandra', 'zookeeper', 'supervisor', 'openjdk-8-jre-headless', 'contrail-database']
+    {%- else %}
+    pkgs:
+         ['cassandra', 'zookeeper', 'openjdk-8-jre-headless', 'contrail-database']
     {%- endif %}
     cassandra_config: '/etc/cassandra/'
     compaction_throughput_mb_per_sec: 16
     services:
+    {%- if grains.get('init') != 'systemd' or version < 4.0 %}
          ['supervisord-contrail-database', 'zookeeper']
+    {%- else %}
+         ['contrail-database', 'contrail-database-nodemgr', 'zookeeper']
+    {%- endif %}
   RedHat:
     pkgs:
          ['contrail-openstack-database', 'zookeeper', 'supervisor', 'java-1.7.0-openjdk-headless']
     cassandra_config: '/etc/cassandra/conf/'
     compaction_throughput_mb_per_sec: 16
     services:
+    {%- if grains.get('init') != 'systemd' or version < 4.0 %}
          ['supervisord-contrail-database', 'zookeeper']
+    {%- else %}
+         ['contrail-database', 'contrail-database-nodemgr', 'zookeeper']
+    {%- endif %}
 web:
   Debian:
     pkgs:
@@ -127,26 +171,42 @@
          ['contrail-analytics', 'python-cassandra-driver']
     redis_config: '/etc/redis/redis.conf'
     services:
+    {%- if grains.get('init') != 'systemd' or version < 4.0 %}
         ['supervisor-analytics', 'redis-server']
+    {%- else %}
+        ['contrail-collector', 'contrail-analytics-api', 'contrail-query-engine', 'contrail-alarm-gen', 'contrail-snmp-collector', 'contrail-topology', 'contrail-analytics-nodemgr', 'redis-server']
+    {%- endif %}
   RedHat:
     pkgs:
          ['contrail-analytics', 'python-cassandra-driver']
     redis_config: '/etc/redis.conf'
     services:
+    {%- if grains.get('init') != 'systemd' or version < 4.0 %}
         ['supervisor-analytics', 'redis']
+    {%- else %}
+        ['contrail-collector', 'contrail-analytics-api', 'contrail-query-engine', 'contrail-alarm-gen', 'contrail-snmp-collector', 'contrail-topology', 'contrail-analytics-nodemgr', 'redis']
+    {%- endif %}
 compute:
   Debian:
     pkgs:
          ['contrail-utils', 'iproute2', 'haproxy']
     services:
+    {%- if grains.get('init') != 'systemd' or version < 4.0 %}
         ['supervisor-vrouter']
+    {%- else %}
+        ['contrail-vrouter-agent', 'contrail-vrouter-nodemgr']
+    {%- endif %}
     dpdk:
         enabled: False
   RedHat:
     pkgs:
          ['contrail-openstack-vrouter', 'contrail-utils', 'haproxy', 'contrail-vrouter-source']
     services:
+    {%- if grains.get('init') != 'systemd' or version < 4.0 %}
         ['supervisor-vrouter']
+    {%- else %}
+        ['contrail-vrouter-agent', 'contrail-vrouter-nodemgr']
+    {%- endif %}
     dpdk:
         enabled: False
 config:
@@ -154,23 +214,39 @@
     pkgs:
          ['contrail-config-openstack', 'ifmap-server']
     services:
+    {%- if grains.get('init') != 'systemd' or version < 4.0 %}
         ['supervisor-config']
+    {%- else %}
+        ['contrail-api', 'contrail-schema', 'contrail-svc-monitor', 'contrail-device-manager', 'contrail-config-nodemgr']
+    {%- endif %}
   RedHat:
     pkgs:
          ['contrail-openstack-config']
     services:
+    {%- if grains.get('init') != 'systemd' or version < 4.0 %}
         ['supervisor-config']
+    {%- else %}
+        ['contrail-api', 'contrail-schema', 'contrail-svc-monitor', 'contrail-device-manager', 'contrail-config-nodemgr']
+    {%- endif %}
 control:
   Debian:
     pkgs:
          ['contrail-control', 'contrail-dns']
     services:
-         ['contrail-control', 'supervisor-control']
+    {%- if grains.get('init') != 'systemd' or version < 4.0 %}
+        ['contrail-control', 'supervisor-control']
+    {%- else %}
+        ['contrail-control', 'contrail-named', 'contrail-dns', 'contrail-control-nodemgr']
+    {%- endif %}
   RedHat:
     pkgs:
          ['contrail-openstack-control']
     services:
-         ['contrail-control', 'supervisor-control']
+    {%- if grains.get('init') != 'systemd' or version < 4.0 %}
+        ['contrail-control', 'supervisor-control']
+    {%- else %}
+        ['contrail-control', 'contrail-named', 'contrail-dns', 'contrail-control-nodemgr']
+    {%- endif %}
 database:
   Debian:
     {%- if grains.get('oscodename') == 'trusty' %}
@@ -183,14 +259,22 @@
     cassandra_config: '/etc/cassandra/'
     compaction_throughput_mb_per_sec: 16
     services:
+    {%- if grains.get('init') != 'systemd' or version < 4.0 %}
          ['supervisord-contrail-database', 'zookeeper']
+    {%- else %}
+         ['contrail-database', 'contrail-database-nodemgr', 'zookeeper']
+    {%- endif %}
   RedHat:
     pkgs:
          ['contrail-openstack-database', 'zookeeper', 'supervisor', 'java-1.7.0-openjdk-headless']
     cassandra_config: '/etc/cassandra/conf/'
     compaction_throughput_mb_per_sec: 16
     services:
+    {%- if grains.get('init') != 'systemd' or version < 4.0 %}
          ['supervisord-contrail-database', 'zookeeper']
+    {%- else %}
+         ['contrail-database', 'contrail-database-nodemgr', 'zookeeper']
+    {%- endif %}
 web:
   Debian:
     pkgs: