[Ovirt-devel] [PATCH]: Rewrite the ovirt-identify-node in bash

Perry N. Myers pmyers at redhat.com
Wed Jun 11 14:17:40 UTC 2008


Chris Lalancette wrote:
> All,
>      Attached is a patch to rewrite the ovirt-identify-node script in bash.
> Note that this is a drop-in replacement for the current python script; in
> particular, it doesn't do any restructuring like Darryl's new code is going to
> do.  However, given that we need to get rid of python because of my last patch,
> I think this is a fine interim step.  Note that this patch must be applied on
> top of the previous "Shrink Ovirt Node" patch to apply cleanly.
> 
> Signed-off-by: Chris Lalancette <clalance at redhat.com>

Some minor comments below.

> --- a/ovirt-host-creator/common-post.ks	2008-06-11 12:12:03.000000000 +0000
> +++ b/ovirt-host-creator/common-post.ks	2008-06-11 12:12:35.000000000 +0000
> @@ -14,10 +14,10 @@ EOF
[snip]
> +echo_error() {
> +	echo "$@" > /dev/stderr
> +}

I'm a big fan of consistency... In create-wui-appliance and 
ovirt-wui-install we've gone with some of Jim's structure using functions 
like warn, try_h and die.  We should probably do the same here.

> -EOF
> +usage() {
> +	echo_error "Usage: ovirt-identify-node -s <server> -p <port>"
> +	exit 1
> +}

Same thing for the usage function as above.

> -chmod +x /sbin/ovirt-identify-node
> +send_key_value() {
> +	echo "$1=$2" 1>&3
> +
> +	read 0<&3
> +	if [ "$REPLY" != "ACK $1" ]; then
> +		echo_error "Failed acknowledge of key $1"
> +		exit 4
> +	fi
> +}
> +
> +############# MAIN ##################
> +
> +# parse our options
> +while getopts ":s:p:" flag ; do
> +	case "$flag" in
> +		s)
> +			server=$OPTARG
> +			;;
> +		p)
> +			port=$OPTARG
> +			;;
> +		?)
> +			usage
> +			;;
> +	esac
> +done
> +
> +if [ $(( $# - $OPTIND )) -ge 0 ]; then
> +	usage
> +fi
>  
> +if [ -z "$server" -o -z "$port" ]; then
> +	usage
> +fi

Could use one liners with test here instead of if statements.

> +# gather our information
> +uuid=`hostname -f`
> +arch=`uname -i`
> +memsize=$(( `getconf _PHYS_PAGES` * `getconf PAGESIZE` / 1024 / 1024 ))
> +numcpus=`getconf _NPROCESSORS_ONLN`
> +speed=`grep "cpu MHz" /proc/cpuinfo | uniq | cut -d':' -f2 | sed -e 's/^[[:space:]]*\(.*\)$/\1/' -e 's/^\(.*\)[[:space:]]*$/\1/'`
> +hostname=`hostname -f`
> +hypervisor="QEMU"

For bundled installs this won't be true, since those will have KVM 
hypervisors.  Can we look at cpuflags to figure out whether to put QEMU or 
KVM here?

> +# FIXME: check that the above values are sane
> +
> +# open our connection to the remote host
> +# FIXME: this is ugly if it fails; redirecting to stderr doesn't seem to work,
> +# probably because of exec
> +exec 3<> /dev/tcp/$server/$port
> +if [ $? -ne 0 ]; then
> +	echo_error "Connection to $server:$port failed"
> +	exit 5
> +fi
> +
> +# say hello
> +read 0<&3
> +if [ "$REPLY" != "HELLO?" ]; then
> +	echo_error "Expected response HELLO?, received response $REPLY"
> +	exit 2
> +fi
> +echo "HELLO!" 1>&3
> +
> +# OK, start sending our information
> +read 0<&3
> +if [ "$REPLY" != "INFO?" ]; then
> +	echo_error "Expected response INFO?, received response $REPLY"
> +	exit 3
> +fi
> +
> +send_key_value "UUID" "$uuid"
> +send_key_value "ARCH" "$arch"
> +send_key_value "MEMSIZE" "$memsize"
> +send_key_value "NUMCPUS" "$numcpus"
> +send_key_value "CPUSPEED" "$speed"
> +send_key_value "HOSTNAME" "$hostname"
> +send_key_value "HYPERVISOR_TYPE" "$hypervisor"
> +
> +echo "ENDINFO" 1>&3
> +
> +read 0<&3
> +
> +if [ "${REPLY:0:4}" != "KTAB" ]; then
> +	echo_error "Expected response KTAB <filename>, received response $REPLY"
> +	exit 6
> +fi
> +echo "${REPLY:5}"
> +EOF
> +chmod +x /sbin/ovirt-identify-node
>  
>  echo "Writing ovirt-functions script"
>  # common functions





More information about the ovirt-devel mailing list