Initial commit
[ta/infra-ansible.git] / roles / partfs_rootdisk / templates / localstorage.j2
1 {%- set node_service_profiles = hosts[inventory_hostname]['service_profiles'] %}
2 {%- if (openstack is defined) and (openstack != '') -%}
3   {%- if (('management' in node_service_profiles) and (ceph_configured | default(False))) -%}
4     {%- set _ = node_service_profiles.append("cephcontroller") -%}
5   {%- endif -%}
6 {%- endif -%}
7 {%- if node_service_profiles|length > 1 %}
8
9   {%- set device_mapping = {} %}
10   {% if device_mapping.update(localstorage[node_service_profiles[0]]) %}{%- endif %}
11
12   {%- macro update_bigger_hash(hash) -%}
13     {%- set vol_names1 = device_mapping.keys()|list %}
14     {%- set vol_names2 = hash.keys()| list %}
15     {%- set vol_names =  vol_names1 + vol_names2| unique|list%}
16
17     {%- for vol_name in vol_names %}
18       {% if vol_name in device_mapping.keys() and vol_name not in hash.keys() %}
19         {% if device_mapping.update({ vol_name:  device_mapping[vol_name]}) %}{%- endif %}
20       {% elif vol_name not in device_mapping.keys() and vol_name in hash.keys() %}
21         {% if device_mapping.update({ vol_name: hash[vol_name]} ) %}{%- endif %}
22       {%- elif device_mapping[vol_name]["lvm_size"]|replace("%VG", "")|int > hash[vol_name]["lvm_size"]|replace("%VG", "")|int %}
23         {% if device_mapping.update({ vol_name: device_mapping[vol_name]}) %}{%- endif %}
24       {%- else %}
25         {% if device_mapping.update({ vol_name: hash[vol_name]} ) %}{%- endif %}
26       {%- endif %}
27     {%- endfor -%}
28   {%- endmacro -%}
29
30   {%- for index in range(1, node_service_profiles | length) -%}
31     {%-if update_bigger_hash(localstorage[node_service_profiles[index]]) -%}{%- endif %}
32   {%- endfor -%}
33
34 {%- else %}
35   {%- set device_mapping = localstorage[node_service_profiles[0]] %}
36 {%- endif %}
37
38 {% set allocated_vg = device_mapping.values() | map(attribute="lvm_size") | map("replace", "%VG", "") | map("int") | sum %}
39 {% set variable_found = device_mapping.values() | selectattr("lvm_size", "search", "variable") | list %}
40 {% if variable_found %}
41   {% set variable_size = (100-allocated_vg) | string + '%VG'%}
42   {% set _ = variable_found[0].update({'lvm_size': variable_size}) %}
43 {% endif %}
44
45 {
46 "device_mapping": [
47 {%- for vol_value in device_mapping.values() %}
48    {
49    {%- for vol_details_key,vol_details_value in vol_value.iteritems()  %}
50    "{{vol_details_key}}":"{{vol_details_value}}"{% if not loop.last %},{% endif %}
51    {%- endfor -%}
52    }{% if not loop.last %},{% endif %}
53 {%- endfor -%}
54 ]
55 }