#!/bin/bash
#
# Copyright (c) 2015 Mirantis Inc.
#
# 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.

export NETWORK=${1:-neutron}
export ENGINE=${2:-heat}

# Normalize network name
if [[ $NETWORK == nova* ]]; then
    export NETWORK="nova-network"
fi

source settings

export DEST=${DEST:-$BASE/new}
export DEVSTACK_DIR=${DEVSTACK_DIR:-$DEST/devstack}
export SAHARA_DIR=${SAHARA_DIR:-$DEST/sahara}
export SAHARA_TESTS_DIR=${SAHARA_TESTS_DIR:-$DEST/sahara-scenario}


export LOCALRC_PATH=$DEVSTACK_DIR/localrc
export LOCALCONF_PATH=$DEVSTACK_DIR/local.conf

function sahara_register_fake_plugin_image {
    local props="--public"
    props+=" --property _sahara_tag_0.1=True"
    props+=" --property _sahara_tag_fake=True"
    props+=" --property _sahara_username=$SAHARA_FAKE_PLUGIN_IMAGE_USERNAME"

    openstack --os-url $GLANCE_SERVICE_PROTOCOL://$GLANCE_HOSTPORT --os-image-api-version 1 image set \
        $SAHARA_FAKE_PLUGIN_IMAGE_NAME $props
}

function sahara_register_flavor {
    nova flavor-create $SAHARA_FLAVOR_NAME $SAHARA_FLAVOR_ID $SAHARA_FLAVOR_RAM \
        $SAHARA_FLAVOR_DISK $SAHARA_FLAVOR_VCPUS
}
