Merge "Enable TLS for XMPP bus"
diff --git a/README.rst b/README.rst
index e285e13..827ddc1 100644
--- a/README.rst
+++ b/README.rst
@@ -921,7 +921,8 @@
     opencontrail:
       ...
       config:
-        api_workers: 3
+        api:
+          workers_count: 3
       ...
 
 Increase number of alarm-gen workers
@@ -1333,7 +1334,20 @@
           port: 8443
       ....
 
+Configure TCP_TW_RECYCLE in kernel
+------------------------------------
 
+Enable fast recycling of TIME-WAIT sockets. To enable set parameter to 1, which is
+default value in formula. To turn off this option set parameter to 0:
+
+.. code-block:: yaml
+
+    opencontrail:
+      ....
+      common
+        ....
+        tcp_tw_recycle: 0
+        ....
 
 Usage
 =====
diff --git a/opencontrail/common.sls b/opencontrail/common.sls
index 7628815..76d2ec9 100644
--- a/opencontrail/common.sls
+++ b/opencontrail/common.sls
@@ -48,7 +48,7 @@
 # TODO: Remove this for Ubuntu Bionic (4.15 is the default kernel)
 net.ipv4.tcp_tw_recycle:
   sysctl.present:
-    - value: 1
+    - value: {{ common.get('tcp_tw_recycle', 1) }}
 {% endif %}
 
 net.ipv4.tcp_tw_reuse:
@@ -99,12 +99,6 @@
   file.directory
 
 {%- if common.identity.engine == "keystone" %}
-/etc/contrail/service.token:
-  file.managed:
-  - contents: "{{ common.identity.token }}"
-  - require:
-    - file: /etc/contrail
-
 /etc/contrail/ctrl-details:
   file.managed:
   - source: salt://opencontrail/files/{{ common.version }}/ctrl-details
diff --git a/opencontrail/files/3.0/contrail-api.ini b/opencontrail/files/3.0/contrail-api.ini
index 4caaeb3..f6b6af2 100644
--- a/opencontrail/files/3.0/contrail-api.ini
+++ b/opencontrail/files/3.0/contrail-api.ini
@@ -1,11 +1,11 @@
 {%- from "opencontrail/map.jinja" import config with context -%}
 [program:contrail-api]
-{%- if config.get('api_workers', 1) < 2 %}
+{%- if config.get('api', {}).get('workers_count', 1) < 2 %}
 command=/usr/bin/contrail-api --conf_file /etc/contrail/contrail-api.conf --conf_file /etc/contrail/contrail-keystone-auth.conf --worker_id %(process_num)s
 numprocs=1
 {%- else %}
 command=/usr/bin/contrail-api --conf_file /etc/contrail/contrail-api.conf --conf_file /etc/contrail/contrail-keystone-auth.conf --worker_id %(process_num)s --listen_port 910%(process_num)s --admin_port 819%(process_num)s --http_server_port 828%(process_num)s --log_file /var/log/contrail/contrail-api-%(process_num)s.log
-numprocs={{ config.api_workers }}
+numprocs={{ config.api.workers_count }}
 {%- endif %}
 process_name=%(process_num)s
 redirect_stderr=true
diff --git a/opencontrail/files/4.0/contrail-api.ini b/opencontrail/files/4.0/contrail-api.ini
index 4caaeb3..f6b6af2 100644
--- a/opencontrail/files/4.0/contrail-api.ini
+++ b/opencontrail/files/4.0/contrail-api.ini
@@ -1,11 +1,11 @@
 {%- from "opencontrail/map.jinja" import config with context -%}
 [program:contrail-api]
-{%- if config.get('api_workers', 1) < 2 %}
+{%- if config.get('api', {}).get('workers_count', 1) < 2 %}
 command=/usr/bin/contrail-api --conf_file /etc/contrail/contrail-api.conf --conf_file /etc/contrail/contrail-keystone-auth.conf --worker_id %(process_num)s
 numprocs=1
 {%- else %}
 command=/usr/bin/contrail-api --conf_file /etc/contrail/contrail-api.conf --conf_file /etc/contrail/contrail-keystone-auth.conf --worker_id %(process_num)s --listen_port 910%(process_num)s --admin_port 819%(process_num)s --http_server_port 828%(process_num)s --log_file /var/log/contrail/contrail-api-%(process_num)s.log
-numprocs={{ config.api_workers }}
+numprocs={{ config.api.workers_count }}
 {%- endif %}
 process_name=%(process_num)s
 redirect_stderr=true
diff --git a/opencontrail/files/4.0/contrail-config-nodemgr.conf b/opencontrail/files/4.0/contrail-config-nodemgr.conf
index d9964ca..6653427 100644
--- a/opencontrail/files/4.0/contrail-config-nodemgr.conf
+++ b/opencontrail/files/4.0/contrail-config-nodemgr.conf
@@ -1,7 +1,7 @@
 {%- from "opencontrail/map.jinja" import config,database with context %}
 {%- if database is defined and config.version >= 4.0 %}
 [DEFAULTS]
-minimum_diskGB={{ database.get('minimum_disk', 80) }}
+minimum_diskGB={{ database.get('minimum_disk', 150) }}
 hostip={{ database.bind.get('host', '127.0.0.1') }}
 db_port={{ database.bind.get('port_configdb', database.bind.get('port', 9042)) }}
 {%- endif %}
diff --git a/opencontrail/files/4.0/database/cassandra-env.sh b/opencontrail/files/4.0/database/cassandra-env.sh
index 7f2145c..e3ad874 100644
--- a/opencontrail/files/4.0/database/cassandra-env.sh
+++ b/opencontrail/files/4.0/database/cassandra-env.sh
@@ -93,13 +93,14 @@
 jvmver=`echo "$java_ver_output" | grep '[openjdk|java] version' | awk -F'"' 'NR==1 {print $2}'`
 JVM_VERSION=${jvmver%_*}
 JVM_PATCH_VERSION=${jvmver#*_}
+COMPARE_CMD="dpkg --compare-versions"
 
-if [ "$JVM_VERSION" -lt "1.7" ] ; then
+if $COMPARE_CMD "$JVM_VERSION" lt "1.7"  ; then
     echo "Cassandra 2.0 and later require Java 7u25 or later."
     exit 1;
 fi
 
-if [ "$JVM_VERSION" -lt "1.8" ] && [ "$JVM_PATCH_VERSION" -lt "25" ] ; then
+if $COMPARE_CMD "$JVM_VERSION" lt "1.8"  && $COMPARE_CMD "$JVM_PATCH_VERSION" lt "25" ; then
     echo "Cassandra 2.0 and later require Java 7u25 or later."
     exit 1;
 fi
@@ -229,7 +230,7 @@
 JVM_OPTS="$JVM_OPTS -XX:CMSWaitDuration=10000"
 
 # note: bash evals '1.7.x' as > '1.7' so this is really a >= 1.7 jvm check
-if { [ "$JVM_VERSION" -gt "1.7" ] && [ "$JVM_VERSION" -lt "1.8.0" ] && [ "$JVM_PATCH_VERSION" -ge "60" ]; } || [ "$JVM_VERSION" -gt "1.8" ] ; then
+if { $COMPARE_CMD "$JVM_VERSION" gt "1.7" && $COMPARE_CMD "$JVM_VERSION" lt "1.8.0" && $COMPARE_CMD "$JVM_PATCH_VERSION" ge "60" ; } || $COMPARE_CMD "$JVM_VERSION" gt "1.8" ; then
     JVM_OPTS="$JVM_OPTS -XX:+CMSParallelInitialMarkEnabled -XX:+CMSEdenChunksRecordAlways -XX:CMSWaitDuration=10000"
 fi
 
diff --git a/opencontrail/files/grafana_dashboards/contrail_4_controller_prometheus.json b/opencontrail/files/grafana_dashboards/contrail_4_controller_prometheus.json
index 3411f28..72422ea 100644
--- a/opencontrail/files/grafana_dashboards/contrail_4_controller_prometheus.json
+++ b/opencontrail/files/grafana_dashboards/contrail_4_controller_prometheus.json
@@ -334,18 +334,18 @@
       "steppedLine": false,
       "targets": [
         {
-          "expr": "min(haproxy_scur{host=~\"$host\", proxy=~\"contrail.api\", sv=\"BACKEND\"}) by (host)",
+          "expr": "sum(label_replace(haproxy_scur{proxy=~\"contrail.api\", type=\"server\"}, \"sv_new\", \"$1\", \"sv\", \"([a-zA-Z0-9_]+)(?:-.*)?\")) by (sv_new)",
           "format": "time_series",
           "intervalFactor": 2,
-          "legendFormat": "contrail @{{ host }}",
+          "legendFormat": "contrail @{{ sv_new }}",
           "refId": "A",
           "step": 2
         },
         {
-          "expr": "min(haproxy_scur{host=~\"$host\",proxy=~\"contrail.analytics\", sv=\"BACKEND\"}) by (host)",
+          "expr": "sum(label_replace(haproxy_scur{proxy=~\"contrail.analytics\", type=\"server\"}, \"sv_new\", \"$1\", \"sv\", \"([a-zA-Z0-9_]+)(?:-.*)?\")) by (sv_new)",
           "format": "time_series",
           "intervalFactor": 2,
-          "legendFormat": "analytics @{{ host }}",
+          "legendFormat": "analytics @{{ sv_new }}",
           "refId": "B",
           "step": 2
         }
diff --git a/opencontrail/files/grafana_dashboards/contrail_controller_prometheus.json b/opencontrail/files/grafana_dashboards/contrail_controller_prometheus.json
index ab8fcae..ecbad3b 100644
--- a/opencontrail/files/grafana_dashboards/contrail_controller_prometheus.json
+++ b/opencontrail/files/grafana_dashboards/contrail_controller_prometheus.json
@@ -416,26 +416,26 @@
       "steppedLine": false,
       "targets": [
         {
-          "expr": "min(haproxy_scur{host=~\"$host\", proxy=~\"contrail.api\", sv=\"BACKEND\"}) by (host)",
+          "expr": "sum(label_replace(haproxy_scur{proxy=~\"contrail.api\", type=\"server\"}, \"sv_new\", \"$1\", \"sv\", \"([a-zA-Z0-9_]+)(?:-.*)?\")) by (sv_new)",
           "format": "time_series",
           "intervalFactor": 2,
-          "legendFormat": "contrail @{{ host }}",
+          "legendFormat": "contrail @{{ sv_new }}",
           "refId": "A",
           "step": 2
         },
         {
-          "expr": "min(haproxy_scur{host=~\"$host\",proxy=~\"contrail.analytics\", sv=\"BACKEND\"}) by (host)",
+          "expr": "sum(label_replace(haproxy_scur{proxy=~\"contrail.analytics\", type=\"server\"}, \"sv_new\", \"$1\", \"sv\", \"([a-zA-Z0-9_]+)(?:-.*)?\")) by (sv_new)",
           "format": "time_series",
           "intervalFactor": 2,
-          "legendFormat": "analytics @{{ host }}",
+          "legendFormat": "analytics @{{ sv_new }}",
           "refId": "B",
           "step": 2
         },
         {
-          "expr": "min(haproxy_scur{host=~\"$host\",proxy=~\"contrail.discovery\", sv=\"BACKEND\"}) by (host)",
+          "expr": "sum(label_replace(haproxy_scur{proxy=~\"contrail.discovery\", type=\"server\"}, \"sv_new\", \"$1\", \"sv\", \"([a-zA-Z0-9_]+)(?:-.*)?\")) by (sv_new)",
           "format": "time_series",
           "intervalFactor": 2,
-          "legendFormat": "discovery @{{ host }}",
+          "legendFormat": "discovery @{{ sv_new }}",
           "refId": "C"
         }
       ],