[states] baremetal_init: Parameterize kvm hosts
[fuel.git] / mcp / scripts / xdf_data.sh.j2
1 #!/bin/bash -e
2 # shellcheck disable=SC2034
3 ##############################################################################
4 # Copyright (c) 2018 Mirantis Inc., Enea AB and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10 #
11 # Data derived from XDF (PDF/IDF/SDF/etc), used as input in deploy.sh
12 #
13
14 {%- import 'net_map.j2' as nm with context -%}
15 {%- set arch = conf[conf.MCP_JUMP_ARCH] -%}
16 {%- set V = conf.virtual -%}
17 {%- set section_map = {
18   'infra': -1,
19   'control': nm.ctl01.idx,
20   'compute': nm.cmp001.idx
21 } -%}
22
23 {%- macro bash_arr(_l) -%}
24   ({%- for n in _l -%}'{{ n }}' {% endfor -%})
25 {%- endmacro -%}
26
27 {#- Pack list as `sep`-separated string, replacing spaces with '|' -#}
28 {%- macro pack(x = [], sep = ',') -%}
29   {{ x | join(sep) | replace(' ', '|') }}
30 {%- endmacro -%}
31
32 {#- Pack all vnode data as string -#}
33 {%- macro serialize_vnodes() -%}
34   {%- set arr = [] -%}
35   {%- for section in section_map -%}
36     {%- for n in V.nodes[section] -%}
37       {%- if section_map[section] < 0 or conf.nodes[section_map[section] + loop.index0].node.type == 'virtual' -%}
38         {%- if n not in V -%}{%- do V.update({n: {}}) -%}{%- endif -%}
39         {%- do arr.append(pack([n, V[n].ram or arch.default.ram,
40                                    V[n].vcpus or arch.default.vcpus])) -%}
41       {%- endif -%}
42     {%- endfor -%}
43   {%- endfor -%}
44   '{{ pack(arr, '|') }}'
45 {%- endmacro -%}
46
47 {#- Return a bash array of node names or a Salt query, optionally filtered by type #}
48 {%- macro filter_nodes(type, output_as_query = False, sections = section_map) -%}
49   {%- set arr = [] -%}
50   {%- for section in sections -%}
51     {%- for n in V.nodes[section] -%}
52       {%- if ( (section_map[section] < 0 and type == 'virtual') or
53                (section_map[section] >= 0 and
54                 conf.nodes[section_map[section] + loop.index0].node.type in type) ) -%}
55         {%- do arr.append(n) -%}
56       {%- endif -%}
57     {%- endfor -%}
58   {%- endfor -%}
59   {%- if output_as_query -%}
60   '{{ arr | join('* or ') }}*'
61   {%- else -%}
62   {{ bash_arr(arr) }}
63   {%- endif -%}
64 {%- endmacro -%}
65
66 {#- Pack apt_pkg data as string -#}
67 {%- macro serialize_apt_pkg() -%}
68   {%- set arr = [] -%}
69   {%- set sections = [arch.common] -%}
70   {%- if conf.MCP_VCP -%}
71     {%- do sections.append(arch.control) -%}
72   {%- endif -%}
73   {%- for c in sections -%}
74     {%- do arr.append(pack([pack(c.apt['keys']), pack(c.apt.repos),
75                             pack(c.pkg.install), pack(c.pkg.remove)], '^')) -%}
76   {%- endfor -%}
77   '{{ pack(arr, '^') }}'
78 {%- endmacro -%}
79
80 {%- set bridges = conf.idf.fuel.jumphost.bridges %}
81 # Determine bridge names based on IDF, where all bridges are now mandatory
82 OPNFV_BRIDGES=(
83   '{{ bridges.admin or "pxebr" }}'
84   '{{ bridges.mgmt or "mgmt" }}'
85   '{{ bridges.private or "internal" }}'
86   '{{ bridges.public or "public" }}'
87 )
88
89 export CLUSTER_DOMAIN={{ conf.cluster.domain }}
90 cluster_states={{ bash_arr(conf.cluster.states) }}
91 virtual_nodes={{ filter_nodes('virtual') }}
92 control_nodes_query={{ filter_nodes(['baremetal', 'virtual'], True, ['control']) }}
93 base_image={{ arch.base_image }}
94
95 # Serialize vnode data as '<name0>,<ram0>,<vcpu0>|<name1>,<ram1>,<vcpu1>[...]'
96 virtual_nodes_data={{ serialize_vnodes() }}
97
98 # Serialize repos, packages to (pre-)install/remove for:
99 # - foundation node VM base image (virtual: all VMs, baremetal: cfg01|mas01)
100 # - virtualized control plane VM base image (only when VCP is used)
101 virtual_repos_pkgs={{ serialize_apt_pkg() }}