
* Move the logic out into ansible/templates * Let the ring_builder just build the ring based on a list of devices * Allows us to not have to specify the storage/repl ip as long as the bridge is specified Fixes #603
90 lines
5.0 KiB
Django/Jinja
90 lines
5.0 KiB
Django/Jinja
{### Check if this is an object storage policy #}
|
|
{% if item[1] is defined %}
|
|
{% set port = item[1]['port'] %}
|
|
{% set type = item[1]['type'] %}
|
|
{% set item = item[0]['policy'] %}
|
|
{### If the index is 0 then it needs to be object without index #}
|
|
{% if item.index == 0 %}
|
|
{% set builder_file = type %}
|
|
{% else %}
|
|
{% set builder_file = type + '-' + item.index|string %}
|
|
{% endif %}
|
|
{% set name = item.name %}
|
|
{### Otherwise this should be account or container rings #}
|
|
{### Make the port/type/item/builder_file/name vals uniform across rings #}
|
|
{% elif item.port is defined %}
|
|
{% set port = item.port %}
|
|
{% set type = item.type %}
|
|
{% set item = item.item %}
|
|
{% set builder_file = type %}
|
|
{% set name = type %}
|
|
{% endif %}
|
|
{### Lets get the min_part_hours, part_power and repl_number vals #}
|
|
{% set min_part_hours = item.min_part_hours | default(swift.min_part_hours | default(swift_default_min_part_hours)) %}
|
|
{% set part_power = item.part_power | default(swift.part_power) %}
|
|
{% set repl_number = item.repl_number | default(swift.repl_number | default(swift_default_replication_number)) %}
|
|
{### Create the builder dict #}
|
|
{% set builder = {} %}
|
|
{### This is a hacky way of updating the builder dict #}
|
|
{% set _update = builder.update({'min_part_hours':min_part_hours}) %}
|
|
{% set _update = builder.update({'repl_number':repl_number}) %}
|
|
{% set _update = builder.update({'part_power':part_power}) %}
|
|
{% set _update = builder.update({'builder_file':builder_file}) %}
|
|
{### Now we need to add the drives #}
|
|
{### Create an update the builder dict to have drives as an empty list #}
|
|
{% set _update = builder.update({'drives':[]}) %}
|
|
{### Lets get the default groups for drives and find the default storage_policy #}
|
|
{% set def_groups = [ 'account', 'container' ] %}
|
|
{% for policy in swift.storage_policies %}
|
|
{% if policy.policy.default is defined and policy.policy.default == True %}
|
|
{% set _update = def_groups.append(policy.policy.name) %}
|
|
{% endif %}
|
|
{% endfor %}
|
|
{### Loop through the swift_hosts #}
|
|
{% for host in groups['swift_hosts'] %}
|
|
{### Set the default storage_ip #}
|
|
{% set def_storage_ip = hostvars[host]['container_address'] %}
|
|
{% if swift.storage_network is defined %}
|
|
{% set storage_bridge = 'ansible_' + swift.storage_network|replace('-', '_') %}
|
|
{% set def_storage_ip = hostvars[host][storage_bridge]['ipv4']['address'] | default(hostvars[host]['container_address']) %}
|
|
{% endif %}
|
|
{### Set the default replication_ip #}
|
|
{% set def_repl_ip = def_storage_ip %}
|
|
{% if swift.replication_network is defined %}
|
|
{% set repl_bridge = 'ansible_' + swift.replication_network|replace('-', '_') %}
|
|
{% set def_repl_ip = hostvars[host][repl_bridge]['ipv4']['address'] | default(def_storage_ip) %}
|
|
{% endif %}
|
|
{### Get the drives use swift global as default #}
|
|
{% set drives = hostvars[host]['swift_vars']['drives'] | default(swift.drives | default([])) %}
|
|
{### Loop through the drives #}
|
|
{% for drive in drives %}
|
|
{### Check if groups is defined per host or drive #}
|
|
{% set groups = drive.groups | default(hostvars[host]['swift_vars']['groups'] | default(swift.groups | default(def_groups))) %}
|
|
{### Only build the device if it is part of the group we're building the ring for #}
|
|
{% if name in groups %}
|
|
{### Build an empty device which we'll update with the appropriate details #}
|
|
{% set device = {} %}
|
|
{% set weight = drive.weight | default(hostvars[host]['swift_vars']['weight'] | default(swift.weight | default(swift_default_drive_weight))) %}
|
|
{% set region = drive.region | default(hostvars[host]['swift_vars']['region'] | default(swift.region | default(1))) %}
|
|
{% set zone = drive.zone | default(hostvars[host]['swift_vars']['zone'] | default(swift.zone | default(swift_default_host_zone))) %}
|
|
{% set repl_ip = drive.repl_ip | default( hostvars[host]['swift_vars']['repl_ip'] | default(def_repl_ip)) %}
|
|
{% set repl_port = drive.repl_port | default((hostvars[host]['swift_vars']['repl_port']) | default(port)) %}
|
|
{% set storage_ip = drive.storage_ip | default(hostvars[host]['swift_vars']['storage_ip'] | default(def_storage_ip)) %}
|
|
{% set storage_port = drive.storage_port | default((hostvars[host]['swift_vars']['storage_port']) | default(port)) %}
|
|
{### Update the device with the appropriate values #}
|
|
{% set _update = device.update({'device':drive.name}) %}
|
|
{% set _update = device.update({'weight': weight}) %}
|
|
{% set _update = device.update({'region': region}) %}
|
|
{% set _update = device.update({'zone': zone}) %}
|
|
{% set _update = device.update({'repl_ip': repl_ip}) %}
|
|
{% set _update = device.update({'repl_port': repl_port|int}) %}
|
|
{% set _update = device.update({'ip': storage_ip}) %}
|
|
{% set _update = device.update({'port': storage_port|int}) %}
|
|
{### Append the device to the drives list of the builder dict #}
|
|
{% set _update = builder.drives.append(device) %}
|
|
{% endif %}
|
|
{% endfor %}
|
|
{% endfor %}
|
|
{### Output the builder file #}
|
|
{{ builder | to_nice_json }}
|