Dennis Dmitriev | 9dada8a | 2017-08-30 17:38:55 +0300 | [diff] [blame] | 1 | {% from 'cookieshape-mcp-ocata-dvr-vxlan/underlay.yaml' import HOSTNAME_CFG01 with context %} |
| 2 | {% from 'cookieshape-mcp-ocata-dvr-vxlan/underlay.yaml' import LAB_CONFIG_NAME with context %} |
| 3 | {% from 'cookieshape-mcp-ocata-dvr-vxlan/underlay.yaml' import DOMAIN_NAME with context %} |
| 4 | |
| 5 | {% set SALT_MODELS_REPOSITORY = os_env('SALT_MODELS_REPOSITORY','https://gerrit.mcp.mirantis.net/salt-models/mcp-virtual-lab') %} |
| 6 | # Other salt model repository parameters see in shared-salt.yaml |
| 7 | |
| 8 | # Name of the context file (without extension, that is fixed .yaml) used to render the Environment model |
| 9 | {% set ENVIRONMENT_MODEL_INVENTORY_NAME = os_env('ENVIRONMENT_MODEL_INVENTORY_NAME','virtual-devops-mcp-ocata-sl2') %} |
| 10 | |
| 11 | |
| 12 | {% import 'shared-salt.yaml' as SHARED with context %} |
| 13 | |
| 14 | {{ SHARED.MACRO_INSTALL_SALT_MASTER() }} |
| 15 | |
| 16 | |
| 17 | {#{ SHARED.MACRO_CLONE_RECLASS_MODELS() }#} |
| 18 | - description: Create cluster model from cookiecutter templates |
| 19 | cmd: | |
| 20 | set -e; |
| 21 | pip install cookiecutter |
| 22 | export GIT_SSL_NO_VERIFY=true; git clone https://gerrit.mcp.mirantis.net/mk/cookiecutter-templates /tmp/cookiecutter-templates |
| 23 | mkdir -p /srv/salt/reclass/classes/cluster/ |
| 24 | mkdir -p /srv/salt/reclass/classes/system/ |
| 25 | mkdir -p /srv/salt/reclass/classes/service/ |
| 26 | mkdir -p /srv/salt/reclass/nodes/ |
| 27 | |
| 28 | sed -i 's/cluster_name:.*/cluster_name: {{ LAB_CONFIG_NAME }}/g' /tmp/cookiecutter-templates/contexts/openstack_ovs_dvr_vxlan.yml |
| 29 | sed -i 's/cluster_domain:.*/cluster_domain: {{ DOMAIN_NAME }}/g' /tmp/cookiecutter-templates/contexts/openstack_ovs_dvr_vxlan.yml |
| 30 | |
| 31 | # Replace firstly to an intermediate value to avoid intersection between |
| 32 | # already replaced and replacing networks. |
| 33 | # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice: |
| 34 | # 192.168.10 -> 10.16.0 (generated network for admin) |
| 35 | # 10.16.0 -> <external network> |
| 36 | # So let's replace constant networks to the keywords, and then keywords to the desired networks. |
| 37 | sed -i 's/10\.167\.5\./==IPV4_NET_ADMIN_PREFIX==/g' /tmp/cookiecutter-templates/contexts/openstack_ovs_dvr_vxlan.yml |
| 38 | sed -i 's/10\.167\.4\./==IPV4_NET_CONTROL_PREFIX==/g' /tmp/cookiecutter-templates/contexts/openstack_ovs_dvr_vxlan.yml |
| 39 | sed -i 's/10\.167\.6\./==IPV4_NET_TENANT_PREFIX==/g' /tmp/cookiecutter-templates/contexts/openstack_ovs_dvr_vxlan.yml |
| 40 | sed -i 's/172\.17\.16\./==IPV4_NET_EXTERNAL_PREFIX==/g' /tmp/cookiecutter-templates/contexts/openstack_ovs_dvr_vxlan.yml |
| 41 | |
| 42 | sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ SHARED.IPV4_NET_ADMIN_PREFIX }}./g' /tmp/cookiecutter-templates/contexts/openstack_ovs_dvr_vxlan.yml |
| 43 | sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ SHARED.IPV4_NET_CONTROL_PREFIX }}./g' /tmp/cookiecutter-templates/contexts/openstack_ovs_dvr_vxlan.yml |
| 44 | sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ SHARED.IPV4_NET_TENANT_PREFIX }}./g' /tmp/cookiecutter-templates/contexts/openstack_ovs_dvr_vxlan.yml |
| 45 | sed -i 's/==IPV4_NET_EXTERNAL_PREFIX==/{{ SHARED.IPV4_NET_EXTERNAL_PREFIX }}./g' /tmp/cookiecutter-templates/contexts/openstack_ovs_dvr_vxlan.yml |
| 46 | |
| 47 | for i in $(ls /tmp/cookiecutter-templates/cluster_product/); do |
| 48 | cookiecutter /tmp/cookiecutter-templates/cluster_product/$i \ |
| 49 | --config-file /tmp/cookiecutter-templates/contexts/openstack_ovs_dvr_vxlan.yml \ |
| 50 | --output-dir /srv/salt/reclass/classes/cluster/ \ |
| 51 | --no-input -f; |
| 52 | done |
| 53 | |
| 54 | export GIT_SSL_NO_VERIFY=true; git clone https://gerrit.mcp.mirantis.net/salt-models/reclass-system /srv/salt/reclass/classes/system/ |
| 55 | |
| 56 | # Create the cfg01 node and disable checkouting the model from remote repository |
| 57 | cat << 'EOF' >> /srv/salt/reclass/nodes/{{ HOSTNAME_CFG01 }}.yml |
| 58 | classes: |
| 59 | - cluster.{{ LAB_CONFIG_NAME }}.infra.config |
| 60 | parameters: |
| 61 | _param: |
| 62 | linux_system_codename: xenial |
| 63 | reclass_data_revision: master |
| 64 | linux: |
| 65 | system: |
| 66 | name: cfg01 |
| 67 | domain: {{ DOMAIN_NAME }} |
| 68 | # local storage |
| 69 | reclass: |
| 70 | storage: |
| 71 | data_source: |
| 72 | engine: local |
| 73 | EOF |
| 74 | |
| 75 | node_name: {{ HOSTNAME_CFG01 }} |
| 76 | retry: {count: 1, delay: 1} |
| 77 | skip_fail: false |
| 78 | |
| 79 | - description: Modify cluster model for testing purposes |
| 80 | cmd: | |
| 81 | set -e; |
| 82 | apt-get -y install python-virtualenv python-pip build-essential python-dev libssl-dev; |
| 83 | pip install git+https://github.com/dis-xcom/reclass-tools; |
| 84 | |
| 85 | # Enable 'root' user |
| 86 | reclass-tools add-key classes system.openssh.server.team.lab /srv/salt/reclass/classes/cluster/{{ LAB_CONFIG_NAME }}/infra/config.yml --merge |
| 87 | |
| 88 | node_name: {{ HOSTNAME_CFG01 }} |
| 89 | retry: {count: 1, delay: 1} |
| 90 | skip_fail: false |
| 91 | |
| 92 | |
| 93 | {{ SHARED.MACRO_CONFIGURE_RECLASS(FORMULA_SERVICES='"linux" "reclass" "salt" "openssh" "ntp" "git" "nginx" "collectd" "sensu" "heka" "sphinx" "keystone" "mysql" "grafana" "haproxy" "rsyslog" "horizon" "prometheus" "telegraf" "elasticsearch" "powerdns" "glusterfs" "xtrabackup"') }} |
| 94 | |
| 95 | |
| 96 | - description: Upload 'environment' to {{ HOSTNAME_GTW01 }} |
| 97 | upload: |
| 98 | local_path: {{ config.salt_deploy.environment_template_dir }} |
| 99 | remote_path: /tmp/environment/ |
| 100 | node_name: {{ HOSTNAME_CFG01 }} |
| 101 | skip_fail: false |
| 102 | |
| 103 | - description: "[EXPERIMENTAL] Create environment model for virtual environment" |
| 104 | cmd: | |
| 105 | set -e; |
| 106 | ln -s '/tmp/environment/environment_template/{{ '{# interfaces #}' }}' '/tmp/environment/environment_template/{{ '{{ cookiecutter._env_name }}' }}/'; |
| 107 | ln -s '/tmp/environment/environment_template/{{ '{# roles #}' }}' '/tmp/environment/environment_template/{{ '{{ cookiecutter._env_name }}' }}/'; |
| 108 | reclass-tools render --template-dir /tmp/environment/environment_template/ \ |
| 109 | --output-dir /srv/salt/reclass/classes/environment/ \ |
| 110 | --context /tmp/environment/environment_inventory/{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}.yaml \ |
| 111 | --env-name {{ ENVIRONMENT_MODEL_INVENTORY_NAME }} |
| 112 | node_name: {{ HOSTNAME_CFG01 }} |
| 113 | retry: {count: 1, delay: 5} |
| 114 | skip_fail: false |
| 115 | |
| 116 | - description: "[EXPERIMENTAL] Remove linux.network.interface object from the cluster/system models and use fixed 'environment' model instead" |
| 117 | cmd: | |
| 118 | apt-get -y install python-virtualenv python-pip build-essential python-dev libssl-dev; |
| 119 | pip install git+https://github.com/dis-xcom/reclass-tools; |
| 120 | reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/cluster/; |
| 121 | reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/system/; |
| 122 | reclass-tools del-key parameters.linux.network.interface /usr/share/salt-formulas/reclass/; |
| 123 | |
| 124 | if ! reclass-tools get-key 'classes' /srv/salt/reclass/nodes/{{ HOSTNAME_CFG01 }}.yml | grep -q "environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}$"; then |
| 125 | reclass-tools add-key 'classes' 'environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}' /srv/salt/reclass/nodes/{{ HOSTNAME_CFG01 }}.yml --merge ; |
| 126 | fi; |
| 127 | |
| 128 | node_name: {{ HOSTNAME_CFG01 }} |
| 129 | retry: {count: 1, delay: 5} |
| 130 | skip_fail: false |
| 131 | |
| 132 | {{ SHARED.MACRO_INSTALL_SALT_MINIONS() }} |
| 133 | |
| 134 | {{ SHARED.MACRO_RUN_SALT_MASTER_UNDERLAY_STATES() }} |
| 135 | |
| 136 | {{ SHARED.MACRO_GENERATE_INVENTORY() }} |
| 137 | |
| 138 | {{ SHARED.MACRO_NETWORKING_WORKAROUNDS() }} |
| 139 | |
| 140 | {{ SHARED.MACRO_BOOTSTRAP_ALL_MINIONS() }} |
| 141 | |
| 142 | #- description: Hack gtw node |
| 143 | # cmd: salt 'gtw*' cmd.run "ip addr del {{ SHARED.IPV4_NET_CONTROL_PREFIX }}.110/24 dev ens4; ip addr flush dev ens4"; |
| 144 | # node_name: {{ HOSTNAME_CFG01 }} |
| 145 | # retry: {count: 1, delay: 10} |
| 146 | # skip_fail: false |
| 147 | |
| 148 | #- description: Hack cmp01 node |
| 149 | # cmd: salt 'cmp01*' cmd.run "ip addr del {{ SHARED.IPV4_NET_CONTROL_PREFIX }}.105/24 dev ens4; ip addr flush dev ens4"; |
| 150 | # node_name: {{ HOSTNAME_CFG01 }} |
| 151 | # retry: {count: 1, delay: 10} |
| 152 | # skip_fail: false |
| 153 | |
| 154 | #- description: Hack cmp02 node |
| 155 | # cmd: salt 'cmp02*' cmd.run "ip addr del {{ SHARED.IPV4_NET_CONTROL_PREFIX }}.106/24 dev ens4; ip addr flush dev ens4"; |
| 156 | # node_name: {{ HOSTNAME_CFG01 }} |
| 157 | # retry: {count: 1, delay: 10} |
| 158 | # skip_fail: false |