[scenario] Factor out common nodes, states
[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 {%- do V.nodes.update(arch.default.virtual.nodes) -%}
18 {%- set section_map = {
19   'infra': -1,
20   'control': nm.ctl01.idx,
21   'compute': nm.cmp001.idx
22 } -%}
23
24 {%- macro bash_arr(_l) -%}
25   ({%- for n in _l -%}'{{ n }}' {% endfor -%})
26 {%- endmacro -%}
27
28 {#- Pack list as `sep`-separated string, replacing spaces with '|' -#}
29 {%- macro pack(x = [], sep = ',') -%}
30   {{ x | join(sep) | replace(' ', '|') }}
31 {%- endmacro -%}
32
33 {#- Pack all vnode data as string -#}
34 {%- macro serialize_vnodes() -%}
35   {%- set arr = [] -%}
36   {%- for section in section_map -%}
37     {%- for n in V.nodes[section] or [] -%}
38       {%- if section_map[section] < 0 or conf.nodes[section_map[section] + loop.index0].node.type == 'virtual' -%}
39         {%- if n not in V -%}{%- do V.update({n: {}}) -%}{%- endif -%}
40         {%- do arr.append(pack([n, V[n].ram or arch.default.ram,
41                                    V[n].vcpus or arch.default.vcpus])) -%}
42       {%- endif -%}
43     {%- endfor -%}
44   {%- endfor -%}
45   '{{ pack(arr, '|') }}'
46 {%- endmacro -%}
47
48 {#- Return a bash array of node names or a Salt query, optionally filtered by type #}
49 {%- macro filter_nodes(type, output_as_query = False, sections = section_map) -%}
50   {%- set arr = [] -%}
51   {%- for section in sections -%}
52     {%- for n in V.nodes[section] or [] -%}
53       {%- if ( (section_map[section] < 0 and type == 'virtual') or
54                (section_map[section] >= 0 and
55                 conf.nodes[section_map[section] + loop.index0].node.type in type) ) -%}
56         {%- do arr.append(n) -%}
57       {%- endif -%}
58     {%- endfor -%}
59   {%- endfor -%}
60   {%- if output_as_query -%}
61   '{{ arr | join('* or ') }}*'
62   {%- else -%}
63   {{ bash_arr(arr) }}
64   {%- endif -%}
65 {%- endmacro -%}
66
67 {#- Pack apt_pkg data as string -#}
68 {%- macro serialize_apt_pkg() -%}
69   {%- set arr = [] -%}
70   {%- set sections = [arch.common] -%}
71   {%- if conf.MCP_VCP -%}
72     {%- do sections.append(arch.control) -%}
73   {%- endif -%}
74   {%- for c in sections -%}
75     {%- do arr.append(pack([pack(c.apt['keys']), pack(c.apt.repos),
76                             pack(c.pkg.install), pack(c.pkg.remove)], '^')) -%}
77   {%- endfor -%}
78   '{{ pack(arr, '^') }}'
79 {%- endmacro -%}
80
81 {%- set bridges = conf.idf.fuel.jumphost.bridges %}
82 # Determine bridge names based on IDF, where all bridges are now mandatory
83 OPNFV_BRIDGES=(
84   '{{ bridges.admin or "pxebr" }}'
85   '{{ bridges.mgmt or "mgmt" }}'
86   '{{ bridges.private or "internal" }}'
87   '{{ bridges.public or "public" }}'
88 )
89
90 export CLUSTER_DOMAIN={{ conf.cluster.domain }}
91 cluster_states={{ bash_arr(arch.default.cluster.states + conf.cluster.states) }}
92 virtual_nodes={{ filter_nodes('virtual') }}
93 control_nodes_query={{ filter_nodes(['baremetal', 'virtual'], True, ['control']) }}
94 base_image={{ arch.base_image }}
95
96 # Serialize vnode data as '<name0>,<ram0>,<vcpu0>|<name1>,<ram1>,<vcpu1>[...]'
97 virtual_nodes_data={{ serialize_vnodes() }}
98
99 # Serialize repos, packages to (pre-)install/remove for:
100 # - foundation node VM base image (virtual: all VMs, baremetal: cfg01|mas01)
101 # - virtualized control plane VM base image (only when VCP is used)
102 virtual_repos_pkgs={{ serialize_apt_pkg() }}