datastore.sheepdog.patch
| /var/lib/one/remotes/datastore/sheepdog/clone 2014-05-25 19:18:00.946579548 +0200 | ||
|---|---|---|
| 1 |
#!/bin/bash |
|
| 2 | ||
| 3 |
# -------------------------------------------------------------------------- # |
|
| 4 |
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs # |
|
| 5 |
# # |
|
| 6 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may # |
|
| 7 |
# not use this file except in compliance with the License. You may obtain # |
|
| 8 |
# a copy of the License at # |
|
| 9 |
# # |
|
| 10 |
# http://www.apache.org/licenses/LICENSE-2.0 # |
|
| 11 |
# # |
|
| 12 |
# Unless required by applicable law or agreed to in writing, software # |
|
| 13 |
# distributed under the License is distributed on an "AS IS" BASIS, # |
|
| 14 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # |
|
| 15 |
# See the License for the specific language governing permissions and # |
|
| 16 |
# limitations under the License. # |
|
| 17 |
#--------------------------------------------------------------------------- # |
|
| 18 | ||
| 19 |
############################################################################### |
|
| 20 |
# This script is used to copy a VM image (SRC) to the image repository as DST |
|
| 21 |
# Several SRC types are supported |
|
| 22 |
############################################################################### |
|
| 23 |
# -------- Set up the environment to source common tools & conf ------------ |
|
| 24 |
if [ -z "${ONE_LOCATION}" ]; then
|
|
| 25 |
LIB_LOCATION=/usr/lib/one |
|
| 26 |
else |
|
| 27 |
LIB_LOCATION=$ONE_LOCATION/lib |
|
| 28 |
fi |
|
| 29 | ||
| 30 |
. $LIB_LOCATION/sh/scripts_common.sh |
|
| 31 | ||
| 32 |
DRIVER_PATH=$(dirname $0) |
|
| 33 |
source ${DRIVER_PATH}/../libfs.sh
|
|
| 34 |
source ${DRIVER_PATH}/sheepdog.conf
|
|
| 35 | ||
| 36 |
# -------- Get cp and datastore arguments from OpenNebula core ------------ |
|
| 37 | ||
| 38 |
DRV_ACTION=$1 |
|
| 39 |
ID=$2 |
|
| 40 | ||
| 41 |
XPATH="${DRIVER_PATH}/../xpath.rb -b $DRV_ACTION"
|
|
| 42 | ||
| 43 |
unset i XPATH_ELEMENTS |
|
| 44 | ||
| 45 |
while IFS= read -r -d '' element; do |
|
| 46 |
XPATH_ELEMENTS[i++]="$element" |
|
| 47 |
done < <($XPATH /DS_DRIVER_ACTION_DATA/DATASTORE/BASE_PATH \ |
|
| 48 |
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/BRIDGE_LIST \ |
|
| 49 |
/DS_DRIVER_ACTION_DATA/IMAGE/PATH \ |
|
| 50 |
/DS_DRIVER_ACTION_DATA/IMAGE/SIZE) |
|
| 51 | ||
| 52 |
unset i |
|
| 53 | ||
| 54 |
BASE_PATH="${XPATH_ELEMENTS[i++]}"
|
|
| 55 |
BRIDGE_LIST="${XPATH_ELEMENTS[i++]}"
|
|
| 56 |
SRC="${XPATH_ELEMENTS[i++]}"
|
|
| 57 |
SIZE="${XPATH_ELEMENTS[i++]}"
|
|
| 58 | ||
| 59 |
DST_HOST=`get_destination_host $ID` |
|
| 60 | ||
| 61 |
if [ -z "$DST_HOST" ]; then |
|
| 62 |
error_message "Datastore template missing 'BRIDGE_LIST' attribute." |
|
| 63 |
exit -1 |
|
| 64 |
fi |
|
| 65 | ||
| 66 |
SAFE_DIRS="" |
|
| 67 | ||
| 68 |
IMAGE_NAME="one-${ID}"
|
|
| 69 |
SHEEPDOG_DST="${IMAGE_NAME}"
|
|
| 70 | ||
| 71 |
ssh_exec_and_log "$DST_HOST" "$QEMU_IMG snapshot -c source_snap_$ID sheepdog:$SRC && $QEMU_IMG create -b sheepdog:$SRC:source_snap_$ID sheepdog:$SHEEPDOG_DST && $DOG vdi delete -s source_snap_$ID $SRC" \ |
|
| 72 |
"Error cloning $SRC to $SHEEPDOG_DST in $DST_HOST" |
|
| 73 | ||
| 74 |
echo "$SHEEPDOG_DST" |
|
| /var/lib/one/remotes/datastore/sheepdog/cp 2014-05-25 19:24:49.366579548 +0200 | ||
|---|---|---|
| 1 |
#!/bin/bash |
|
| 2 | ||
| 3 |
# -------------------------------------------------------------------------- # |
|
| 4 |
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs # |
|
| 5 |
# # |
|
| 6 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may # |
|
| 7 |
# not use this file except in compliance with the License. You may obtain # |
|
| 8 |
# a copy of the License at # |
|
| 9 |
# # |
|
| 10 |
# http://www.apache.org/licenses/LICENSE-2.0 # |
|
| 11 |
# # |
|
| 12 |
# Unless required by applicable law or agreed to in writing, software # |
|
| 13 |
# distributed under the License is distributed on an "AS IS" BASIS, # |
|
| 14 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # |
|
| 15 |
# See the License for the specific language governing permissions and # |
|
| 16 |
# limitations under the License. # |
|
| 17 |
#--------------------------------------------------------------------------- # |
|
| 18 | ||
| 19 |
############################################################################### |
|
| 20 |
# This script is used to copy a VM image (SRC) to the image repository as DST |
|
| 21 |
# Several SRC types are supported |
|
| 22 |
############################################################################### |
|
| 23 | ||
| 24 |
# -------- Set up the environment to source common tools & conf ------------ |
|
| 25 | ||
| 26 |
if [ -z "${ONE_LOCATION}" ]; then
|
|
| 27 |
LIB_LOCATION=/usr/lib/one |
|
| 28 |
else |
|
| 29 |
LIB_LOCATION=$ONE_LOCATION/lib |
|
| 30 |
fi |
|
| 31 | ||
| 32 |
. $LIB_LOCATION/sh/scripts_common.sh |
|
| 33 | ||
| 34 |
DRIVER_PATH=$(dirname $0) |
|
| 35 |
source ${DRIVER_PATH}/../libfs.sh
|
|
| 36 |
source ${DRIVER_PATH}/sheepdog.conf
|
|
| 37 | ||
| 38 |
# -------- Get cp and datastore arguments from OpenNebula core ------------ |
|
| 39 | ||
| 40 |
DRV_ACTION=$1 |
|
| 41 |
ID=$2 |
|
| 42 | ||
| 43 |
UTILS_PATH="${DRIVER_PATH}/.."
|
|
| 44 | ||
| 45 |
XPATH="$UTILS_PATH/xpath.rb -b $DRV_ACTION" |
|
| 46 | ||
| 47 |
unset i XPATH_ELEMENTS |
|
| 48 | ||
| 49 |
while IFS= read -r -d '' element; do |
|
| 50 |
XPATH_ELEMENTS[i++]="$element" |
|
| 51 |
done < <($XPATH /DS_DRIVER_ACTION_DATA/DATASTORE/BASE_PATH \ |
|
| 52 |
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/RESTRICTED_DIRS \ |
|
| 53 |
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/SAFE_DIRS \ |
|
| 54 |
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/BRIDGE_LIST \ |
|
| 55 |
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/POOL_NAME \ |
|
| 56 |
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/STAGING_DIR \ |
|
| 57 |
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/SHEEPDOG_FORMAT \ |
|
| 58 |
/DS_DRIVER_ACTION_DATA/IMAGE/PATH \ |
|
| 59 |
/DS_DRIVER_ACTION_DATA/IMAGE/SIZE \ |
|
| 60 |
/DS_DRIVER_ACTION_DATA/IMAGE/TEMPLATE/MD5 \ |
|
| 61 |
/DS_DRIVER_ACTION_DATA/IMAGE/TEMPLATE/SHA1 \ |
|
| 62 |
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/NO_DECOMPRESS \ |
|
| 63 |
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/LIMIT_TRANSFER_BW) |
|
| 64 | ||
| 65 |
unset i |
|
| 66 | ||
| 67 |
BASE_PATH="${XPATH_ELEMENTS[i++]}"
|
|
| 68 |
RESTRICTED_DIRS="${XPATH_ELEMENTS[i++]}"
|
|
| 69 |
SAFE_DIRS="${XPATH_ELEMENTS[i++]}"
|
|
| 70 |
BRIDGE_LIST="${XPATH_ELEMENTS[i++]}"
|
|
| 71 |
POOL_NAME="${XPATH_ELEMENTS[i++]:-$POOL_NAME}"
|
|
| 72 |
STAGING_DIR="${XPATH_ELEMENTS[i++]:-$STAGING_DIR}"
|
|
| 73 |
SHEEPDOG_FORMAT="${XPATH_ELEMENTS[i++]:-$SHEEPDOG_FORMAT}"
|
|
| 74 |
SRC="${XPATH_ELEMENTS[i++]}"
|
|
| 75 |
SIZE="${XPATH_ELEMENTS[i++]}"
|
|
| 76 |
MD5="${XPATH_ELEMENTS[i++]}"
|
|
| 77 |
SHA1="${XPATH_ELEMENTS[i++]}"
|
|
| 78 |
NO_DECOMPRESS="${XPATH_ELEMENTS[i++]}"
|
|
| 79 |
LIMIT_TRANSFER_BW="${XPATH_ELEMENTS[i++]}"
|
|
| 80 | ||
| 81 |
DST_HOST=`get_destination_host $ID` |
|
| 82 | ||
| 83 |
if [ -z "$DST_HOST" ]; then |
|
| 84 |
error_message "Datastore template missing 'BRIDGE_LIST' attribute." |
|
| 85 |
exit -1 |
|
| 86 |
fi |
|
| 87 | ||
| 88 |
set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS" |
|
| 89 | ||
| 90 |
IMAGE_HASH=`generate_image_hash` |
|
| 91 |
TMP_DST="$STAGING_DIR/$IMAGE_HASH" |
|
| 92 | ||
| 93 |
IMAGE_NAME="one-${ID}"
|
|
| 94 |
SHEEPDOG_SOURCE="${IMAGE_NAME}"
|
|
| 95 | ||
| 96 |
DOWNLOADER_ARGS=`set_downloader_args "$MD5" "$SHA1" "$NO_DECOMPRESS" "$LIMIT_TRANSFER_BW" "$SRC" -` |
|
| 97 | ||
| 98 |
COPY_COMMAND="$UTILS_PATH/downloader.sh $DOWNLOADER_ARGS" |
|
| 99 | ||
| 100 |
case $SRC in |
|
| 101 |
http://*|https://*) |
|
| 102 |
log "Downloading $SRC to the image repository" |
|
| 103 | ||
| 104 |
DUMP="$COPY_COMMAND" |
|
| 105 |
;; |
|
| 106 | ||
| 107 |
*) |
|
| 108 |
if [ `check_restricted $SRC` -eq 1 ]; then |
|
| 109 |
log_error "Not allowed to copy images from $RESTRICTED_DIRS" |
|
| 110 |
error_message "Not allowed to copy image file $SRC" |
|
| 111 |
exit -1 |
|
| 112 |
fi |
|
| 113 | ||
| 114 |
log "Copying local image $SRC to the image repository" |
|
| 115 | ||
| 116 |
DUMP="$COPY_COMMAND" |
|
| 117 |
;; |
|
| 118 |
esac |
|
| 119 | ||
| 120 |
exec_and_log "eval $DUMP | $SSH $DST_HOST $DD of=$TMP_DST bs=64k" \ |
|
| 121 |
"Error dumping $SRC to $DST_HOST:$TMP_DST" |
|
| 122 | ||
| 123 |
REGISTER_CMD=$(cat <<EOF |
|
| 124 |
set -e |
|
| 125 | ||
| 126 |
if [ "$SHEEPDOG_FORMAT" = "raw" ]; then |
|
| 127 |
FORMAT=\$($QEMU_IMG info $TMP_DST | grep "^file format:" | awk '{print $3}')
|
|
| 128 | ||
| 129 |
if [ "\$FORMAT" != "raw" ]; then |
|
| 130 |
$QEMU_IMG convert -O raw $TMP_DST $TMP_DST.raw |
|
| 131 |
mv $TMP_DST.raw $TMP_DST |
|
| 132 |
fi |
|
| 133 |
fi |
|
| 134 |
$QEMU_IMG convert -t directsync $QEMU_IMG_CONVERT_ARGS $TMP_DST sheepdog:$SHEEPDOG_SOURCE |
|
| 135 | ||
| 136 |
# remove original |
|
| 137 |
$RM -f $TMP_DST |
|
| 138 |
EOF |
|
| 139 |
) |
|
| 140 | ||
| 141 |
ssh_exec_and_log "$DST_HOST" "$REGISTER_CMD" \ |
|
| 142 |
"Error registering $SHEEPDOG_SOURCE in $DST_HOST" |
|
| 143 | ||
| 144 |
echo "$SHEEPDOG_SOURCE" |
|
| /var/lib/one/remotes/datastore/sheepdog/mkfs 2014-05-25 19:30:30.654579548 +0200 | ||
|---|---|---|
| 1 |
#!/bin/bash |
|
| 2 | ||
| 3 |
# -------------------------------------------------------------------------- # |
|
| 4 |
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs # |
|
| 5 |
# # |
|
| 6 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may # |
|
| 7 |
# not use this file except in compliance with the License. You may obtain # |
|
| 8 |
# a copy of the License at # |
|
| 9 |
# # |
|
| 10 |
# http://www.apache.org/licenses/LICENSE-2.0 # |
|
| 11 |
# # |
|
| 12 |
# Unless required by applicable law or agreed to in writing, software # |
|
| 13 |
# distributed under the License is distributed on an "AS IS" BASIS, # |
|
| 14 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # |
|
| 15 |
# See the License for the specific language governing permissions and # |
|
| 16 |
# limitations under the License. # |
|
| 17 |
#--------------------------------------------------------------------------- # |
|
| 18 | ||
| 19 |
############################################################################### |
|
| 20 |
# This script is used to create a VM image (SRC) of size (SIZE) and formatted |
|
| 21 |
# as (FS) |
|
| 22 |
############################################################################### |
|
| 23 | ||
| 24 |
# -------- Set up the environment to source common tools & conf ------------ |
|
| 25 | ||
| 26 |
if [ -z "${ONE_LOCATION}" ]; then
|
|
| 27 |
LIB_LOCATION=/usr/lib/one |
|
| 28 |
else |
|
| 29 |
LIB_LOCATION=$ONE_LOCATION/lib |
|
| 30 |
fi |
|
| 31 | ||
| 32 |
. $LIB_LOCATION/sh/scripts_common.sh |
|
| 33 | ||
| 34 |
DRIVER_PATH=$(dirname $0) |
|
| 35 |
source ${DRIVER_PATH}/../libfs.sh
|
|
| 36 |
source ${DRIVER_PATH}/sheepdog.conf
|
|
| 37 | ||
| 38 |
# -------- Get mkfs and datastore arguments from OpenNebula core ------------ |
|
| 39 | ||
| 40 |
DRV_ACTION=$1 |
|
| 41 |
ID=$2 |
|
| 42 | ||
| 43 |
XPATH="${DRIVER_PATH}/../xpath.rb -b $DRV_ACTION"
|
|
| 44 | ||
| 45 |
unset i XPATH_ELEMENTS |
|
| 46 | ||
| 47 |
while IFS= read -r -d '' element; do |
|
| 48 |
XPATH_ELEMENTS[i++]="$element" |
|
| 49 |
done < <($XPATH /DS_DRIVER_ACTION_DATA/DATASTORE/BASE_PATH \ |
|
| 50 |
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/RESTRICTED_DIRS \ |
|
| 51 |
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/SAFE_DIRS \ |
|
| 52 |
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/BRIDGE_LIST \ |
|
| 53 |
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/POOL_NAME \ |
|
| 54 |
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/STAGING_DIR \ |
|
| 55 |
/DS_DRIVER_ACTION_DATA/IMAGE/FSTYPE \ |
|
| 56 |
/DS_DRIVER_ACTION_DATA/IMAGE/SIZE) |
|
| 57 | ||
| 58 |
unset i |
|
| 59 | ||
| 60 |
BASE_PATH="${XPATH_ELEMENTS[i++]}"
|
|
| 61 |
RESTRICTED_DIRS="${XPATH_ELEMENTS[i++]}"
|
|
| 62 |
SAFE_DIRS="${XPATH_ELEMENTS[i++]}"
|
|
| 63 |
BRIDGE_LIST="${XPATH_ELEMENTS[i++]}"
|
|
| 64 |
POOL_NAME="${XPATH_ELEMENTS[i++]:-$POOL_NAME}"
|
|
| 65 |
STAGING_DIR="${XPATH_ELEMENTS[i++]:-$STAGING_DIR}"
|
|
| 66 |
FSTYPE="${XPATH_ELEMENTS[i++]}"
|
|
| 67 |
SIZE="${XPATH_ELEMENTS[i++]}"
|
|
| 68 | ||
| 69 |
DST_HOST=`get_destination_host $ID` |
|
| 70 | ||
| 71 |
if [ -z "$DST_HOST" ]; then |
|
| 72 |
error_message "Datastore template missing 'BRIDGE_LIST' attribute." |
|
| 73 |
exit -1 |
|
| 74 |
fi |
|
| 75 | ||
| 76 |
set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS" |
|
| 77 | ||
| 78 |
IMAGE_HASH=`generate_image_hash` |
|
| 79 |
TMP_DST="$STAGING_DIR/$IMAGE_HASH" |
|
| 80 | ||
| 81 |
IMAGE_NAME="one-${ID}"
|
|
| 82 |
SHEEPDOG_SOURCE="${IMAGE_NAME}"
|
|
| 83 | ||
| 84 |
# ------------ Image to save_as disk, no need to create a FS ------------ |
|
| 85 | ||
| 86 |
if [ "$FSTYPE" = "save_as" ]; then |
|
| 87 |
echo "$SHEEPDOG_SOURCE" |
|
| 88 |
exit 0 |
|
| 89 |
fi |
|
| 90 | ||
| 91 |
# ------------ Create the image in the repository ------------ |
|
| 92 | ||
| 93 |
MKFS_CMD=`mkfs_command $TMP_DST $FSTYPE $SIZE` |
|
| 94 | ||
| 95 |
REGISTER_CMD=$(cat <<EOF |
|
| 96 |
set -e |
|
| 97 |
export PATH=/usr/sbin:/sbin:\$PATH |
|
| 98 |
if [ "$FSTYPE" = "raw" ]; then |
|
| 99 |
$QEMU_IMG create sheepdog:$SHEEPDOG_SOURCE ${SIZE}M
|
|
| 100 |
else |
|
| 101 |
# create and format |
|
| 102 |
$DD if=/dev/zero of=$TMP_DST bs=1 count=1 seek=${SIZE}M
|
|
| 103 |
$MKFS_CMD |
|
| 104 | ||
| 105 |
# create sheepdog |
|
| 106 |
$QEMU_IMG convert -t directsync $QEMU_IMG_CONVERT_ARGS $TMP_DST sheepdog:$SHEEPDOG_SOURCE |
|
| 107 | ||
| 108 |
# remove original |
|
| 109 |
$RM -f $TMP_DST |
|
| 110 |
fi |
|
| 111 | ||
| 112 | ||
| 113 |
EOF |
|
| 114 |
) |
|
| 115 | ||
| 116 |
ssh_exec_and_log "$DST_HOST" "$REGISTER_CMD" \ |
|
| 117 |
"Error registering $SHEEPDOG_SOURCE in $DST_HOST" |
|
| 118 | ||
| 119 |
echo "$SHEEPDOG_SOURCE" |
|
| /var/lib/one/remotes/datastore/sheepdog/monitor 2014-05-25 18:11:24.886579548 +0200 | ||
|---|---|---|
| 1 |
#!/bin/bash |
|
| 2 | ||
| 3 |
# -------------------------------------------------------------------------- # |
|
| 4 |
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs # |
|
| 5 |
# # |
|
| 6 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may # |
|
| 7 |
# not use this file except in compliance with the License. You may obtain # |
|
| 8 |
# a copy of the License at # |
|
| 9 |
# # |
|
| 10 |
# http://www.apache.org/licenses/LICENSE-2.0 # |
|
| 11 |
# # |
|
| 12 |
# Unless required by applicable law or agreed to in writing, software # |
|
| 13 |
# distributed under the License is distributed on an "AS IS" BASIS, # |
|
| 14 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # |
|
| 15 |
# See the License for the specific language governing permissions and # |
|
| 16 |
# limitations under the License. # |
|
| 17 |
#--------------------------------------------------------------------------- # |
|
| 18 | ||
| 19 |
############################################################################### |
|
| 20 |
# This script is used to monitor the free and used space of a datastore |
|
| 21 |
############################################################################### |
|
| 22 | ||
| 23 |
# -------- Set up the environment to source common tools & conf ------------ |
|
| 24 | ||
| 25 |
if [ -z "${ONE_LOCATION}" ]; then
|
|
| 26 |
LIB_LOCATION=/usr/lib/one |
|
| 27 |
else |
|
| 28 |
LIB_LOCATION=$ONE_LOCATION/lib |
|
| 29 |
fi |
|
| 30 | ||
| 31 |
. $LIB_LOCATION/sh/scripts_common.sh |
|
| 32 | ||
| 33 |
DRIVER_PATH=$(dirname $0) |
|
| 34 |
source ${DRIVER_PATH}/../libfs.sh
|
|
| 35 |
source ${DRIVER_PATH}/sheepdog.conf
|
|
| 36 | ||
| 37 |
# -------- Get datastore arguments from OpenNebula core ------------ |
|
| 38 | ||
| 39 |
DRV_ACTION=$1 |
|
| 40 |
ID=$2 |
|
| 41 | ||
| 42 |
XPATH="${DRIVER_PATH}/../xpath.rb -b $DRV_ACTION"
|
|
| 43 | ||
| 44 |
unset i j XPATH_ELEMENTS |
|
| 45 | ||
| 46 |
while IFS= read -r -d '' element; do |
|
| 47 |
XPATH_ELEMENTS[i++]="$element" |
|
| 48 |
done < <($XPATH /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/BRIDGE_LIST \ |
|
| 49 |
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/POOL_NAME) |
|
| 50 | ||
| 51 |
BRIDGE_LIST="${XPATH_ELEMENTS[j++]}"
|
|
| 52 |
POOL_NAME="${XPATH_ELEMENTS[j++]:-$POOL_NAME}"
|
|
| 53 | ||
| 54 |
HOST=`get_destination_host` |
|
| 55 | ||
| 56 |
if [ -z "$HOST" ]; then |
|
| 57 |
error_message "Datastore template missing 'BRIDGE_LIST' attribute." |
|
| 58 |
exit -1 |
|
| 59 |
fi |
|
| 60 | ||
| 61 |
# ------------ Compute datastore usage ------------- |
|
| 62 | ||
| 63 |
MONITOR_SCRIPT=$(cat <<EOF |
|
| 64 |
$DOG node info -r | $AWK '{
|
|
| 65 |
if (\$1 == "Total") {
|
|
| 66 | ||
| 67 |
print "TOTAL_MB=" int(\$2/1024/1024) |
|
| 68 |
print "USED_MB=" int(\$3/1024/1024) |
|
| 69 |
print "FREE_MB=" int(\$4/1024/1024) |
|
| 70 | ||
| 71 |
} |
|
| 72 |
}' |
|
| 73 |
EOF |
|
| 74 |
) |
|
| 75 | ||
| 76 |
MONITOR_DATA=$(ssh_monitor_and_log $HOST "$MONITOR_SCRIPT" 2>&1 | tee -a /tmp/mon.log ) |
|
| 77 |
MONITOR_STATUS=$? |
|
| 78 | ||
| 79 |
if [ "$MONITOR_STATUS" = "0" ]; then |
|
| 80 |
echo "$MONITOR_DATA" | tr ' ' '\n' |
|
| 81 |
else |
|
| 82 |
echo "$MONITOR_DATA" |
|
| 83 |
exit $MONITOR_STATUS |
|
| 84 |
fi |
|
| 85 | ||
| /var/lib/one/remotes/datastore/sheepdog/rm 2014-05-25 17:35:48.670579548 +0200 | ||
|---|---|---|
| 1 |
#!/bin/bash |
|
| 2 | ||
| 3 |
# -------------------------------------------------------------------------- # |
|
| 4 |
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs # |
|
| 5 |
# # |
|
| 6 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may # |
|
| 7 |
# not use this file except in compliance with the License. You may obtain # |
|
| 8 |
# a copy of the License at # |
|
| 9 |
# # |
|
| 10 |
# http://www.apache.org/licenses/LICENSE-2.0 # |
|
| 11 |
# # |
|
| 12 |
# Unless required by applicable law or agreed to in writing, software # |
|
| 13 |
# distributed under the License is distributed on an "AS IS" BASIS, # |
|
| 14 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # |
|
| 15 |
# See the License for the specific language governing permissions and # |
|
| 16 |
# limitations under the License. # |
|
| 17 |
#--------------------------------------------------------------------------- # |
|
| 18 | ||
| 19 |
############################################################################### |
|
| 20 |
# This script is used to remove a VM image (SRC) from the image repository |
|
| 21 |
############################################################################### |
|
| 22 | ||
| 23 |
# ------------ Set up the environment to source common tools ------------ |
|
| 24 |
if [ -z "${ONE_LOCATION}" ]; then
|
|
| 25 |
LIB_LOCATION=/usr/lib/one |
|
| 26 |
else |
|
| 27 |
LIB_LOCATION=$ONE_LOCATION/lib |
|
| 28 |
fi |
|
| 29 | ||
| 30 |
. $LIB_LOCATION/sh/scripts_common.sh |
|
| 31 | ||
| 32 |
DRIVER_PATH=$(dirname $0) |
|
| 33 |
source ${DRIVER_PATH}/../libfs.sh
|
|
| 34 |
source ${DRIVER_PATH}/sheepdog.conf
|
|
| 35 | ||
| 36 |
# -------- Get rm and datastore arguments from OpenNebula core ------------ |
|
| 37 | ||
| 38 |
DRV_ACTION=$1 |
|
| 39 |
ID=$2 |
|
| 40 | ||
| 41 |
XPATH="${DRIVER_PATH}/../xpath.rb -b $DRV_ACTION"
|
|
| 42 | ||
| 43 |
unset i j XPATH_ELEMENTS |
|
| 44 | ||
| 45 |
while IFS= read -r -d '' element; do |
|
| 46 |
XPATH_ELEMENTS[i++]="$element" |
|
| 47 |
done < <($XPATH /DS_DRIVER_ACTION_DATA/IMAGE/SOURCE \ |
|
| 48 |
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/BRIDGE_LIST) |
|
| 49 | ||
| 50 |
SRC="${XPATH_ELEMENTS[j++]}"
|
|
| 51 |
BRIDGE_LIST="${XPATH_ELEMENTS[j++]}"
|
|
| 52 | ||
| 53 |
DST_HOST=`get_destination_host $ID` |
|
| 54 | ||
| 55 |
if [ -z "$DST_HOST" ]; then |
|
| 56 |
error_message "Datastore template missing 'BRIDGE_LIST' attribute." |
|
| 57 |
exit -1 |
|
| 58 |
fi |
|
| 59 | ||
| 60 |
log "Removing $SRC from the sheepdog image repository in $DST_HOST" |
|
| 61 | ||
| 62 |
ssh_exec_and_log "$DST_HOST" "$DOG vdi delete $SRC" \ |
|
| 63 |
"Error removing $SRC in $DST_HOST" |
|
| 64 | ||
| 65 |
exit 0 |
|
| /var/lib/one/remotes/datastore/sheepdog/sheepdog.conf 2014-05-25 17:38:27.354579548 +0200 | ||
|---|---|---|
| 1 |
# -------------------------------------------------------------------------- # |
|
| 2 |
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs # |
|
| 3 |
# # |
|
| 4 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may # |
|
| 5 |
# not use this file except in compliance with the License. You may obtain # |
|
| 6 |
# a copy of the License at # |
|
| 7 |
# # |
|
| 8 |
# http://www.apache.org/licenses/LICENSE-2.0 # |
|
| 9 |
# # |
|
| 10 |
# Unless required by applicable law or agreed to in writing, software # |
|
| 11 |
# distributed under the License is distributed on an "AS IS" BASIS, # |
|
| 12 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # |
|
| 13 |
# See the License for the specific language governing permissions and # |
|
| 14 |
# limitations under the License. # |
|
| 15 |
#--------------------------------------------------------------------------- # |
|
| 16 | ||
| 17 |
# Default POOL_NAME |
|
| 18 |
POOL_NAME=one |
|
| 19 | ||
| 20 |
# Staging directory |
|
| 21 |
# A directory in the Ceph server host where image will be transferred to |
|
| 22 |
# temporarily during the create/mkfs processes. This directoy MUST exist, |
|
| 23 |
# have enough space and be writeable by 'oneadmin' |
|
| 24 |
STAGING_DIR=/var/tmp |
|
| 25 | ||
| 26 |
# Default SHEEPDOG_FORMAT. By default RAW format will be used. Uncomment the |
|
| 27 |
# following options to enable support for qcow2. This value affects all the sheepdog |
|
| 28 |
# datastores, however it can be enabled per sheepdog datastore using the same |
|
| 29 |
# option in the datastore template |
|
| 30 |
# SHEEPDOG_FORMAT=qcow2 |
|
| 31 | ||
| 32 |
# Extra arguments send to "qemu-img convert". |
|
| 33 |
# QEMU_IMG_CONVERT_ARGS=" " |
|
| /var/lib/one/remotes/datastore/sheepdog/stat 2014-05-25 17:36:24.290579548 +0200 | ||
|---|---|---|
| 1 |
#!/bin/bash |
|
| 2 | ||
| 3 |
# -------------------------------------------------------------------------- # |
|
| 4 |
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs # |
|
| 5 |
# # |
|
| 6 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may # |
|
| 7 |
# not use this file except in compliance with the License. You may obtain # |
|
| 8 |
# a copy of the License at # |
|
| 9 |
# # |
|
| 10 |
# http://www.apache.org/licenses/LICENSE-2.0 # |
|
| 11 |
# # |
|
| 12 |
# Unless required by applicable law or agreed to in writing, software # |
|
| 13 |
# distributed under the License is distributed on an "AS IS" BASIS, # |
|
| 14 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # |
|
| 15 |
# See the License for the specific language governing permissions and # |
|
| 16 |
# limitations under the License. # |
|
| 17 |
#--------------------------------------------------------------------------- # |
|
| 18 | ||
| 19 |
# ------------------------------------------------------------------------------ |
|
| 20 |
# Set up Environment and transfer arguments |
|
| 21 |
# ------------------------------------------------------------------------------ |
|
| 22 |
# |
|
| 23 |
# vmfs.conf: includes default TMP_DIR |
|
| 24 |
# libfs.sh a& scripts_common.sh: includes tools and lib calls |
|
| 25 |
# ------------------------------------------------------------------------------ |
|
| 26 | ||
| 27 |
if [ -z "${ONE_LOCATION}" ]; then
|
|
| 28 |
LIB_LOCATION=/usr/lib/one |
|
| 29 |
else |
|
| 30 |
LIB_LOCATION=$ONE_LOCATION/lib |
|
| 31 |
fi |
|
| 32 | ||
| 33 |
. $LIB_LOCATION/sh/scripts_common.sh |
|
| 34 | ||
| 35 |
DRIVER_PATH=$(dirname $0) |
|
| 36 |
source ${DRIVER_PATH}/../libfs.sh
|
|
| 37 | ||
| 38 |
# -------- Get stat and datastore arguments from OpenNebula core ------------ |
|
| 39 | ||
| 40 |
DRV_ACTION=$1 |
|
| 41 |
ID=$2 |
|
| 42 | ||
| 43 |
XPATH="${DRIVER_PATH}/../xpath.rb -b $DRV_ACTION"
|
|
| 44 | ||
| 45 |
unset i XPATH_ELEMENTS |
|
| 46 | ||
| 47 |
while IFS= read -r -d '' element; do |
|
| 48 |
XPATH_ELEMENTS[i++]="$element" |
|
| 49 |
done < <($XPATH /DS_DRIVER_ACTION_DATA/IMAGE/PATH) |
|
| 50 | ||
| 51 |
SRC="${XPATH_ELEMENTS[0]}"
|
|
| 52 | ||
| 53 |
# ------------------------------------------------------------------------------ |
|
| 54 |
# Compute the size |
|
| 55 |
# ------------------------------------------------------------------------------ |
|
| 56 | ||
| 57 |
SIZE=`fs_size $SRC` |
|
| 58 | ||
| 59 |
if [ "$SIZE" = "0" ]; then |
|
| 60 |
log_error "Cannot determine size for $SRC" |
|
| 61 |
exit -1 |
|
| 62 |
fi |
|
| 63 | ||
| 64 |
echo "$SIZE" |
|