Sergii Golovatiuk | 50f9189 | 2017-08-04 18:11:06 +0200 | [diff] [blame^] | 1 | {% set SALT_MODELS_BRANCH = os_env('SALT_MODELS_BRANCH','master') %} |
| 2 | {% set SALT_MODELS_COMMIT = os_env('SALT_MODELS_COMMIT','master') %} |
| 3 | {# Reference to a patch that should be applied to the model if required, for example: export SALT_MODELS_REF_CHANGE=refs/changes/19/7219/12 #} |
| 4 | {% set SALT_MODELS_REF_CHANGE = os_env('SALT_MODELS_REF_CHANGE', '') %} |
| 5 | {# Pin to a specified commit in salt-models/reclass-system #} |
| 6 | {% set SALT_MODELS_SYSTEM_COMMIT = os_env('SALT_MODELS_SYSTEM_COMMIT','') %} |
| 7 | |
| 8 | {# Address pools for reclass cluster model are taken in the following order: |
| 9 | # 1. environment variables, |
| 10 | # 2. config.underlay.address_pools based on fuel-devops address pools |
| 11 | # (see generated '.ini' file after underlay is created), |
| 12 | # 3. defaults #} |
| 13 | {% set address_pools = config.underlay.address_pools %} |
| 14 | {% set IPV4_NET_ADMIN = os_env('IPV4_NET_ADMIN', address_pools.get('admin-pool01', '192.168.10.0/24')) %} |
| 15 | {% set IPV4_NET_CONTROL = os_env('IPV4_NET_CONTROL', address_pools.get('private-pool01', '172.16.10.0/24')) %} |
| 16 | {% set IPV4_NET_TENANT = os_env('IPV4_NET_TENANT', address_pools.get('tenant-pool01', '10.1.0.0/24')) %} |
| 17 | {% set IPV4_NET_EXTERNAL = os_env('IPV4_NET_EXTERNAL', address_pools.get('external-pool01', '10.16.0.0/24')) %} |
| 18 | {% set IPV4_NET_ADMIN_PREFIX = '.'.join(IPV4_NET_ADMIN.split('.')[0:3]) %} |
| 19 | {% set IPV4_NET_CONTROL_PREFIX = '.'.join(IPV4_NET_CONTROL.split('.')[0:3]) %} |
| 20 | {% set IPV4_NET_TENANT_PREFIX = '.'.join(IPV4_NET_TENANT.split('.')[0:3]) %} |
| 21 | {% set IPV4_NET_EXTERNAL_PREFIX = '.'.join(IPV4_NET_EXTERNAL.split('.')[0:3]) %} |
| 22 | |
| 23 | {# - description: Clone reclass models with submodules #} |
| 24 | {%- macro MACRO_CLONE_RECLASS_MODELS() %} |
| 25 | ssh-keyscan -H github.com >> ~/.ssh/known_hosts; |
| 26 | git clone -b {{ SALT_MODELS_BRANCH }} --recurse-submodules {{ SALT_MODELS_REPOSITORY }} /srv/salt/reclass; |
| 27 | pushd /srv/salt/reclass && \ |
| 28 | {%- if SALT_MODELS_REF_CHANGE != '' %} |
| 29 | {%- for item in SALT_MODELS_REF_CHANGE.split(" ") %} |
| 30 | git fetch {{ SALT_MODELS_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD && \ |
| 31 | {%- endfor %} |
| 32 | {%- elif SALT_MODELS_COMMIT != 'master' %} |
| 33 | git checkout {{ SALT_MODELS_COMMIT }} && \ |
| 34 | {%- endif %} |
| 35 | {%- if SALT_MODELS_SYSTEM_COMMIT != '' %} |
| 36 | pushd classes/system/ && \ |
| 37 | git checkout {{ SALT_MODELS_SYSTEM_COMMIT }} && \ |
| 38 | popd && \ |
| 39 | {%- else %} |
| 40 | git submodule update --init --recursive && \ |
| 41 | {%- endif %} |
| 42 | popd; |
| 43 | mkdir -p /srv/salt/reclass/classes/service; |
| 44 | |
| 45 | # Replace firstly to an intermediate value to avoid intersection between |
| 46 | # already replaced and replacing networks. |
| 47 | # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice: |
| 48 | # 192.168.10 -> 10.16.0 (generated network for admin) |
| 49 | # 10.16.0 -> <external network> |
| 50 | # So let's replace constant networks to the keywords, and then keywords to the desired networks. |
| 51 | find /srv/salt/reclass/ -type f -exec sed -i 's/192\.168\.10\./==IPV4_NET_ADMIN_PREFIX==/g' {} + |
| 52 | find /srv/salt/reclass/ -type f -exec sed -i 's/172\.16\.10\./==IPV4_NET_CONTROL_PREFIX==/g' {} + |
| 53 | find /srv/salt/reclass/ -type f -exec sed -i 's/10\.1\.0\./==IPV4_NET_TENANT_PREFIX==/g' {} + |
| 54 | find /srv/salt/reclass/ -type f -exec sed -i 's/10\.16\.0\./==IPV4_NET_EXTERNAL_PREFIX==/g' {} + |
| 55 | |
| 56 | find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}./g' {} + |
| 57 | find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}./g' {} + |
| 58 | find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}./g' {} + |
| 59 | find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_EXTERNAL_PREFIX==/{{ IPV4_NET_EXTERNAL_PREFIX }}./g' {} + |
| 60 | |
| 61 | find /srv/salt/reclass/ -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} + |
| 62 | |
| 63 | # Disable checkouting the model from remote repository |
| 64 | cat << 'EOF' >> /srv/salt/reclass/nodes/{{ HOSTNAME_CFG01 }}.yml |
| 65 | # local storage |
| 66 | reclass: |
| 67 | storage: |
| 68 | data_source: |
| 69 | engine: local |
| 70 | EOF |
| 71 | {%- endmacro %} |