aboutsummaryrefslogtreecommitdiffstats
path: root/mcp/scripts/lib.sh
diff options
context:
space:
mode:
authorAlexandru Avadanii <Alexandru.Avadanii@enea.com>2018-03-03 21:39:59 +0100
committerAlexandru Avadanii <Alexandru.Avadanii@enea.com>2018-03-07 03:19:45 +0100
commit256e2a50b9b340bb78a8c85fdd7cacf96d0fb637 (patch)
tree2d9c7174840020b6d40012c65a82e75493bbad29 /mcp/scripts/lib.sh
parent3f63be553d8be68b2dc39dd2813bf5ffef0c3207 (diff)
[vnode parsing] Move core logic to j2
j2/python is easier to read and manipulate strings, although it does need some special care about undefined dict keys. With this in place, deploy.sh only contains the higher level logic for the deployment process. - merge arch-specific default configuration files into a singular file with arch name as main dict key of old config (also avoids creating duplicate 'virtual' YAML keys in $LOCAL_PDF); - move template handling to separate <lib_template.sh>; - decouple tight bash ordering of scenario expansion -> parse_yaml -> variable export (e.g. CLUSTER_DOMAIN) -> re-use in cluster j2s; however we can't parse *all* j2s in one go, as scenario j2s might expand to YAMLs needed while expanding cluster j2; - split `do_templates` into separate functions for each stage, with no coupling between them other then call order; Change-Id: I4b5e804094c00e5e918caf769fd85fa52181ad76 Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
Diffstat (limited to 'mcp/scripts/lib.sh')
-rw-r--r--mcp/scripts/lib.sh64
1 files changed, 1 insertions, 63 deletions
diff --git a/mcp/scripts/lib.sh b/mcp/scripts/lib.sh
index e8edf9587..5be4c556d 100644
--- a/mcp/scripts/lib.sh
+++ b/mcp/scripts/lib.sh
@@ -1,7 +1,7 @@
#!/bin/bash -e
# shellcheck disable=SC2155,SC1001,SC2015,SC2128
##############################################################################
-# Copyright (c) 2017 Mirantis Inc., Enea AB and others.
+# Copyright (c) 2018 Mirantis Inc., Enea AB and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
@@ -543,65 +543,3 @@ function get_nova_compute_pillar_data {
echo "${value}"
fi
}
-
-function do_templates() {
- local git_repo_root=$1; shift
- local image_dir=$1; shift
- local target_lab=$1; shift
- local target_pod=$1; shift
- local lab_config_uri=$1; shift
- local scenario_dir=${1:-}
-
- RECLASS_CLUSTER_DIR=$(cd "${git_repo_root}/mcp/reclass/classes/cluster"; pwd)
- PHAROS_GEN_CFG="./pharos/config/utils/generate_config.py"
- PHAROS_IA=$(readlink -f "./pharos/config/installers/fuel/pod_config.yml.j2")
- PHAROS_VALIDATE_SCHEMA_SCRIPT="./pharos/config/utils/validate_schema.py"
- PHAROS_SCHEMA_PDF="./pharos/config/pdf/pod1.schema.yaml"
- PHAROS_SCHEMA_IDF="./pharos/config/pdf/idf-pod1.schema.yaml"
- BASE_CONFIG_PDF="${lab_config_uri}/labs/${target_lab}/${target_pod}.yaml"
- BASE_CONFIG_IDF="${lab_config_uri}/labs/${target_lab}/idf-${target_pod}.yaml"
- LOCAL_PDF="${image_dir}/$(basename "${BASE_CONFIG_PDF}")"
- LOCAL_IDF="${image_dir}/$(basename "${BASE_CONFIG_IDF}")"
-
- # Two-stage expansion, first stage handles pod_config and scenarios only
- if [ -n "${scenario_dir}" ]; then
- # Make sample PDF/IDF available via default lab-config (pharos submodule)
- ln -sf "$(readlink -f "../config/labs/local")" "./pharos/labs/"
-
- # Expand scenario file and main reclass input (pod_config.yaml) based on PDF
- if ! curl --create-dirs -o "${LOCAL_PDF}" "${BASE_CONFIG_PDF}"; then
- notify_e "[ERROR] Could not retrieve PDF (Pod Descriptor File)!"
- elif ! curl -o "${LOCAL_IDF}" "${BASE_CONFIG_IDF}"; then
- notify_e "[ERROR] Could not retrieve IDF (Installer Descriptor File)!"
- fi
- # Check first if configuration files are valid
- if [[ ! "$target_pod" =~ "virtual" ]]; then
- if ! "${PHAROS_VALIDATE_SCHEMA_SCRIPT}" -y "${LOCAL_PDF}" \
- -s "${PHAROS_SCHEMA_PDF}"; then
- notify_e "[ERROR] PDF does not match yaml schema!"
- elif ! "${PHAROS_VALIDATE_SCHEMA_SCRIPT}" -y "${LOCAL_IDF}" \
- -s "${PHAROS_SCHEMA_IDF}"; then
- notify_e "[ERROR] IDF does not match yaml schema!"
- fi
- fi
- if ! "${PHAROS_GEN_CFG}" -y "${LOCAL_PDF}" \
- -j "${PHAROS_IA}" -v > "${image_dir}/pod_config.yml"; then
- notify_e "[ERROR] Could not convert PDF+IDF to reclass model input!"
- fi
- template_dirs="${scenario_dir}"
- template_err_str='Could not convert j2 scenario definitions!'
- else
- # Expand reclass and virsh network templates based on PDF + IDF
- printenv | \
- awk '/^(SALT|MCP|MAAS|CLUSTER).*=/ { gsub(/=/,": "); print }' >> "${LOCAL_PDF}"
- template_dirs="${RECLASS_CLUSTER_DIR} $(readlink -f virsh_net) $(readlink -f ./*j2)"
- template_err_str='Could not convert PDF to network definitions!'
- fi
- # shellcheck disable=SC2086
- j2args=$(find $template_dirs -name '*.j2' -exec echo -j {} \;)
- # shellcheck disable=SC2086
- if ! "${PHAROS_GEN_CFG}" -y "${LOCAL_PDF}" ${j2args} -b -v \
- -i "$(dirname "${PHAROS_IA}")"; then
- notify_e "[ERROR] ${template_err_str}"
- fi
-}