#!/bin/bash

ETHERNET=$1
DEVICE=$2

if [ ! -b $DEVICE ]; then
    echo "$DEVICE is not a block device, goodbye!"
    exit 1
fi

AOE_LIST=`/usr/sbin/vblade-persist ls --no-header`

for shelf in `seq 0 2048`; do
    for slot in `seq 0 15`; do
	if [ `echo "$AOE_LIST" | grep "$shelf $slot $ETHERNET" | wc -l` == 0 ]; then
	    break 2
	fi
    done
done

/usr/sbin/vblade-persist setup $shelf $slot $ETHERNET $DEVICE > /dev/null
/usr/sbin/vblade-persist auto $shelf $slot
/usr/sbin/vblade-persist start $shelf $slot > /dev/null

echo e$shelf.$slot
