79bc16c81ff1d1b62a32efca00814e57a995f6c6
[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 cluster_states = conf.cluster.states if conf.MCP_NO_DEPLOY_ENVIRONMENT < 2 else [] -%}
16 {%- set arch = conf[conf.MCP_JUMP_ARCH] -%}
17 {%- set V = conf.virtual -%}
18 {%- set section_map = {
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] or [] -%}
37       {%- if ( section_map[section] < conf.nodes | length and
38                conf.nodes[section_map[section] + loop.index0].node.type == 'virtual' ) -%}
39         {%- if n not in V -%}{%- do V.update({n: {}}) -%}{%- endif -%}
40         {%- set cpu_topo = 'cpu_topology' in V[n] and not conf.MCP_CMP_SS -%}
41         {%- if 'numa' in V[n] and cpu_topo -%}
42           {%- for k, v in V[n].numa.iteritems() -%}
43             {%- set c = pack([k, v.memory, v.cpus]) -%}
44             {%- do V[n].update({'s_numa': c if 's_numa' not in V[n] else pack([c, V[n].s_numa])}) -%}
45           {%- endfor -%}
46         {%- endif -%}
47         {%- do arr.append(pack([n, V[n].disks or arch.default.disks,
48                                    V[n].ram or arch.default.ram,
49                                    V[n].vcpus or arch.default.vcpus,
50                                    '' if not cpu_topo else pack([
51                                        V[n].cpu_topology.sockets,
52                                        V[n].cpu_topology.cores,
53                                        V[n].cpu_topology.threads,
54                                        '' if 's_numa' not in V[n] else V[n].s_numa])])) -%}
55       {%- endif -%}
56     {%- endfor -%}
57   {%- endfor -%}
58   '{{ pack(arr, '|') }}'
59 {%- endmacro -%}
60
61 {#- Return a bash array of node names or a Salt query, optionally filtered by type #}
62 {%- macro filter_nodes(type, output_as_query = False, sections = section_map) -%}
63   {%- set arr = [] -%}
64   {%- for section in sections -%}
65     {%- for n in V.nodes[section] or [] -%}
66       {%- if ( section_map[section] < conf.nodes | length and
67                conf.nodes[section_map[section] + loop.index0].node.type in type ) -%}
68         {%- do arr.append(n) -%}
69       {%- endif -%}
70     {%- endfor -%}
71   {%- endfor -%}
72   {%- if output_as_query -%}
73   '{{ arr | join('* or ') }}*'
74   {%- else -%}
75   {{ bash_arr(arr) }}
76   {%- endif -%}
77 {%- endmacro -%}
78
79 {#- Pack repo_pkg data as string -#}
80 {%- macro serialize_repo_pkg() -%}
81   {%- set arr = [] -%}
82   {%- set sections = [arch[conf.MCP_OS].common] -%}
83   {%- if conf.MCP_VCP or '-vcp-' in conf.MCP_DEPLOY_SCENARIO -%}
84     {%- do sections.append(arch[conf.MCP_OS].control) -%}
85   {%- endif -%}
86   {%- for c in sections -%}
87     {%- do arr.append(pack([pack(c.repo['keys']), pack(c.repo.repos),
88                             pack(c.pkg.install), pack(c.pkg.remove)], '^')) -%}
89   {%- endfor -%}
90   '{{ pack(arr, '^') }}'
91 {%- endmacro -%}
92
93 {%- set bridges = conf.idf.fuel.jumphost.bridges %}
94 # Determine bridge names based on IDF, where all bridges are now mandatory
95 OPNFV_BRIDGES=(
96   '{{ bridges.admin or "pxebr" }}'
97   '{{ bridges.mgmt or "mgmt" }}'
98   '{{ bridges.private or "internal" }}'
99   '{{ bridges.public or "public" }}'
100 )
101
102 export CLUSTER_DOMAIN={{ conf.cluster.domain }}
103 dns_public={{ nm.dns_public[0] }}
104 cluster_states={{ bash_arr(arch.default.cluster.states + cluster_states) }}
105 virtual_nodes={{ filter_nodes('virtual') }}
106 control_nodes_query={{ filter_nodes(['baremetal', 'virtual'], True, ['control']) }}
107 base_image={{ arch[conf.MCP_OS].base_image }}
108
109 # Serialize vnode data as:
110 #   <name0>,<ram0>,<vcpu0>[,<sockets0>,<cores0>,<threads0>[,<cell0name0>,<cell0memory0>,
111 #   <cell0cpus0>,<cell1name0>,<cell1memory0>,<cell1cpus0>]]|<name1>,...'
112 virtual_nodes_data={{ serialize_vnodes() }}
113
114 # Serialize repos, packages to (pre-)install/remove for:
115 # - foundation node VM base image (virtual: all VMs, baremetal: cfg01|mas01)
116 # - virtualized control plane VM base image (only when VCP is used)
117 virtual_repos_pkgs={{ serialize_repo_pkg() }}