From 9aea04342798408bf0afbfec97b90a42392feb09 Mon Sep 17 00:00:00 2001 From: Mirabal Date: Wed, 23 Nov 2016 15:55:09 +0000 Subject: [PATCH] enhancement at script development scripts Signed-off-by: Mirabal --- ...figure-compute-node-develop-UBUNTU16.04.sh | 6 +-- scripts/host-add-develop.sh | 47 +++++++++---------- 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/scripts/configure-compute-node-develop-UBUNTU16.04.sh b/scripts/configure-compute-node-develop-UBUNTU16.04.sh index d54bf70..6024a62 100755 --- a/scripts/configure-compute-node-develop-UBUNTU16.04.sh +++ b/scripts/configure-compute-node-develop-UBUNTU16.04.sh @@ -52,6 +52,7 @@ function _usage(){ echo -e " -f --force: do not prompt for confirmation. If a new user is created, the user name is set as password" echo -e " -u --user: Create if not exist and configure this user for openvim to connect" echo -e " --in --iface-name: creates bridge interfaces on this interface, needed for openvim overlay networks" + exit 1 } function _interface_cfg_generator(){ @@ -356,7 +357,6 @@ function _get_opts() fi done - echo option_help "$option_help" [[ -n "$get_argument" ]] && echo "option '-$option' requires an argument" >&2 && return 1 return 0 @@ -376,16 +376,14 @@ function _parse_opts() interface=$option_iface_name } -#1 CHECK input parameters #Parse opts _get_opts "help:h force:f user:u= iface-name:in= " $* || exit 1 +_parse_opts #check root privileges [ "${USER}" != "root" ] && echo "Needed root privileges" >&2 && exit 2 -_parse_opts - echo "checking interface "$interface _check_interface $interface diff --git a/scripts/host-add-develop.sh b/scripts/host-add-develop.sh index d62db8d..01b877f 100755 --- a/scripts/host-add-develop.sh +++ b/scripts/host-add-develop.sh @@ -1,4 +1,3 @@ - #!/bin/bash ## @@ -26,17 +25,18 @@ function usage(){ - echo -e "\nUsage: $0 --user --ip= --cores= --huge-pages-1G= --nb-10GB-interfaces==" + echo -e "\nUsage: $0 --user-name --ip= --cores= --huge-pages-1G= --nb-10GB-interfaces==" echo -e "Generate a develop host yaml to be used for openvim host-add\n" - echo -e " --user -u Server OAM Ip" - echo -e " --ip -i Server hostname" - echo -e " --cores -c Numa Cores available must be an odd number and bigger or equal to 4." + echo -e " --user-name -u * Server OAM Ip" + echo -e " --ip -i * Server hostname" + echo -e " --cores -c Numa Cores available must be an odd number and bigger or equal to 4." echo -e " --huge-pages-1G -hp Must be an odd number and bigger or equal to 16. 4GiB of memory will be reserved for the host OS, the rest will be used by VM." echo -e " --nb-10GB-interfaces -ni Dataplane interfaces must be an odd number and bigger or equal to 4." + echo -e " * Mandatory arguments" echo -e "\n" echo -e "The output will be a server descriptor with two numas and resources (memory, cores and interfaces) equally distributed between them." echo -e "Each interface (physical funtion) will have defined 8 SR-IOV (virtual functions)." - echo -e "\n" + exit 1 } @@ -62,8 +62,8 @@ function _parse_opts(){ fi #User argument - [ -z "$option_user" ] && echo -e "ERROR: User argument is mandatory, --user=\n" && usage - USER=${option_user} + [ -z "$option_user_name" ] && echo -e "ERROR: User argument is mandatory, --user-name=\n" && usage + USER_NAME=${option_user_name} [ -z "$option_ip" ] && echo -e "ERROR: OAM IP argument is mandatory, --ip=\n" && usage IP=${option_ip} @@ -118,11 +118,11 @@ function _generate_compute_develope_yaml(){ echo2file echo2file "host:" echo2file " name: $HOST_NAME" - echo2file " user: $USER" + echo2file " user: $USER_NAME" echo2file " ip_name: $IP" echo2file "host-data:" echo2file " name: $HOST_NAME" - echo2file " user: $USER" + echo2file " user: $USER_NAME" echo2file " ip_name: $IP" echo2file " ranking: 100" echo2file " description: $HOST_NAME" @@ -206,8 +206,6 @@ function echo2file(){ function _get_opts() { - [[ ${BASH_SOURCE[0]} != $0 ]] && ___exit="return" || ___exit="exit" - options="$1" shift @@ -228,7 +226,7 @@ function _get_opts() shift if [[ -n $get_argument ]] then - [[ ${argument:0:1} == "-" ]] && echo "option '-$option' requires an argument" >&2 && $___exit 1 + [[ ${argument:0:1} == "-" ]] && echo "option '-$option' requires an argument" >&2 && return 1 eval ${get_argument}='"$argument"' #echo option $get_argument with argument get_argument="" @@ -272,7 +270,7 @@ function _get_opts() fi done done - [[ $bad_option == y ]] && echo "invalid argument '-$option'? Type -h for help" >&2 && $___exit 1 + [[ $bad_option == y ]] && echo "invalid argument '-$option'? Type -h for help" >&2 && return 1 done elif [[ ${argument:0:2} == "--" ]] && [[ ${#argument} -ge 3 ]] then @@ -293,7 +291,7 @@ function _get_opts() bad_option=n if [[ ${option_group:${#option_group}-1} != "=" ]] then #not an argument - [[ -n "${option_argument}" ]] && echo "option '--${option%%=*}' do not accept an argument " >&2 && $___exit 1 + [[ -n "${option_argument}" ]] && echo "option '--${option%%=*}' do not accept an argument " >&2 && return 1 eval option_${_name}='"${option_'${_name}'}-"' elif [[ -n "${option_argument}" ]] then @@ -306,7 +304,7 @@ function _get_opts() fi done done - [[ $bad_option == y ]] && echo "invalid argument '-$option'? Type -h for help" >&2 && $___exit 1 + [[ $bad_option == y ]] && echo "invalid argument '-$option'? Type -h for help" >&2 && return 1 elif [[ ${argument:0:2} == "--" ]] then option__="$*" @@ -320,7 +318,7 @@ function _get_opts() break fi done - [[ $bad_option == y ]] && echo "invalid argument '--'? Type -h for help" >&2 && $___exit 1 + [[ $bad_option == y ]] && echo "invalid argument '--'? Type -h for help" >&2 && return 1 break else params="$params ${argument}" @@ -328,22 +326,23 @@ function _get_opts() done - [[ -n "$get_argument" ]] && echo "option '-$option' requires an argument" >&2 && $___exit 1 - $___exit 0 - + [[ -n "$get_argument" ]] && echo "option '-$option' requires an argument" >&2 && return 1 + return 0 } -#check root privileges and non a root user behind -[ "${USER}" != "root" ] && echo "Needed root privileges" && _usage && exit -1 - #process options DIRNAME=$(readlink -f ${BASH_SOURCE[0]}) DIRNAME=$(dirname $DIRNAME) #source ${DIRNAME}/get-options.sh "help:h user:u= ip:i= cores:c= huge-pages-1G:hp= nb-10GB-interfaces:ni=" $* -_get_opts "help:h user:u= ip:i= cores:c= huge-pages-1G:hp= nb-10GB-interfaces:ni=" $* +_get_opts "help:h user-name:u= ip:i= cores:c= huge-pages-1G:hp= nb-10GB-interfaces:ni=" $* || exit 1 _parse_opts +#check root privileges +[ "${USER}" != "root" ] && echo "Needed root privileges" >&2 && exit 2 +#check root privileges and non a root user behind + + HOST_NAME=`cat /etc/hostname` _generate_compute_develope_yaml -- 2.17.1