Merge "Refactor grain code to remove string handling using bash"
diff --git a/ceph/backup.sls b/ceph/backup.sls
index 7963e5c..5067012 100644
--- a/ceph/backup.sls
+++ b/ceph/backup.sls
@@ -54,6 +54,8 @@
 {%- endif %}
 {%- if backup.client.backup_times.minute is defined %}
   - minute: {{ backup.client.backup_times.minute }}
+{%- else %}
+  - minute: 0
 {%- endif %}
 {%- elif backup.client.hours_before_incr is defined %}
   - minute: 0
@@ -155,6 +157,8 @@
 {%- endif %}
 {%- if backup.server.backup_times.minute is defined %}
   - minute: {{ backup.server.backup_times.minute }}
+{%- else %}
+  - minute: 0
 {%- endif %}
 {%- elif backup.server.hours_before_incr is defined %}
   - minute: 0
diff --git a/ceph/files/backup/ceph-backup-client-runner.sh b/ceph/files/backup/ceph-backup-client-runner.sh
index 971f944..4b5b4f9 100644
--- a/ceph/files/backup/ceph-backup-client-runner.sh
+++ b/ceph/files/backup/ceph-backup-client-runner.sh
@@ -45,9 +45,13 @@
     rsync -arv --exclude=osd/{{ common.get('cluster_name', 'ceph') }}-*/current /var/lib/ceph $TMPDIR/{{ common.get('cluster_name', 'ceph') }}-$HOSTNAME/
 {%- elif mon.get('enabled', False) %}
     cp -a /etc/ceph/ $TMPDIR/
-    service ceph-mon@$HOSTNAME stop
-    cp -a /var/lib/ceph/ $TMPDIR/{{ common.get('cluster_name', 'ceph') }}-$HOSTNAME/
-    service ceph-mon@$HOSTNAME start
+    if service ceph-mon@$HOSTNAME status >/dev/null; then
+        service ceph-mon@$HOSTNAME stop
+        cp -a /var/lib/ceph/ $TMPDIR/{{ common.get('cluster_name', 'ceph') }}-$HOSTNAME/
+        service ceph-mon@$HOSTNAME start
+    else 
+        cp -a /var/lib/ceph/ $TMPDIR/{{ common.get('cluster_name', 'ceph') }}-$HOSTNAME/
+    fi
 {%- endif %}
 
     tar -cvzf $BACKUPDIR/$HOSTNAME/{{ common.get('cluster_name', 'ceph') }}-$HOSTNAME-$TIMESTAMP.tgz $TMPDIR
diff --git a/ceph/files/grafana_dashboards/hosts-overview_prometheus.json b/ceph/files/grafana_dashboards/hosts-overview_prometheus.json
index 93314e2..921f886 100644
--- a/ceph/files/grafana_dashboards/hosts-overview_prometheus.json
+++ b/ceph/files/grafana_dashboards/hosts-overview_prometheus.json
@@ -577,7 +577,7 @@
       "tableColumn": "Value",
       "targets": [
         {
-          "expr": "avg ( (irate(diskio_io_time{host=~\"($osd_hosts).*\"}[5m]) / 10 ) )",
+          "expr": "avg ( (irate(diskio_io_time{host=~\"($osd_hosts).*\"}[5m])) )",
           "format": "table",
           "instant": true,
           "intervalFactor": 1,
diff --git a/ceph/files/grafana_dashboards/osds-overview_prometheus.json b/ceph/files/grafana_dashboards/osds-overview_prometheus.json
index 49c1cb5..3337014 100644
--- a/ceph/files/grafana_dashboards/osds-overview_prometheus.json
+++ b/ceph/files/grafana_dashboards/osds-overview_prometheus.json
@@ -383,7 +383,7 @@
     },
     {
       "aliasColors": {},
-      "bars": false,
+      "bars": true,
       "dashLength": 10,
       "dashes": false,
       "datasource": null,
@@ -405,11 +405,11 @@
         "max": false,
         "min": false,
         "rightSide": false,
-        "show": true,
+        "show": false,
         "total": false,
         "values": false
       },
-      "lines": true,
+      "lines": false,
       "linewidth": 1,
       "links": [],
       "nullPointMode": "null",
@@ -427,7 +427,7 @@
         {
           "expr": "ceph_osd_numpg",
           "format": "time_series",
-          "instant": false,
+          "instant": true,
           "intervalFactor": 1,
           "legendFormat": "PGs per OSD",
           "refId": "A"
@@ -446,7 +446,7 @@
       "type": "graph",
       "xaxis": {
         "buckets": 20,
-        "mode": "time",
+        "mode": "histogram",
         "name": null,
         "show": true,
         "values": []
diff --git a/ceph/meta/logrotate.yml b/ceph/meta/logrotate.yml
new file mode 100644
index 0000000..8f2730c
--- /dev/null
+++ b/ceph/meta/logrotate.yml
@@ -0,0 +1,19 @@
+## Default: Daily rotation with 28 rotations kept
+{%- from "ceph/map.jinja" import common, mgr, mon, osd, radosgw with context %}
+
+{%- if mgr.get('enabled', False) or mon.get('enabled', False) or osd.get('enabled', False) or radosgw.get('enabled', False) %}
+job:
+  ceph-common:
+    - files:
+        - /var/log/ceph/*.log
+      options:
+        - {{ common.get('logrotate', {}).get('interval', 'daily') }}
+        - rotate: {{ common.get('logrotate', {}).get('rotate', 28) }}
+        - compress
+        - sharedscripts
+        - missingok
+        - notifempty
+        - su root ceph
+        - postrotate:
+              killall -q -1 ceph-mon ceph-mgr ceph-mds ceph-osd ceph-fuse radosgw || true
+{%- endif %}
diff --git a/ceph/osd/setup.sls b/ceph/osd/setup.sls
index 5b1a832..ab03da1 100644
--- a/ceph/osd/setup.sls
+++ b/ceph/osd/setup.sls
@@ -21,7 +21,7 @@
 
 {%- if disk.get('enabled', True) %}
 
-{% set dev = disk.dev %}
+{% set dev = '`readlink -f ' + disk.dev + '`' %}
 
 # for uniqueness
 {% set dev_device = dev + disk.get('data_partition_prefix', '') + disk.get('data_partition', 1)|string %}
diff --git a/ceph/setup/keyring.sls b/ceph/setup/keyring.sls
index f26c608..d51a109 100644
--- a/ceph/setup/keyring.sls
+++ b/ceph/setup/keyring.sls
@@ -2,18 +2,18 @@
 
 {% if not common.get('container_mode', False) %}
 
-{# run only if ceph cluster is present #}
-{%- for node_name, node_grains in salt['mine.get']('ceph:common:keyring:admin', 'grains.items', 'pillar').iteritems() %}
+  {# run only if ceph cluster is present #}
+  {%- for node_name, node_grains in salt['mine.get']('ceph:common:keyring:admin', 'grains.items', 'pillar').iteritems() %}
 
-{%- if node_grains.ceph is defined and node_grains.ceph.ceph_keyring is defined and node_grains.ceph.ceph_keyring.admin is defined and node_grains.ceph.get('fsid', '') == common.fsid %}
+    {%- if node_grains.ceph is defined and node_grains.ceph.ceph_keyring is defined and node_grains.ceph.ceph_keyring.admin is defined and node_grains.ceph.get('fsid', '') == common.fsid %}
 
-{%- if loop.index0 == 0 %}
+      {%- if loop.index0 == 0 %}
 
-{% for keyring_name, keyring in common.get('keyring', {}).iteritems() %}
+        {% for keyring_name, keyring in common.get('keyring', {}).iteritems() %}
 
-{%- if keyring.name is defined %}
+          {%- if keyring.name is defined %}
 
-{%- if keyring.name != 'admin' and keyring.key is defined and common.get("manage_keyring", False) %}
+            {%- if keyring.name != 'admin' and keyring.key is defined and common.get("manage_keyring", False) %}
 
 {{ common.prefix_dir }}/etc/ceph/{{ common.get('cluster_name', 'ceph') }}.client.{{ keyring.name }}.keyring:
   file.managed:
@@ -25,22 +25,43 @@
 
 ceph_import_keyring_{{ keyring.name }}:
   cmd.run:
-  - name: "ceph -c /etc/ceph/{{ common.get('cluster_name', 'ceph') }}.conf auth import -i {{ common.prefix_dir }}/etc/ceph/{{ common.get('cluster_name', 'ceph') }}.client.{{ keyring.name }}.keyring"
+  - name: ceph -c /etc/ceph/{{ common.get('cluster_name', 'ceph') }}.conf auth import -i {{ common.prefix_dir }}/etc/ceph/{{ common.get('cluster_name', 'ceph') }}.client.{{ keyring.name }}.keyring
   - onchanges:
     - file: {{ common.prefix_dir }}/etc/ceph/{{ common.get('cluster_name', 'ceph') }}.client.{{ keyring.name }}.keyring
 
-{%- elif keyring.name != 'admin' %}
+ceph_update_caps_for_{{ keyring.name }}:
+  cmd.run:
+  - name: ceph -c /etc/ceph/{{ common.get('cluster_name', 'ceph') }}.conf auth caps client.{{ keyring.name }} {%- for cap_name, cap in  keyring.caps.iteritems() %} {{ cap_name }} '{{ cap }}' {%- endfor %}
+  - onchanges:
+    - file: {{ common.prefix_dir }}/etc/ceph/{{ common.get('cluster_name', 'ceph') }}.client.{{ keyring.name }}.keyring
+
+            {%- elif keyring.name != 'admin' %}
 
 ceph_create_keyring_{{ keyring.name }}:
   cmd.run:
-  - name: "ceph -c /etc/ceph/{{ common.get('cluster_name', 'ceph') }}.conf auth get-or-create client.{{ keyring.name }} {%- for cap_name, cap in  keyring.caps.iteritems() %} {{ cap_name }} '{{ cap }}' {%- endfor %} > {{ common.prefix_dir }}/etc/ceph/{{ common.get('cluster_name', 'ceph') }}.client.{{ keyring.name }}.keyring"
+  - name: ceph -c /etc/ceph/{{ common.get('cluster_name', 'ceph') }}.conf auth get-or-create client.{{ keyring.name }} {%- for cap_name, cap in  keyring.caps.iteritems() %} {{ cap_name }} '{{ cap }}' {%- endfor %} > {{ common.prefix_dir }}/etc/ceph/{{ common.get('cluster_name', 'ceph') }}.client.{{ keyring.name }}.keyring
   - unless: "test -f {{ common.prefix_dir }}/etc/ceph/{{ common.get('cluster_name', 'ceph') }}.client.{{ keyring.name }}.keyring"
 
-{%- endif %}
+              {%- if salt['file.file_exists']('/usr/bin/ceph') %}
+                {%- set caps = salt['cmd.shell']('ceph auth list --format json') | load_json %}
+                {%- for client in caps['auth_dump'] %}
+                  {%- if client['entity'] == "client." + keyring.name %}
+                    {%- for cap_name, cap in  client.caps.iteritems() %}
+                      {%- if cap != keyring.caps[cap_name] %}
+ceph_update_caps_for_{{ keyring.name }}:
+  cmd.run:
+  - name: ceph -c /etc/ceph/{{ common.get('cluster_name', 'ceph') }}.conf auth caps client.{{ keyring.name }} {%- for cap_name, cap in  keyring.caps.iteritems() %} {{ cap_name }} '{{ cap }}' {%- endfor %}
+                      {%- endif %}
+                    {%- endfor %}
+                  {%- endif %}
+                {%- endfor %}
+              {%- endif %}
 
-{%- else %}
+            {%- endif %}
 
-{%- if keyring_name != 'admin' and keyring.key is defined and common.get("manage_keyring", False) %}
+          {%- else %}
+
+            {%- if keyring_name != 'admin' and keyring.key is defined and common.get("manage_keyring", False) %}
 
 {{ common.prefix_dir }}/etc/ceph/{{ common.get('cluster_name', 'ceph') }}.client.{{ keyring_name }}.keyring:
   file.managed:
@@ -56,23 +77,44 @@
   - onchanges:
     - file: {{ common.prefix_dir }}/etc/ceph/{{ common.get('cluster_name', 'ceph') }}.client.{{ keyring_name }}.keyring
 
-{%- elif keyring_name != 'admin' %}
+ceph_update_caps_for_{{ keyring_name }}:
+  cmd.run:
+  - name: ceph -c /etc/ceph/{{ common.get('cluster_name', 'ceph') }}.conf auth caps client.{{ keyring_name }} {%- for cap_name, cap in  keyring.caps.iteritems() %} {{ cap_name }} '{{ cap }}' {%- endfor %}
+  - onchanges:
+    - file: {{ common.prefix_dir }}/etc/ceph/{{ common.get('cluster_name', 'ceph') }}.client.{{ keyring_name }}.keyring
+
+            {%- elif keyring_name != 'admin' %}
 
 ceph_create_keyring_{{ keyring_name }}:
   cmd.run:
-  - name: "ceph -c /etc/ceph/{{ common.get('cluster_name', 'ceph') }}.conf auth get-or-create client.{{ keyring_name }} {%- for cap_name, cap in  keyring.caps.iteritems() %} {{ cap_name }} '{{ cap }}' {%- endfor %} > {{ common.prefix_dir }}/etc/ceph/{{ common.get('cluster_name', 'ceph') }}.client.{{ keyring_name }}.keyring"
+  - name: ceph -c /etc/ceph/{{ common.get('cluster_name', 'ceph') }}.conf auth get-or-create client.{{ keyring_name }} {%- for cap_name, cap in  keyring.caps.iteritems() %} {{ cap_name }} '{{ cap }}' {%- endfor %} > {{ common.prefix_dir }}/etc/ceph/{{ common.get('cluster_name', 'ceph') }}.client.{{ keyring_name }}.keyring
   - unless: "test -f {{ common.prefix_dir }}/etc/ceph/{{ common.get('cluster_name', 'ceph') }}.client.{{ keyring_name }}.keyring"
 
-{%- endif %}
+              {%- if salt['file.file_exists']('/usr/bin/ceph') %}
+                {%- set caps = salt['cmd.shell']('ceph auth list --format json') | load_json %}
+                {%- for client in caps['auth_dump'] %}
+                  {%- if client['entity'] == "client." + keyring_name %}
+                    {%- for cap_name, cap in  client.caps.iteritems() %}
+                      {%- if cap != keyring.caps[cap_name] %}
+ceph_update_caps_for_{{ keyring_name }}:
+  cmd.run:
+  - name: ceph -c /etc/ceph/{{ common.get('cluster_name', 'ceph') }}.conf auth caps client.{{ keyring_name }} {%- for cap_name, cap in  keyring.caps.iteritems() %} {{ cap_name }} '{{ cap }}' {%- endfor %}
+                      {%- endif %}
+                    {%- endfor %}
+                  {%- endif %}
+                {%- endfor %}
+              {%- endif %}
 
-{%- endif %}
+            {%- endif %}
 
-{% endfor %}
+          {%- endif %}
 
-{%- endif %}
+        {% endfor %}
 
-{%- endif %}
+      {%- endif %}
 
-{%- endfor %}
+    {%- endif %}
+
+  {%- endfor %}
 
 {%- endif %}