summaryrefslogtreecommitdiffstats
path: root/deploy/deploy_parameter.sh
blob: d8696ce8511bc909e41d59bea48828993ec0df37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

@media only all and (prefers-color-scheme: dark) {
.highlight .hll { background-color: #49483e }
.highlight .c { color: #75715e } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .k { color: #66d9ef } /* Keyword */
.highlight .l { color: #ae81ff } /* Literal */
.highlight .n { color: #f8f8f2 } /* Name */
.highlight .o { color: #f92672 } /* Operator */
.highlight .p { color: #f8f8f2 } /* Punctuation */
.highlight .ch { color: #75715e } /* Comment.Hashbang */
.highlight .cm { color: #75715e } /* Comment.Multiline */
.highlight .cp { color: #75715e } /* Comment.Preproc */
.highlight .cpf { color: #75715e } /* Comment.PreprocFile */
.highlight .c1 { color: #75715e } /* Comment.Single */
.highlight .cs { color: #75715e } /* Comment.Special */
.highlight .gd { color: #f92672 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gi { color: #a6e22e } /* Generic.Inserted */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #75715e } /* Generic.Subheading */
.highlight .kc { color: #66d9ef } /* Keyword.Constant */
.highlight .kd { color: #66d9ef } /* Keyword.Declaration */
.highlight .kn { color: #f92672 } /* Keyword.Namespace */
.highlight .kp { color: #66d9ef } /* Keyword.Pseudo */
.highlight .kr { color: #66d9ef } /* Keyword.Reserved */
.highlight .kt { color: #66d9ef } /* Keyword.Type */
.highlight .ld { color: #e6db74 } /* Literal.Date */
.highlight .m { color: #ae81ff } /* Literal.Number */
.highlight .s { color: #e6db74 } /* Literal.String */
.highlight .na { color: #a6e22e } /* Name.Attribute */
.highlight 
#!/bin/bash
##############################################################################
# Copyright (c) 2016 HUAWEI TECHNOLOGIES CO.,LTD 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
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
set -x
function get_option_name_list()
{
    echo $(echo "$1" | xargs -n 1 grep -oP "export .*?=" | \
            awk '{print $2}' | sort | uniq | sed -e 's/=$//g')
}
function get_option_flag_list()
{
    echo $(echo "$1" | tr [:upper:] [:lower:] | \
                 xargs | sed  -e 's/ /:,/g' -e 's/_/-/g')
}

function get_conf_name()
{
    if [[ -n $DHA ]]; then
        return
    fi

    cfg_file=`ls $COMPASS_DIR/deploy/conf/*.conf`
    option_name=`get_option_name_list "$cfg_file"`
    option_flag=`get_option_flag_list "$option_name"`

    TEMP=`getopt -o h -l dha:,network:,neutron:,conf-dir:,$option_flag -n 'deploy_parameter.sh' -- "$@"`

    if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
    eval set -- "$TEMP"
    while :; do
        if [[ "$1" == "--" ]]; then
            shift
            break
        fi
        shift
    done

    if [[ $# -eq 0 ]]; then
        export DHA="$COMPASS_DIR/deploy/conf/vm_environment/os-nosdn-nofeature-ha.yml"
    else
        file=${1%*.yml}.yml
        if [[ -f $file ]]; then
            export DHA=$file
        elif [[ -f $CONF_DIR/$file ]]; then
            export DHA=$CONF_DIR/$file
        elif [[ -f $COMPASS_DIR/deploy/conf/$file ]]; then
            export DHA=$COMPASS_DIR/deploy/conf/$file
        else
            exit 1
        fi
    fi
}

function generate_input_env_file()
{
    ofile="$WORK_DIR/script/deploy_input.sh"

    echo  '#input deployment  parameter' > $ofile

    cfg_file=`ls $COMPASS_DIR/deploy/conf/{base,"$TYPE"_"$FLAVOR",$TYPE,$FLAVOR,compass}.conf 2>/dev/null`
    option_name=`get_option_name_list "$cfg_file"`
    option_flag=`get_option_flag_list "$option_name"`

    TEMP=`getopt -o h -l dha:,network:,neutron:,conf-dir:,$option_flag -n 'deploy_parameter.sh' -- "$@"`

    if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
    eval set -- "$TEMP"
    while :; do
        if [[ "$1" == "--" ]]; then
            shift
            break
        fi

        option=`echo ${1##-?} | tr [:lower:] [:upper:] | sed 's/-/_/g'`
        echo "export $option=$2" >> $ofile
        shift 2
        continue

    done

    echo $ofile
}

function process_default_para()
{
    if [[ -z $CONF_DIR ]]; then
         local set conf_dir=${COMPASS_DIR}/deploy/conf
    else
         local set conf_dir=$CONF_DIR
    fi

    get_conf_name $*
    python ${COMPASS_DIR}/deploy/config_parse.py \
           "$DHA" "$conf_dir" \
           "${COMPASS_DIR}/deploy/template" \
           "${WORK_DIR}/script" \
           "deploy_config.sh"

    echo ${WORK_DIR}/script/deploy_config.sh
}

function process_input_para()
{
    input_file=`generate_input_env_file $config_file $*`

    echo $input_file
}