1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-28 07:21:29 +03:00

feature #1112: Small modifications in DS/TM scripts:

* The DS directory is created specifically by each action only when needed
* ssh_exec_and_log and ssh_make_path move to scripts_common.sh
* Round the size up
* drop unused remote2local_path function
This commit is contained in:
Jaime Melis 2012-03-07 12:41:35 +01:00
parent ea089f0626
commit 89a0a475c9
7 changed files with 51 additions and 71 deletions

View File

@ -57,6 +57,7 @@ SAFE_DIRS="${XPATH_ELEMENTS[2]}"
UMASK="${XPATH_ELEMENTS[3]}"
SRC="${XPATH_ELEMENTS[4]}"
mkdir -p "$BASE_PATH"
set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS" "$UMASK"
DST=`generate_image_path`

View File

@ -49,7 +49,6 @@ done < <($XPATH /DS_DRIVER_ACTION_DATA/DATASTORE/BASE_PATH \
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/RESTRICTED_DIRS \
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/SAFE_DIRS \
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/UMASK \
/DS_DRIVER_ACTION_DATA/IMAGE/PATH \
/DS_DRIVER_ACTION_DATA/IMAGE/FSTYPE \
/DS_DRIVER_ACTION_DATA/IMAGE/SIZE)
@ -58,10 +57,10 @@ BASE_PATH="${XPATH_ELEMENTS[0]}"
RESTRICTED_DIRS="${XPATH_ELEMENTS[1]}"
SAFE_DIRS="${XPATH_ELEMENTS[2]}"
UMASK="${XPATH_ELEMENTS[3]}"
SRC="${XPATH_ELEMENTS[4]}"
FSTYPE="${XPATH_ELEMENTS[5]}"
SIZE="${XPATH_ELEMENTS[6]}"
FSTYPE="${XPATH_ELEMENTS[4]}"
SIZE="${XPATH_ELEMENTS[5]}"
mkdir -p "$BASE_PATH"
set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS" "$UMASK"
DST=`generate_image_path`
@ -82,7 +81,4 @@ exec_and_log "$DD if=/dev/zero of=$DST bs=1 count=1 seek=${SIZE}M" \
exec_and_log "$MKFS_CMD" \
"Unable to create filesystem $FSTYPE in $DST"
# ---------------- Get the size of the image ------------
SIZE=`fs_du $DST`
echo "$DST $SIZE"

View File

@ -53,8 +53,6 @@ function set_up_datastore {
export RESTRICTED_DIRS
export SAFE_DIRS
mkdir -p $BASE_PATH
if [ -n "$UMASK" ]; then
umask $UMASK
else
@ -94,7 +92,7 @@ function fs_du {
if [ $error -ne 0 ]; then
SIZE=0
else
SIZE=$(($SIZE/1048576))
SIZE=$((($SIZE+1048575)/1048576))
fi
echo "$SIZE"
@ -111,7 +109,7 @@ function qemu_size {
SIZE=`$QEMU_IMG info $DISK|grep "^virtual size:"|\
sed 's/^.*(\([0-9]\+\) bytes.*$/\1/g'`
SIZE=$(($SIZE/1048576))
SIZE=$((($SIZE+1048575)/1048576))
echo "$SIZE"
}

View File

@ -57,6 +57,7 @@ SAFE_DIRS="${XPATH_ELEMENTS[2]}"
UMASK="${XPATH_ELEMENTS[3]}"
SRC="${XPATH_ELEMENTS[4]}"
mkdir -p "$BASE_PATH"
set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS" "$UMASK"
DST=`generate_image_path`

View File

@ -49,7 +49,6 @@ done < <($XPATH /DS_DRIVER_ACTION_DATA/DATASTORE/BASE_PATH \
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/RESTRICTED_DIRS \
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/SAFE_DIRS \
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/UMASK \
/DS_DRIVER_ACTION_DATA/IMAGE/PATH \
/DS_DRIVER_ACTION_DATA/IMAGE/FSTYPE \
/DS_DRIVER_ACTION_DATA/IMAGE/SIZE)
@ -57,10 +56,10 @@ BASE_PATH="${XPATH_ELEMENTS[0]}"
RESTRICTED_DIRS="${XPATH_ELEMENTS[1]}"
SAFE_DIRS="${XPATH_ELEMENTS[2]}"
UMASK="${XPATH_ELEMENTS[3]}"
SRC="${XPATH_ELEMENTS[4]}"
FSTYPE="${XPATH_ELEMENTS[5]}"
SIZE="${XPATH_ELEMENTS[6]}"
FSTYPE="${XPATH_ELEMENTS[4]}"
SIZE="${XPATH_ELEMENTS[5]}"
mkdir -p "$BASE_PATH"
set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS" "$UMASK"
DST=`generate_image_path`

View File

@ -115,7 +115,7 @@ function error_message
function exec_and_log
{
message=$2
EXEC_LOG_ERR=`$1 2>&1 1>/dev/null`
EXEC_LOG_RC=$?
@ -192,7 +192,7 @@ function mkfs_command {
;;
"raw")
echo ""
return 0
return 0
;;
"swap")
echo "$MKSWAP $DST"
@ -205,3 +205,41 @@ function mkfs_command {
echo "$MKFS -t $FSTYPE $OPTS $DST"
}
#This function executes $2 at $1 host and report error $3
function ssh_exec_and_log
{
SSH_EXEC_ERR=`$SSH $1 bash -s 2>&1 1>/dev/null <<EOF
$2
EOF`
SSH_EXEC_RC=$?
if [ $SSH_EXEC_RC -ne 0 ]; then
log_error "Command \"$2\" failed: $SSH_EXEC_ERR"
if [ -n "$3" ]; then
error_message "$3"
else
error_message "Error executing $2: $SSH_EXEC_ERR"
fi
exit $SSH_EXEC_RC
fi
}
#Creates path ($2) at $1
function ssh_make_path
{
SSH_EXEC_ERR=`$SSH $1 bash -s 2>&1 1>/dev/null <<EOF
if [ ! -d $2 ]; then
mkdir -p $2
fi
EOF`
SSH_EXEC_RC=$?
if [ $? -ne 0 ]; then
error_message "Error creating directory $2 at $1: $SSH_EXEC_ERR"
exit $SSH_EXEC_RC
fi
}

View File

@ -62,7 +62,7 @@ function set_ds_location
#Return 1 if the first argument is a disk
function is_disk
{
echo "$1" | $GREP '/disk\.[0-9]\+' > /dev/null 2>&1
echo "$1" | $GREP '/disk\.[0-9]\+' > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "1"
@ -70,56 +70,3 @@ function is_disk
echo "0"
fi
}
# ------------------------------------------------------------------------------
# Function to get hosts and paths from arguments
# ------------------------------------------------------------------------------
#This function executes $2 at $1 host and report error $3
function ssh_exec_and_log
{
SSH_EXEC_ERR=`$SSH $1 bash -s 2>&1 1>/dev/null <<EOF
$2
EOF`
SSH_EXEC_RC=$?
if [ $SSH_EXEC_RC -ne 0 ]; then
log_error "Command \"$2\" failed: $SSH_EXEC_ERR"
if [ -n "$3" ]; then
error_message "$3"
else
error_message "Error executing $2: $SSH_EXEC_ERR"
fi
exit $SSH_EXEC_RC
fi
}
#Creates path ($2) at $1
function ssh_make_path
{
SSH_EXEC_ERR=`$SSH $1 bash -s 2>&1 1>/dev/null <<EOF
if [ ! -d $2 ]; then
mkdir -p $2
fi
EOF`
SSH_EXEC_RC=$?
if [ $? -ne 0 ]; then
error_message "Error creating directory $2 at $1: $SSH_EXEC_ERR"
exit $SSH_EXEC_RC
fi
}
#Transform a system data store path from its remote location to the local one
#$1 remote path
function remote2local_path
{
if [ -z "$RMT_DS_DIR" ]; then
set_ds_location
fi
echo "$ONE_LOCAL_VAR/datastores/${1##"$RMT_DS_DIR/"}"
}