[Ovirt-devel] [PATCH] Static IPv4 addresses entered are validated when they're entered.
Joey Boggs
jboggs at redhat.com
Mon Dec 7 23:10:18 UTC 2009
On 12/07/2009 05:12 PM, Darryl L. Pierce wrote:
> If the address is not blank then it is validated. Only those that are
> properly formed are accepted. Otherwise an error message is displayed
> and the user is prompted again.
>
> Resolves: rhbz#536912 - validation for static IP should be optimized
>
> Signed-off-by: Darryl L. Pierce<dpierce at redhat.com>
> ---
> scripts/ovirt-config-networking | 28 +++++++++++++++++++++++++---
> 1 files changed, 25 insertions(+), 3 deletions(-)
>
> diff --git a/scripts/ovirt-config-networking b/scripts/ovirt-config-networking
> index f9c6a4c..ec154c2 100755
> --- a/scripts/ovirt-config-networking
> +++ b/scripts/ovirt-config-networking
> @@ -30,6 +30,28 @@ if ! is_local_storage_configured; then
> exit 99
> fi
>
> +# $1 - the variable name to set
> +# $2 - the input prompt
> +function input_ipv4_address {
> + local varname=$1
> + local prompt=$2
> +
> + eval $varname=\"\"
> +
> + while true; do
> + read -ep "${prompt}: "
> +
> + if [ -z "$REPLY" ]; then return; fi
> +
> + if is_valid_ipv4 $REPLY; then
> + eval $varname=\"$REPLY\"
> + return
> + else
> + printf "\nThe address $REPLY is not a valid IPv4 address.\n"
> + fi
> + done
> +}
> +
> # Checks that a network interface was already configured.
> function has_configured_interface
> {
> @@ -169,9 +191,9 @@ function configure_interface
> ;;
> S|s)
> printf "\n"
> - read -ep "IP Address: "; IPADDR=$REPLY
> - read -ep " Netmask: "; NETMASK=$REPLY
> - read -ep " Gateway: "; GATEWAY=$REPLY
> + input_ipv4_address IPADDR "IP Address"
> + input_ipv4_address NETMASK " Netmask"
> + input_ipv4_address GATEWAY " Gateway"
>
> BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/BOOTPROTO none"
> BR_CONFIG="$BR_CONFIG\nset $BR_ROOT/IPADDR $IPADDR"
>
ACK
More information about the ovirt-devel
mailing list