| {%- from "ceph/map.jinja" import common, setup with context -%} |
| # begin crush map |
| |
| {%- set types = {} -%} |
| {%- set hosts = {} -%} |
| {%- set osds = {} -%} |
| {%- set weights = {} -%} |
| {%- set ids = [0] -%} |
| |
| {%- for node_name, node_grains in salt['mine.get']('ceph:osd', 'grains.items', 'pillar').iteritems() -%} |
| {%- if node_grains.get('ceph', {}).get('fsid', '') == common.fsid -%} |
| {# load OSDs and compute weight#} |
| {%- set node_weight = [] -%} |
| {%- for osd_id, osd in node_grains.ceph.ceph_disk.iteritems() -%} |
| {%- do osd.update({'host': node_grains.nodename }) -%} |
| {%- do osds.update({osd_id: osd}) -%} |
| {%- do node_weight.append(osd.weight|float) -%} |
| {%- endfor -%} |
| |
| {%- do hosts.update({node_grains.nodename: {'weight': node_weight|sum, 'parent': node_grains.ceph_crush_parent }}) -%} |
| {%- if node_grains.ceph.crush_id|d(False) -%} |
| {%- do hosts[node_grains.nodename].update({'crush_id': node_grains.ceph.crush_id|int}) -%} |
| {%- do ids.append(node_grains.ceph.crush_id|int) -%} |
| {%- endif -%} |
| |
| |
| {%- endif -%} |
| {%- endfor -%} |
| |
| {%- set _crush = setup.crush -%} |
| {%- set _buckets = [] %} |
| |
| {%- for i in _crush.type %} |
| {%- for resource in _crush.get(i, {}) -%} |
| {%- if resource.crush_id|d(False) -%} |
| {%- do ids.append(resource.crush_id|int) -%} |
| {%- endif -%} |
| {%- endfor -%} |
| {%- endfor %} |
| |
| # tunables |
| {%- for k, v in _crush.get('tunables', {}).iteritems() %} |
| tunable {{ k }} {{ v }} |
| {%- endfor %} |
| |
| # types |
| {%- for i in _crush.get('type', []) %} |
| type {{ loop.index0 }} {{ i }} |
| {%- do types.update({loop.index: i}) %} |
| {%- endfor %} |
| |
| # devices |
| {%- set ceph_version = pillar.ceph.common.version -%} |
| {%- if ceph_version not in ['kraken', 'jewel'] -%} |
| {% for disk_id in osds|map('int')|sort %} |
| device {{ disk_id }} osd.{{ disk_id }}{%- if osds[disk_id|string].get('class') %} class {{ osds[disk_id|string].class }}{% endif %} |
| {%- endfor %} |
| {%- else %} |
| {% for disk_id in osds|map('int')|sort %} |
| device {{ disk_id }} osd.{{ disk_id }} |
| {%- endfor %} |
| {%- endif %} |
| |
| # host buckets |
| {%- for bucket in hosts %} |
| {%- set weight = [] %} |
| {%- set crush_id = hosts[bucket].crush_id | d(ids|min -1) %} |
| {%- do ids.append(crush_id|int) %} |
| host {{ bucket }} { |
| id {{ crush_id }} |
| alg straw2 |
| hash 0 |
| {%- for disk_id, disk in osds.iteritems() %} |
| {%- if disk.host == bucket %} |
| item osd.{{ disk_id }} weight {{ disk.weight }} |
| {%- do weight.append(disk.weight|float) %} |
| {%- endif %} |
| {%- endfor %} |
| {%- do weights.update({'host-' ~ bucket: weight|sum}) %} |
| # weight: {{ weights['host-' ~ bucket] }} |
| # parent: {{ hosts[bucket].parent }} |
| } |
| {%- endfor %} |
| |
| {%- for i in _crush.type|reverse %} |
| {%- set _typeid = loop.revindex -%} |
| {%- for resource in _crush.get(i, {}) -%} |
| {%- set weight = [] %} |
| {%- set crush_id = resource.crush_id | d(ids|min -1) %} |
| {%- do ids.append(crush_id|int) %} |
| {{ i }} {{ resource.name }} { |
| id {{ crush_id }} |
| alg {{ resource.get('alg', 'straw2') }} |
| hash {{ resource.get('hash', 0) }} |
| |
| # list children resources - {{ _crush.type[_typeid] }} |
| {%- if _crush.type[_typeid] == 'host' %} |
| {%- for r_name, r in hosts.iteritems() %} |
| {%- if r.parent == resource.name %} |
| item {{ r_name }} weight {{ r.weight }} |
| {%- do weight.append(r.weight) %} |
| {%- endif %} |
| {%- endfor %} |
| |
| {%- else %} |
| |
| {%- for r in _crush.get(_crush.type[_typeid], []) %} |
| {%- if r.parent == resource.name %} |
| {%- set rw = weights[_crush.type[_typeid] ~ '-' ~ r.name] %} |
| item {{ r.name }} weight {{ rw }} |
| {%- do weight.append(rw) %} |
| {%- endif %} |
| {%- endfor %} |
| |
| {%- endif %} |
| |
| {%- do weights.update({i ~ '-' ~ resource.name: weight|sum }) %} |
| # weight: {{ weight|sum }} |
| } |
| {%- endfor %} |
| {%- endfor %} |
| |
| # rules |
| {%- for rule_name, rule in _crush.get('rule', {}).iteritems() %} |
| rule {{ rule_name }} { |
| ruleset {{ rule.ruleset }} |
| type {{ rule.type }} |
| min_size {{ rule.min_size }} |
| max_size {{ rule.max_size }} |
| {%- for step in rule.steps %} |
| step {{ step }} |
| {%- endfor %} |
| } |
| {% endfor %} |
| # end crush map |
| |