#!/bin/bash

# -------------------------------------------------------------------------- #
# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org)             #
#                                                                            #
# 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.                                             #
#--------------------------------------------------------------------------- #

#------------------------------------------------------------------------------
# Configuration File for File-System based Image Repositories
#------------------------------------------------------------------------------
if [ -z "${ONE_LOCATION}" ]; then
    export IMAGE_REPOSITORY_PATH=/var/lib/one/images
else
    export IMAGE_REPOSITORY_PATH=$ONE_LOCATION/var/images
fi

#------------------------------------------------------------------------------
# Function used to generate Image names, you should not need to override this
#------------------------------------------------------------------------------
function generate_image_path {

CANONICAL_STR="`$DATE +%s`:$ID"

CANONICAL_MD5=$($MD5SUM - << EOF
$CANONICAL_STR
EOF
)

echo "$IMAGE_REPOSITORY_PATH/`echo $CANONICAL_MD5 | cut -d ' ' -f1`"
}

function fs_du {

SIZE=`$DU -m $1 2>/dev/null`

if [ $? -ne 0 ]; then
    SIZE=0
else
    SIZE=`echo $SIZE | cut -f1 -d' '`
fi

echo "$SIZE"
}
