2 ##############################################################################
3 # Copyright (c) 2015 Tim Rozet (Red Hat), Dan Radez (Red Hat) 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 ##############################################################################
11 # Parser functions used by OPNFV Apex
13 ##translates yaml into variables
14 ##params: filename, prefix (ex. "config_")
15 ##usage: parse_yaml opnfv_ksgen_settings.yml "config_"
18 local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
19 sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
20 -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
22 indent = length($1)/2;
24 for (i in vname) {if (i > indent) {delete vname[i]}}
26 vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
27 printf("%s%s%s=%s\n", "'$prefix'",vn, $2, $3);
32 ##parses variable from a string with '='
33 ##and removes global prefix
34 ##params: string, prefix
35 ##usage: parse_setting_var 'deploy_myvar=2' 'deploy_'
39 if echo $mystr | grep -E "^.+\=" > /dev/null; then
40 echo $(echo $mystr | grep -Eo "^.+\=" | tr -d '=' | sed 's/^'"$prefix"'//')
45 ##parses value from a string with '='
47 ##usage: parse_setting_value
48 parse_setting_value() {
50 echo $(echo $mystr | grep -Eo "\=.*$" | tr -d '=')
53 ##parses network settings yaml into globals
54 parse_network_settings() {
55 local output parse_ext
58 if [[ "${deploy_options_array['dataplane']}" == 'ovs_dpdk' || "${deploy_options_array['dataplane']}" == 'fdio' ]]; then
59 for val in ${performance_roles[@]}; do
60 if [ "$val" == "Compute" ]; then
61 parse_ext="${parse_ext} --compute-pre-config "
62 elif [ "$val" == "Controller" ]; then
63 parse_ext="${parse_ext} --controller-pre-config "
68 if output=$(python3.4 -B $LIB/python/apex_python_utils.py parse-net-settings -s $NETSETS $net_isolation_arg -e $CONFIG/network-environment.yaml $parse_ext); then
69 echo -e "${blue}${output}${reset}"
72 echo -e "${red}ERROR: Failed to parse network settings file $NETSETS ${reset}"
76 if [ "${deploy_options_array['dataplane']}" == 'ovs_dpdk' ]; then
77 if [ "$net_isolation_enabled" == "FALSE" ]; then
78 echo -e "${red}ERROR: flat network is not supported with ovs-dpdk ${reset}"
81 if [[ ! $enabled_network_list =~ "private_network" ]]; then
82 echo -e "${red}ERROR: tenant network is not enabled for ovs-dpdk ${reset}"
88 ##parses deploy settings yaml into globals
89 parse_deploy_settings() {
91 if output=$(python3.4 -B $LIB/python/apex_python_utils.py parse-deploy-settings -f $DEPLOY_SETTINGS_FILE); then
92 echo -e "${blue}${output}${reset}"
95 echo -e "${red}ERROR: Failed to parse deploy settings file $DEPLOY_SETTINGS_FILE ${reset}"
101 ##parses baremetal yaml settings into compatible json
102 ##writes the json to $CONFIG/instackenv_tmp.json
104 ##usage: parse_inventory_file
105 parse_inventory_file() {
106 local inventory=$(parse_yaml $INVENTORY_FILE)
108 local node_prefix="node"
113 # detect number of nodes
114 for entry in $inventory; do
115 if echo $entry | grep -Eo "^nodes_node[0-9]+_" > /dev/null; then
116 this_node=$(echo $entry | grep -Eo "^nodes_node[0-9]+_")
117 if [[ "$inventory_list" != *"$this_node"* ]]; then
118 inventory_list+="$this_node "
123 inventory_list=$(echo $inventory_list | sed 's/ $//')
125 for node in $inventory_list; do
129 node_total=$node_count
131 if [[ "$node_total" -lt 5 && "$ha_enabled" == "True" ]]; then
132 echo -e "${red}ERROR: You must provide at least 5 nodes for HA baremetal deployment${reset}"
134 elif [[ "$node_total" -lt 2 ]]; then
135 echo -e "${red}ERROR: You must provide at least 2 nodes for non-HA baremetal deployment${reset}"
139 eval $(parse_yaml $INVENTORY_FILE) || {
140 echo "${red}Failed to parse inventory.yaml. Aborting.${reset}"
150 for node in $inventory_list; do
154 \"pm_password\": \"$(eval echo \${${node}ipmi_pass})\",
155 \"pm_type\": \"$(eval echo \${${node}pm_type})\",
157 \"$(eval echo \${${node}mac_address})\"
159 \"cpu\": \"$(eval echo \${${node}cpus})\",
160 \"memory\": \"$(eval echo \${${node}memory})\",
161 \"disk\": \"$(eval echo \${${node}disk})\",
162 \"arch\": \"$(eval echo \${${node}arch})\",
163 \"pm_user\": \"$(eval echo \${${node}ipmi_user})\",
164 \"pm_addr\": \"$(eval echo \${${node}ipmi_ip})\",
165 \"capabilities\": \"$(eval echo \${${node}capabilities})\"
167 instackenv_output+=${node_output}
168 if [ $node_count -lt $node_total ]; then
169 instackenv_output+=" },"
171 instackenv_output+=" }"
179 #Copy instackenv.json to undercloud for baremetal
180 echo -e "{blue}Parsed instackenv JSON:\n${instackenv_output}${reset}"
181 ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
182 cat > instackenv.json << EOF