Merge "Ceph setup keyring refactoring."
diff --git a/ceph/map.jinja b/ceph/map.jinja
index 1833052..ae0206b 100644
--- a/ceph/map.jinja
+++ b/ceph/map.jinja
@@ -23,6 +23,7 @@
 Debian:
   pkgs:
   - ceph-mgr
+  - jq
   services:
   - ceph-mgr
 {%- endload %}
diff --git a/ceph/mgr.sls b/ceph/mgr.sls
index ef07e80..f1b51b1 100644
--- a/ceph/mgr.sls
+++ b/ceph/mgr.sls
@@ -2,6 +2,15 @@
 
 {%- if mgr.get('enabled', False) %}
 
+{%- if common.version in ['nautilus'] %}
+enable_msgr2_protocol:
+  cmd.run:
+  - name: "ceph mon enable-msgr2"
+  - unless:
+    - pkg: mgr_packages
+
+{%- endif %}
+
 include:
 - ceph.common
 
@@ -44,6 +53,18 @@
     - onlyif: /bin/false
     {%- endif %}
 
+ceph_mgr_wait_functional:
+  cmd.run:
+    - name: test "$(ceph mgr dump --connect-timeout 30 | jq .available)" = "true"
+    - retry:
+        attempts: 5
+        interval: 10
+    {%- if grains.get('noservices') %}
+    - onlyif: /bin/false
+    {%- endif %}
+    - require:
+      - service: mgr_services
+
 {%- if common.version not in ['kraken', 'jewel'] %}
 
 {%- if mgr.get('dashboard', {}).get('enabled', False) %}
@@ -66,6 +87,7 @@
   cmd.wait:
   - name: "ceph -c /etc/ceph/{{ common.get('cluster_name', 'ceph') }}.conf mgr module disable dashboard;ceph -c /etc/ceph/{{ common.get('cluster_name', 'ceph') }}.conf mgr module enable dashboard --force"
   - watch:
+      - cmd: ceph_mgr_wait_functional
       - cmd: ceph_dashboard_address
       - cmd: ceph_dashboard_port
   - require:
@@ -76,6 +98,7 @@
   - name: "ceph -c /etc/ceph/{{ common.get('cluster_name', 'ceph') }}.conf mgr module enable dashboard"
   - unless: "ceph -c /etc/ceph/{{ common.get('cluster_name', 'ceph') }}.conf mgr module ls | python -c 'import sys, json; print json.load(sys.stdin)[\"enabled_modules\"] | grep dashboard"
   - require:
+    - cmd: ceph_mgr_wait_functional
     - file: common_config
 
 {%- else %}
@@ -85,6 +108,7 @@
   - name: "ceph -c /etc/ceph/{{ common.get('cluster_name', 'ceph') }}.conf mgr module disable dashboard"
   - unless: "ceph -c /etc/ceph/{{ common.get('cluster_name', 'ceph') }}.conf mgr module ls | python -c 'import sys, json; print json.load(sys.stdin)[\"disabled_modules\"] | grep dashboard"
   - require:
+    - cmd: ceph_mgr_wait_functional
     - file: common_config
     - file: /var/lib/ceph/mgr/{{ common.get('cluster_name', 'ceph') }}-{{ grains.host }}/
 
@@ -97,6 +121,7 @@
   - name: "ceph -c /etc/ceph/{{ common.get('cluster_name', 'ceph') }}.conf mgr module enable prometheus"
   - unless: "ceph -c /etc/ceph/{{ common.get('cluster_name', 'ceph') }}.conf mgr module ls | python -c 'import sys, json; print json.load(sys.stdin)[\"enabled_modules\"] | grep prometheus"
   - require:
+    - cmd: ceph_mgr_wait_functional
     - file: common_config
     - file: /var/lib/ceph/mgr/{{ common.get('cluster_name', 'ceph') }}-{{ grains.host }}/
 
diff --git a/ceph/mon.sls b/ceph/mon.sls
index ceaa458..b660cdf 100644
--- a/ceph/mon.sls
+++ b/ceph/mon.sls
@@ -54,6 +54,7 @@
     - pkg: mon_packages
     - file: common_config
 
+{%- if common.keyring.admin is not defined %}
 /var/lib/ceph/mon/{{ common.get('cluster_name', 'ceph') }}-{{ grains.host }}/keyring:
   file.managed:
   - source: salt://ceph/files/mon_keyring
@@ -62,16 +63,6 @@
   - unless: "test -f /var/lib/ceph/mon/{{ common.get('cluster_name', 'ceph') }}-{{ grains.host }}/done"
   - require:
     - pkg: mon_packages
-
-{%- if common.version in ['nautilus'] -%}
-enable_msgr2_protocol:
-  cmd.run:
-  - name: "ceph mon enable-msgr2"
-  - unless: "test -f /var/lib/ceph/mon/{{ common.get('cluster_name', 'ceph') }}-{{ grains.host }}/done"
-  - require:
-    - pkg: mon_packages
-    - file: common_config
-
 {%- endif %}
 
 /var/lib/ceph/mon/{{ common.get('cluster_name', 'ceph') }}-{{ grains.host }}/done:
diff --git a/ceph/osd/setup.sls b/ceph/osd/setup.sls
index 8c2bc56..252569f 100644
--- a/ceph/osd/setup.sls
+++ b/ceph/osd/setup.sls
@@ -1,9 +1,6 @@
 {%- from "ceph/map.jinja" import osd, common with context %}
 
 include:
-{%- if osd.backend.bluestore.create_partitions is defined and osd.backend.bluestore.create_partitions == true %}
-- ceph.osd.setup.partitioning
-{%- endif %}
 {%- if osd.lvm_enabled is defined and osd.lvm_enabled == true %}
 - ceph.osd.setup.lvm
 {%- else %}
diff --git a/ceph/osd/setup/lvm.sls b/ceph/osd/setup/lvm.sls
index 7634179..915caed 100644
--- a/ceph/osd/setup/lvm.sls
+++ b/ceph/osd/setup/lvm.sls
@@ -20,6 +20,14 @@
     - name: "ln -s {{"/etc/ceph/" + common.get('cluster_name', 'ceph') + ".client.bootstrap-osd.keyring"}} /var/lib/ceph/bootstrap-osd/ceph.keyring"
     - unless: "ls /var/lib/ceph/bootstrap-osd/ceph.keyring"
 
+{%- set legacy_disks = [] -%}
+
+{%- for disk_id, ceph_disk in salt['pillar.get']('ceph:osd:legacy_disks', {}).iteritems() %}
+
+{%- do legacy_disks.append(ceph_disk.get('dev')) %}
+
+{%- endfor -%}
+
 {%- for backend_name, backend in osd.backend.iteritems() %}
 
 {%- for disk in backend.disks %}
@@ -28,11 +36,14 @@
 
 {% set dev = disk.dev %}
 
-{% set db_partition = disk.get('db_partition', 1) %}
-{% set wal_partition = disk.get('wal_partition', 1) %}
+{% set db_partition = disk.get('db_partition') %}
+{% set wal_partition = disk.get('wal_partition') %}
+{% set block_partition_prefix = disk.get('block_partition_prefix', '') %}
 
 {%- endif %}
 
+{%- if dev not in legacy_disks -%}
+
 {%- set cmd = [] %}
 {%- do cmd.append('--cluster-fsid ' + common.fsid) %}
 {%- if disk.get('dmcrypt', False) %}
@@ -40,10 +51,10 @@
 {%- endif %}
 {%- do cmd.append('--bluestore') %}
 {%- if disk.block_db is defined %}
-  {%- do cmd.append('--block.db ' + disk.block_db + db_partition | string) %}
+  {%- do cmd.append('--block.db ' + disk.block_db + block_partition_prefix + db_partition | string) %}
 {%- endif %}
 {%- if disk.block_wal is defined %}
-  {%- do cmd.append('--block.wal ' + disk.block_wal + wal_partition | string ) %}
+  {%- do cmd.append('--block.wal ' + disk.block_wal + block_partition_prefix + wal_partition | string ) %}
 {%- endif %}
 {%- do cmd.append('--data ') %}
 {%- do cmd.append(dev) %}
@@ -59,9 +70,7 @@
   - onlyif: /bin/false
   {%- endif %}
 
-{% set db_partition = db_partition + 1 %}
-{% set wal_partition = wal_partition + 1 %}
-
+{%- endif %}
 
 {%- endfor %}
 
diff --git a/ceph/osd/setup/partitioning.sls b/ceph/osd/setup/partitioning.sls
deleted file mode 100644
index 16ced44..0000000
--- a/ceph/osd/setup/partitioning.sls
+++ /dev/null
@@ -1,80 +0,0 @@
-{%- from "ceph/map.jinja" import osd, common with context %}
-
-{%- set devs = [] %}
-{%- set dbs = [] %}
-{%- set wals = [] %}
-{%- for backend_name, backend in osd.backend.iteritems() %}
-{%- for disk in backend.disks %}
-{%- set dev = disk.dev %}
-
-{%- if disk.block_db is defined %}
-{%- set db = disk.block_db %}
-{%- do dbs.append(db) %}
-{%- endif %}
-{%- if disk.block_wal is defined %}
-{%- set wal = disk.block_wal %}
-{%- do wals.append(wal) %}
-{%- endif %}
-{%- do devs.append(dev) %}
-{%- endfor %}
-{%- endfor %}
-{%- set end_size = {} %}
-{%- set counter = {} %}
-
-{%- if dbs != [] %}
-{%- for db in dbs | unique %}
-{%- do end_size.update({db: 1048576}) %}
-{%- do counter.update({db: 1}) %}
-create_disk_label_{{ db }}:
-  module.run:
-  - name: partition.mklabel
-  - device: {{ db }}
-  - label_type: gpt
-  - unless: "fdisk -l {{ db }} | grep -i 'Disklabel type: gpt'"
-{%- endfor %}
-{%- for db in dbs %}
-create_partition_{{ db }}_{{ counter[db] }}:
-  module.run:
-  - name: partition.mkpart
-  - device: {{ db }}
-  - part_type: primary
-  - start: {{ end_size[db] }}B
-  - end: {{ end_size[db] + osd.bluestore_block_db_size }}B
-  - size: {{ osd.bluestore_block_db_size }}B
-  - unless: "blkid {{ db }}{{ counter[db] }} {{ db }}p{{ counter[db] }}"
-  - require:
-    - module: create_disk_label_{{ db }}
-
-{%- do counter.update({db: counter[db] + 1}) %}
-{%- do end_size.update({db: end_size[db] + osd.bluestore_block_db_size + 1048576}) %}
-{%- endfor %}
-{%- endif %}
-
-{%- if wals != [] %}
-{%- for wal in wals | unique %}
-{%- do end_size.update({wal: 1048576}) %}
-{%- do counter.update({wal: 1}) %}
-create_disk_label_{{ wal }}:
-  module.run:
-  - name: partition.mklabel
-  - device: {{ wal }}
-  - label_type: gpt
-  - unless: "fdisk -l {{ wal }} | grep -i 'Disklabel type: gpt'"
-{%- endfor %}
-{%- for wal in wals %}
-create_partition_{{ wal }}_{{ counter[wal] }}:
-  module.run:
-  - name: partition.mkpart
-  - device: {{ wal }}
-  - part_type: primary
-  - start: {{ end_size[wal] }}B
-  - end: {{ end_size[wal] + osd.bluestore_block_db_size }}B
-  - size: {{ osd.bluestore_block_wal_size }}B
-  - unless: "blkid {{ wal }}{{ counter[wal] }} {{ wal }}p{{ counter[wal] }}"
-  - require:
-    - module: create_disk_label_{{ wal }}
-
-{%- do counter.update({wal: counter[wal] + 1}) %}
-{%- do end_size.update({wal: end_size[wal] + osd.bluestore_block_wal_size + 1048576}) %}
-{%- endfor %}
-{% endif %}
diff --git a/metadata/service/common/cluster.yml b/metadata/service/common/cluster.yml
index 09ca6c2..7d98230 100644
--- a/metadata/service/common/cluster.yml
+++ b/metadata/service/common/cluster.yml
@@ -15,8 +15,8 @@
       fsid: ${_param:ceph_cluster_fsid}
       members:
         - name: ${_param:ceph_mon_node01_hostname}
-          host: ${_param:ceph_mon_node01_address}
+          host: ${_param:ceph_mon_node01_ceph_public_address}
         - name: ${_param:ceph_mon_node02_hostname}
-          host: ${_param:ceph_mon_node02_address}
+          host: ${_param:ceph_mon_node02_ceph_public_address}
         - name: ${_param:ceph_mon_node03_hostname}
-          host: ${_param:ceph_mon_node03_address}
+          host: ${_param:ceph_mon_node03_ceph_public_address}