84da75c5037094785f0917e4f268fbc873a4e2a2
[apex.git] / lib / parse-functions.sh
1 #!/usr/bin/env bash
2 ##############################################################################
3 # Copyright (c) 2015 Tim Rozet (Red Hat), Dan Radez (Red Hat) and others.
4 #
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 # Parser functions used by OPNFV Apex
12
13 ##parses network settings yaml into globals
14 parse_network_settings() {
15   local output parse_ext
16   parse_ext=''
17
18   if [[ "${deploy_options_array['dataplane']}" == 'ovs_dpdk' || "${deploy_options_array['dataplane']}" == 'fdio' ]]; then
19       for val in ${performance_roles[@]}; do
20         if [ "$val" == "Compute" ]; then
21           parse_ext="${parse_ext} --compute-pre-config "
22         elif [ "$val" == "Controller" ]; then
23           parse_ext="${parse_ext} --controller-pre-config "
24         fi
25       done
26   fi
27
28   if output=$(python3 -B $LIB/python/apex_python_utils.py parse-net-settings -s $NETSETS -td $APEX_TMP_DIR -e $CONFIG/network-environment.yaml $parse_ext); then
29       echo -e "${blue}${output}${reset}"
30       eval "$output"
31   else
32       echo -e "${red}ERROR: Failed to parse network settings file $NETSETS ${reset}"
33       exit 1
34   fi
35
36   if [ "${deploy_options_array['dataplane']}" == 'ovs_dpdk' ]; then
37     if [[ ! $enabled_network_list =~ "tenant" ]]; then
38       echo -e "${red}ERROR: tenant network is not enabled for ovs-dpdk ${reset}"
39       exit 1
40     fi
41   fi
42 }
43
44 ##parses deploy settings yaml into globals
45 parse_deploy_settings() {
46   local output
47   if output=$(python3 -B $LIB/python/apex_python_utils.py parse-deploy-settings -f $DEPLOY_SETTINGS_FILE); then
48       echo -e "${blue}${output}${reset}"
49       eval "$output"
50   else
51       echo -e "${red}ERROR: Failed to parse deploy settings file $DEPLOY_SETTINGS_FILE ${reset}"
52       exit 1
53   fi
54
55 }
56
57 ##parses baremetal yaml settings into compatible json
58 ##writes the json to undercloud:instackenv.json
59 ##params: none
60 ##usage: parse_inventory_file
61 parse_inventory_file() {
62   if [ "$virtual" == "TRUE" ]; then inv_virt="--virtual"; fi
63   if [[ "$ha_enabled" == "True" ]]; then inv_ha="--ha"; fi
64   instackenv_output=$(python3 -B $LIB/python/apex_python_utils.py parse-inventory -f $INVENTORY_FILE $inv_virt $inv_ha)
65   #Copy instackenv.json to undercloud
66   echo -e "${blue}Parsed instackenv JSON:\n${instackenv_output}${reset}"
67   ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
68 cat > instackenv.json << EOF
69 $instackenv_output
70 EOF
71 EOI
72
73 }