2114c0b71ecac1cda45f48e4d633012bce53ed8d
[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
16
17   if output=$(python3 -B $LIB/python/apex_python_utils.py parse-net-settings -s $NETSETS -td $APEX_TMP_DIR -e $BASE/network-environment.yaml); then
18       echo -e "${blue}${output}${reset}"
19       eval "$output"
20   else
21       echo -e "${red}ERROR: Failed to parse network settings file $NETSETS ${reset}"
22       exit 1
23   fi
24
25   if [ "${deploy_options_array['dataplane']}" == 'ovs_dpdk' ]; then
26     if [[ ! $enabled_network_list =~ "tenant" ]]; then
27       echo -e "${red}ERROR: tenant network is not enabled for ovs-dpdk ${reset}"
28       exit 1
29     fi
30   fi
31 }
32
33 ##parses deploy settings yaml into globals
34 parse_deploy_settings() {
35   local output
36   if output=$(python3 -B $LIB/python/apex_python_utils.py parse-deploy-settings -f $DEPLOY_SETTINGS_FILE); then
37       echo -e "${blue}${output}${reset}"
38       eval "$output"
39   else
40       echo -e "${red}ERROR: Failed to parse deploy settings file $DEPLOY_SETTINGS_FILE ${reset}"
41       exit 1
42   fi
43
44 }
45
46 ##parses baremetal yaml settings into compatible json
47 ##writes the json to undercloud:instackenv.json
48 ##params: none
49 ##usage: parse_inventory_file
50 parse_inventory_file() {
51   local output
52   if [ "$virtual" == "TRUE" ]; then inv_virt="--virtual"; fi
53   if [[ "$ha_enabled" == "True" ]]; then inv_ha="--ha"; fi
54   instackenv_output=$(python3 -B $LIB/python/apex_python_utils.py parse-inventory -f $INVENTORY_FILE $inv_virt $inv_ha)
55   #Copy instackenv.json to undercloud
56   echo -e "${blue}Parsed instackenv JSON:\n${instackenv_output}${reset}"
57   ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
58 cat > instackenv.json << EOF
59 $instackenv_output
60 EOF
61 EOI
62   if output=$(python3 -B $LIB/python/apex_python_utils.py parse-inventory -f $INVENTORY_FILE $inv_virt $inv_ha --export-bash); then
63     echo -e "${blue}${output}${reset}"
64     eval "$output"
65   else
66     echo -e "${red}ERROR: Failed to parse inventory bash settings file ${INVENTORY_FILE}${reset}"
67     exit 1
68   fi
69
70 }