X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=lib%2Fcommon-functions.sh;h=af9b71038cc43639344ceadfd577c5ae02f1796b;hb=78e41283e118e234c8559e8386abaeb19ac30480;hp=1e55aa18dffa0c9cec75e7cdc15d84d5bee436ae;hpb=2a937932642f3e8288d338c6fa4a2b6a7a5defc2;p=apex.git diff --git a/lib/common-functions.sh b/lib/common-functions.sh index 1e55aa18..af9b7103 100644 --- a/lib/common-functions.sh +++ b/lib/common-functions.sh @@ -2,6 +2,15 @@ # Common Functions used by OPNFV Apex # author: Tim Rozet (trozet@redhat.com) +##converts subnet mask to prefix +##params: subnet mask +function prefix2mask { + # Number of args to shift, 255..255, first non-255 byte, zeroes + set -- $(( 5 - ($1 / 8) )) 255 255 255 255 $(( (255 << (8 - ($1 % 8))) & 255 )) 0 0 0 + [ $1 -gt 1 ] && shift $1 || shift + echo ${1-0}.${2-0}.${3-0}.${4-0} +} + ##find ip of interface ##params: interface name function find_ip { @@ -203,7 +212,7 @@ function find_usable_ip_range { } ##generates usable IP range in correct format based on CIDR -##assumes the first 20 IPs are used (by instack or otherwise) +##assumes the first 20 IPs are used (by undercloud or otherwise) ##params: cidr function generate_usable_ip_range { local first_ip first_block_ip last_block_ip @@ -222,7 +231,7 @@ function generate_usable_ip_range { fi } -##find the instack IP address +##find the undercloud IP address ##finds first usable IP on subnet ##params: interface function find_provisioner_ip { @@ -237,7 +246,7 @@ function find_provisioner_ip { echo $(increment_ip ${interface_ip} 1) } -##generates instack IP address based on CIDR +##generates undercloud IP address based on CIDR ##params: cidr function generate_provisioner_ip { local provisioner_ip @@ -356,7 +365,7 @@ function generate_floating_ip_range { ##public indicates attaching to a public interface function attach_interface_to_ovs { local bridge interface - local if_ip if_mask if_gw if_file ovs_file + local if_ip if_mask if_gw if_file ovs_file if_prefix if [[ -z "$1" || -z "$2" ]]; then return 1 @@ -381,8 +390,14 @@ function attach_interface_to_ovs { return 1 fi + if [ -z "$if_mask" ]; then + # we can look for PREFIX here, then convert it to NETMASK + if_prefix=$(sed -n 's/^PREFIX=\(.*\)$/\1/p' ${if_file}) + if_mask=$(prefix2mask ${if_prefix}) + fi + if [[ -z "$if_ip" || -z "$if_mask" ]]; then - echo "ERROR: IPADDR or NETMASK missing for ${interface}" + echo "ERROR: IPADDR or NETMASK/PREFIX missing for ${interface}" return 1 elif [[ -z "$if_gw" && "$3" == "public_network" ]]; then echo "ERROR: GATEWAY missing for ${interface}, which is public" @@ -436,7 +451,7 @@ function detach_interface_from_ovs { local bridge local port_output ports_no_orig local net_path - local if_ip if_mask if_gw + local if_ip if_mask if_gw if_prefix net_path=/etc/sysconfig/network-scripts/ if [[ -z "$1" ]]; then @@ -462,8 +477,13 @@ function detach_interface_from_ovs { if_mask=$(sed -n 's/^NETMASK=\(.*\)$/\1/p' ${if_file}) if_gw=$(sed -n 's/^GATEWAY=\(.*\)$/\1/p' ${if_file}) + if [ -z "$if_mask" ]; then + if_prefix=$(sed -n 's/^PREFIX=\(.*\)$/\1/p' ${if_file}) + if_mask=$(prefix2mask ${if_prefix}) + fi + if [[ -z "$if_ip" || -z "$if_mask" ]]; then - echo "ERROR: IPADDR or NETMASK missing for ${bridge} and no .orig file for interface ${line}" + echo "ERROR: IPADDR or PREFIX/NETMASK missing for ${bridge} and no .orig file for interface ${line}" return 1 fi @@ -524,3 +544,19 @@ iptables -A FORWARD -s ${external_cidr} -m state --state ESTABLISHED,RELATED -j service iptables save EOI } + +# Interactive prompt handler +# params: step stage, ex. deploy, undercloud install, etc +function prompt_user { + while [ 1 ]; do + echo -n "Would you like to proceed with ${1}? (y/n) " + read response + if [ "$response" == 'y' ]; then + return 0 + elif [ "$response" == 'n' ]; then + return 1 + else + continue + fi + done +}