#!/bin/bash

# Copyright 2014 Intel Corporation, All Rights Reserved.

# Licensed under the Apache License, Version 2.0 (the"License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

#  http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

set -e
set -o xtrace

#TOPDIR=$(cd $(dirname "$0") && pwd)
TOPDIR=/etc/vsm/prepools/

#------------------------------------------
# check parameters
#------------------------------------------

if [[ $1 == "cinder" ]]; then
    if [[ $# -lt 6 ]]; then
        echo "The number of parameters can't less than 6."
        echo "Usage: sudo presentpool <type> <ssh_user> <uuid> \
<volume_host> <os_controller_host> <pool_name,pool_type>*n"
        exit 0
    fi
elif [[ $1 == "nova" ]]; then
    if [[ $# -lt 5 ]]; then
        echo "The number of parameters can't less than 5."
        echo "Usage: sudo presentpool <type> <ssh_user> <uuid> \
<compute_host> <os_controller_host>"
        exit 0
    fi
elif [[ $1 == "glance" ]]; then
    if [[ $# -lt 6 ]]; then
        echo "The number of parameters can't less than 4."
        echo "Usage: sudo presentpool <type> <ssh_user> <uuid> \
<glance_host> <os_controller_host> <pool_name>"
        exit 0
    fi
else
    echo "The first parameter should be cinder, nova or glance."
    exit 0
fi

#------------------------------------------
# Usage: present pools for cinder
#------------------------------------------

if [[ $1 == "cinder" ]]; then
    source $TOPDIR/server/presentpool-cinder
    setup_cinder $@
    exit 0
fi

#------------------------------------------
# Usage: present pools for nova
#------------------------------------------

if [[ $1 == "nova" ]]; then
    source $TOPDIR/server/presentpool-nova
    setup_nova $@
    exit 0
fi

#------------------------------------------
# Usage: present pools for glance
#------------------------------------------

if [[ $1 == "glance" ]]; then
    source $TOPDIR/server/presentpool-glance
    setup_glance $@
    exit 0
fi

set +o xtrace
