aoe-patch-v1.0.patch
| src/datastore_mad/remotes/aoe/aoe.conf | ||
|---|---|---|
| 1 |
# -------------------------------------------------------------------------- # |
|
| 2 |
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) # |
|
| 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 AoE target host |
|
| 18 |
HOST=localhost |
|
| 19 | ||
| 20 |
# Default ethernet interface |
|
| 21 |
DEFAULT_ETH=eth1 |
|
| 22 | ||
| 23 |
# Default volume group |
|
| 24 |
VG_NAME=vg-one |
|
| src/datastore_mad/remotes/aoe/clone | ||
|---|---|---|
| 1 |
#!/bin/bash |
|
| 2 | ||
| 3 |
# -------------------------------------------------------------------------- # |
|
| 4 |
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) # |
|
| 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}/aoe.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/RESTRICTED_DIRS \ |
|
| 49 |
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/SAFE_DIRS \ |
|
| 50 |
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/UMASK \ |
|
| 51 |
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/HOST \ |
|
| 52 |
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/VG_NAME \ |
|
| 53 |
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/DEFAULT_ETH \ |
|
| 54 |
/DS_DRIVER_ACTION_DATA/IMAGE/PATH \ |
|
| 55 |
/DS_DRIVER_ACTION_DATA/IMAGE/SIZE) |
|
| 56 | ||
| 57 |
BASE_PATH="${XPATH_ELEMENTS[0]}"
|
|
| 58 |
RESTRICTED_DIRS="${XPATH_ELEMENTS[1]}"
|
|
| 59 |
SAFE_DIRS="${XPATH_ELEMENTS[2]}"
|
|
| 60 |
UMASK="${XPATH_ELEMENTS[3]}"
|
|
| 61 |
DST_HOST="${XPATH_ELEMENTS[4]:-$HOST}"
|
|
| 62 |
VG_NAME="${XPATH_ELEMENTS[5]:-$VG_NAME}"
|
|
| 63 |
DEFAULT_ETH="${XPATH_ELEMENTS[6]:-$DEFAULT_ETH}"
|
|
| 64 |
SRC="${XPATH_ELEMENTS[7]}"
|
|
| 65 |
SIZE="${XPATH_ELEMENTS[8]}"
|
|
| 66 | ||
| 67 |
set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS" "$UMASK" |
|
| 68 | ||
| 69 |
LV_NAME="lv-one-${ID}"
|
|
| 70 |
DEV="/dev/$VG_NAME/$LV_NAME" |
|
| 71 | ||
| 72 |
SHELF=`echo $SRC | sed 's/e//g' | awk -F. '{print \$1}'`
|
|
| 73 |
SLOT=`echo $SRC | sed 's/e//g' | awk -F. '{print \$2}'`
|
|
| 74 | ||
| 75 |
ETHER_SRC=`$SSH $DST_HOST $SUDO $(vblade_get_device_for_shelfslot $DEFAULT_ETH $SHELF $SLOT)` |
|
| 76 |
LV_SRC=$(echo $ETHER_SRC|awk -F/ '{print $NF}')
|
|
| 77 |
DEV_SRC="/dev/$VG_NAME/$LV_SRC" |
|
| 78 | ||
| 79 |
CLONE_CMD=$(cat <<EOF |
|
| 80 |
set -e |
|
| 81 |
$SUDO $LVCREATE -L${SIZE}M ${VG_NAME} -n ${LV_NAME}
|
|
| 82 |
$SUDO $DD if=$DEV_SRC of=$DEV bs=2M |
|
| 83 | ||
| 84 |
$SUDO $(vblade_setup_lun "$DEFAULT_ETH" "$DEV") |
|
| 85 |
EOF |
|
| 86 |
) |
|
| 87 | ||
| 88 |
ssh_exec_and_log "$DST_HOST" "$CLONE_CMD" \ |
|
| 89 |
"Error cloning $DEV_SRC to $DEV in $DST_HOST" |
|
| 90 | ||
| 91 |
SHELFSLOT=`$SSH $DST_HOST $SUDO $(vblade_get_shelfslot_for_device $DEFAULT_ETH $DEV)` |
|
| 92 | ||
| 93 |
echo "$SHELFSLOT" |
|
| src/datastore_mad/remotes/aoe/cp | ||
|---|---|---|
| 1 |
#!/bin/bash |
|
| 2 | ||
| 3 |
# -------------------------------------------------------------------------- # |
|
| 4 |
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) # |
|
| 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}/aoe.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/UMASK \ |
|
| 55 |
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/HOST \ |
|
| 56 |
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/VG_NAME \ |
|
| 57 |
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/DEFAULT_ETH \ |
|
| 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 | ||
| 64 |
BASE_PATH="${XPATH_ELEMENTS[0]}"
|
|
| 65 |
RESTRICTED_DIRS="${XPATH_ELEMENTS[1]}"
|
|
| 66 |
SAFE_DIRS="${XPATH_ELEMENTS[2]}"
|
|
| 67 |
UMASK="${XPATH_ELEMENTS[3]}"
|
|
| 68 |
DST_HOST="${XPATH_ELEMENTS[4]:-$HOST}"
|
|
| 69 |
VG_NAME="${XPATH_ELEMENTS[5]:-$VG_NAME}"
|
|
| 70 |
DEFAULT_ETH="${XPATH_ELEMENTS[6]:-$DEFAULT_ETH}"
|
|
| 71 |
SRC="${XPATH_ELEMENTS[7]}"
|
|
| 72 |
SIZE="${XPATH_ELEMENTS[8]}"
|
|
| 73 |
MD5="${XPATH_ELEMENTS[9]}"
|
|
| 74 |
SHA1="${XPATH_ELEMENTS[10]}"
|
|
| 75 |
NO_DECOMPRESS="${XPATH_ELEMENTS[11]}"
|
|
| 76 | ||
| 77 |
set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS" "$UMASK" |
|
| 78 | ||
| 79 |
LV_NAME="lv-one-${ID}"
|
|
| 80 |
DEV="/dev/$VG_NAME/$LV_NAME" |
|
| 81 | ||
| 82 |
REGISTER_CMD=$(cat <<EOF |
|
| 83 |
set -e |
|
| 84 |
$SUDO $LVCREATE -L${SIZE}M ${VG_NAME} -n ${LV_NAME}
|
|
| 85 | ||
| 86 |
$SUDO $(vblade_setup_lun "$DEFAULT_ETH" "$DEV") |
|
| 87 |
EOF |
|
| 88 |
) |
|
| 89 | ||
| 90 |
DOWNLOADER_ARGS=`set_downloader_args "$MD5" "$SHA1" "$NO_DECOMPRESS" "$SRC" -` |
|
| 91 | ||
| 92 |
COPY_COMMAND="$UTILS_PATH/downloader.sh $DOWNLOADER_ARGS" |
|
| 93 | ||
| 94 |
case $SRC in |
|
| 95 |
http://*|https://*) |
|
| 96 |
log "Downloading $SRC to the image repository" |
|
| 97 | ||
| 98 |
DUMP="$COPY_COMMAND" |
|
| 99 |
;; |
|
| 100 | ||
| 101 |
*) |
|
| 102 |
if [ `check_restricted $SRC` -eq 1 ]; then |
|
| 103 |
log_error "Not allowed to copy images from $RESTRICTED_DIRS" |
|
| 104 |
error_message "Not allowed to copy image file $SRC" |
|
| 105 |
exit -1 |
|
| 106 |
fi |
|
| 107 | ||
| 108 |
log "Copying local image $SRC to the image repository" |
|
| 109 | ||
| 110 |
DUMP="$COPY_COMMAND" |
|
| 111 |
;; |
|
| 112 |
esac |
|
| 113 | ||
| 114 |
ssh_exec_and_log "$DST_HOST" "$REGISTER_CMD" "Error registering $DST_HOST:$DEV" |
|
| 115 | ||
| 116 |
SHELFSLOT=`$SSH $DST_HOST $SUDO $(vblade_get_shelfslot_for_device $DEFAULT_ETH $DEV)` |
|
| 117 | ||
| 118 |
exec_and_log "eval $DUMP | $SSH $DST_HOST $SUDO $DD of=$DEV bs=2M" \ |
|
| 119 |
"Error dumping $SRC to $DST_HOST:$DEV" |
|
| 120 | ||
| 121 |
echo "$SHELFSLOT" |
|
| src/datastore_mad/remotes/aoe/mkfs | ||
|---|---|---|
| 1 |
#!/bin/bash |
|
| 2 | ||
| 3 |
# -------------------------------------------------------------------------- # |
|
| 4 |
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) # |
|
| 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}/aoe.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/UMASK \ |
|
| 53 |
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/HOST \ |
|
| 54 |
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/VG_NAME \ |
|
| 55 |
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/DEFAULT_ETH \ |
|
| 56 |
/DS_DRIVER_ACTION_DATA/IMAGE/FSTYPE \ |
|
| 57 |
/DS_DRIVER_ACTION_DATA/IMAGE/SIZE) |
|
| 58 | ||
| 59 |
BASE_PATH="${XPATH_ELEMENTS[0]}"
|
|
| 60 |
RESTRICTED_DIRS="${XPATH_ELEMENTS[1]}"
|
|
| 61 |
SAFE_DIRS="${XPATH_ELEMENTS[2]}"
|
|
| 62 |
UMASK="${XPATH_ELEMENTS[3]}"
|
|
| 63 |
DST_HOST="${XPATH_ELEMENTS[4]:-$HOST}"
|
|
| 64 |
VG_NAME="${XPATH_ELEMENTS[5]:-$VG_NAME}"
|
|
| 65 |
DEFAULT_ETH="${XPATH_ELEMENTS[6]:-$DEFAULT_ETH}"
|
|
| 66 |
FSTYPE="${XPATH_ELEMENTS[7]}"
|
|
| 67 |
SIZE="${XPATH_ELEMENTS[8]:-0}"
|
|
| 68 | ||
| 69 |
set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS" "$UMASK" |
|
| 70 | ||
| 71 |
LV_NAME="lv-one-${ID}"
|
|
| 72 |
DEV="/dev/$VG_NAME/$LV_NAME" |
|
| 73 | ||
| 74 |
REGISTER_CMD=$(cat <<EOF |
|
| 75 |
set -e |
|
| 76 |
$SUDO $LVCREATE -L${SIZE}M ${VG_NAME} -n ${LV_NAME}
|
|
| 77 | ||
| 78 |
$SUDO $(vblade_setup_lun "$DEFAULT_ETH" "$DEV") |
|
| 79 | ||
| 80 |
if [ "$FSTYPE" != "save_as" ]; then |
|
| 81 |
$SUDO $(mkfs_command "$DEV" "$FSTYPE") |
|
| 82 |
fi |
|
| 83 |
EOF |
|
| 84 |
) |
|
| 85 | ||
| 86 |
ssh_exec_and_log "$DST_HOST" "$REGISTER_CMD" \ |
|
| 87 |
"Error registering $DST_HOST:$DEV" |
|
| 88 | ||
| 89 |
SHELFSLOT=`$SSH $DST_HOST $SUDO $(vblade_get_shelfslot_for_device $DEFAULT_ETH $DEV)` |
|
| 90 | ||
| 91 |
echo "$SHELFSLOT" |
|
| src/datastore_mad/remotes/aoe/rm | ||
|---|---|---|
| 1 |
#!/bin/bash |
|
| 2 | ||
| 3 |
# -------------------------------------------------------------------------- # |
|
| 4 |
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) # |
|
| 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}/aoe.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 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/HOST \ |
|
| 49 |
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/DEFAULT_ETH) |
|
| 50 | ||
| 51 |
SRC="${XPATH_ELEMENTS[0]}"
|
|
| 52 |
DST_HOST="${XPATH_ELEMENTS[1]:-$HOST}"
|
|
| 53 |
DEFAULT_ETH="${XPATH_ELEMENTS[2]:-$DEFAULT_ETH}"
|
|
| 54 | ||
| 55 |
SHELF=`echo $SRC | sed 's/e//g' | awk -F. '{print \$1}'`
|
|
| 56 |
SLOT=`echo $SRC | sed 's/e//g' | awk -F. '{print \$2}'`
|
|
| 57 | ||
| 58 |
ETHER_SRC=`$SSH $DST_HOST $SUDO $(vblade_get_device_for_shelfslot $DEFAULT_ETH $SHELF $SLOT)` |
|
| 59 | ||
| 60 |
LV_NAME=`echo $ETHER_SRC|$AWK -F/ '{print $(NF)}'`
|
|
| 61 |
VG_NAME=`echo $ETHER_SRC|$AWK -F/ '{print $(NF-1)}'`
|
|
| 62 |
DEV="/dev/$VG_NAME/$LV_NAME" |
|
| 63 | ||
| 64 |
RM_COMMAND=$(cat <<EOF |
|
| 65 |
$SUDO $(vblade_delete_shelfslot $SHELF $SLOT) |
|
| 66 |
$SUDO $SYNC |
|
| 67 |
$SUDO $LVREMOVE -f $VG_NAME/$LV_NAME |
|
| 68 |
EOF |
|
| 69 |
) |
|
| 70 | ||
| 71 |
log "Removing $DST_HOST:$DEV from the image repository" |
|
| 72 | ||
| 73 |
ssh_exec_and_log "$DST_HOST" "$RM_COMMAND" \ |
|
| 74 |
"Error removing $DST_HOST:$DEV" |
|
| 75 | ||
| 76 |
exit 0 |
|
| src/datastore_mad/remotes/aoe/stat | ||
|---|---|---|
| 1 |
#!/bin/bash |
|
| 2 | ||
| 3 |
# -------------------------------------------------------------------------- # |
|
| 4 |
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) # |
|
| 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 | ||
| 37 |
# -------- Get cp and 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 XPATH_ELEMENTS |
|
| 45 | ||
| 46 |
while IFS= read -r -d '' element; do |
|
| 47 |
XPATH_ELEMENTS[i++]="$element" |
|
| 48 |
done < <($XPATH /DS_DRIVER_ACTION_DATA/IMAGE/PATH) |
|
| 49 | ||
| 50 |
SRC="${XPATH_ELEMENTS[0]}"
|
|
| 51 | ||
| 52 |
SIZE=`fs_size $SRC` |
|
| 53 | ||
| 54 |
if [ "$SIZE" = "0" ]; then |
|
| 55 |
log_error "Cannot determine size for $SRC" |
|
| 56 |
exit -1 |
|
| 57 |
fi |
|
| 58 | ||
| 59 |
echo "$SIZE" |
|
| src/tm_mad/aoe/clone | ||
|---|---|---|
| 1 |
#!/bin/bash |
|
| 2 | ||
| 3 |
# -------------------------------------------------------------------------- # |
|
| 4 |
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) # |
|
| 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 |
# clone fe:SOURCE host:remote_system_ds/disk.i size vmid dsid |
|
| 20 |
# - fe is the front-end hostname |
|
| 21 |
# - SOURCE is the path of the disk image in the form DS_BASE_PATH/disk |
|
| 22 |
# - host is the target host to deploy the VM |
|
| 23 |
# - remote_system_ds is the path for the system datastore in the host |
|
| 24 |
# - vmid is the id of the VM |
|
| 25 |
# - dsid is the target datastore (0 is the system datastore) |
|
| 26 | ||
| 27 |
SRC=$1 |
|
| 28 |
DST=$2 |
|
| 29 | ||
| 30 |
VMID=$3 |
|
| 31 |
DSID=$4 |
|
| 32 | ||
| 33 |
if [ -z "${ONE_LOCATION}" ]; then
|
|
| 34 |
TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh |
|
| 35 |
else |
|
| 36 |
TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh |
|
| 37 |
fi |
|
| 38 | ||
| 39 |
DRIVER_PATH=$(dirname $0) |
|
| 40 | ||
| 41 |
. $TMCOMMON |
|
| 42 | ||
| 43 |
source ${DRIVER_PATH}/../../datastore/aoe/aoe.conf
|
|
| 44 | ||
| 45 |
#------------------------------------------------------------------------------- |
|
| 46 |
# Set src, dst path and dir |
|
| 47 |
#------------------------------------------------------------------------------- |
|
| 48 | ||
| 49 |
TARGET=`arg_path $SRC` |
|
| 50 | ||
| 51 |
DST_PATH=`arg_path $DST` |
|
| 52 |
DST_HOST=`arg_host $DST` |
|
| 53 |
DST_DIR=`dirname $DST_PATH` |
|
| 54 | ||
| 55 |
#------------------------------------------------------------------------------- |
|
| 56 |
# IQN and TARGETs |
|
| 57 |
#------------------------------------------------------------------------------- |
|
| 58 | ||
| 59 |
SHELFSLOT=$TARGET |
|
| 60 | ||
| 61 |
SHELF=`echo $SHELFSLOT | sed 's/e//g' | awk -F. '{print \$1}'`
|
|
| 62 |
SLOT=`echo $SHELFSLOT | sed 's/e//g' | awk -F. '{print \$2}'`
|
|
| 63 | ||
| 64 |
ETHER_SRC=`$SSH $HOST $SUDO $(vblade_get_device_for_shelfslot $DEFAULT_ETH $SHELF $SLOT)` |
|
| 65 | ||
| 66 |
VG_NAME=`echo $ETHER_SRC|$AWK -F/ '{print $(NF-1)}'`
|
|
| 67 |
LV_NAME=`echo $ETHER_SRC|$AWK -F/ '{print $(NF)}'`
|
|
| 68 |
SOURCE_DEV="/dev/$VG_NAME/$LV_NAME" |
|
| 69 | ||
| 70 |
TARGET_LV_NAME=`echo $LV_NAME-$VMID` |
|
| 71 |
TARGET_DEV="/dev/${VG_NAME}/${TARGET_LV_NAME}"
|
|
| 72 |
TARGET_HOST=$HOST |
|
| 73 | ||
| 74 |
#------------------------------------------------------------------------------- |
|
| 75 |
# Clone script |
|
| 76 |
#------------------------------------------------------------------------------- |
|
| 77 | ||
| 78 |
CLONE_CMD=$(cat <<EOF |
|
| 79 |
set -e |
|
| 80 | ||
| 81 |
# get size |
|
| 82 |
SIZE=\$($SUDO lvdisplay $SOURCE_DEV | grep "Current LE" | awk '{print \$3}')
|
|
| 83 | ||
| 84 |
# create lv |
|
| 85 |
$SUDO $LVCREATE -l\${SIZE} ${VG_NAME} -n ${TARGET_LV_NAME}
|
|
| 86 | ||
| 87 |
# clone lv with dd |
|
| 88 |
$SUDO $DD if=$SOURCE_DEV of=$TARGET_DEV bs=2M |
|
| 89 | ||
| 90 |
# new aoe target |
|
| 91 |
$SUDO $(vblade_setup_lun "$DEFAULT_ETH" "$TARGET_DEV") |
|
| 92 |
EOF |
|
| 93 |
) |
|
| 94 | ||
| 95 |
ssh_exec_and_log "$TARGET_HOST" "$CLONE_CMD" \ |
|
| 96 |
"Error cloning $DST_HOST:$TARGET_DEV" |
|
| 97 | ||
| 98 |
DISCOVERY_CMD=$(cat <<EOF |
|
| 99 |
set -e |
|
| 100 |
mkdir -p $DST_DIR |
|
| 101 |
/usr/sbin/aoe-discover |
|
| 102 |
EOF |
|
| 103 |
) |
|
| 104 | ||
| 105 |
ssh_exec_and_log "$DST_HOST" "$DISCOVERY_CMD" \ |
|
| 106 |
"Error discovering $NEW_IQN in $DST_HOST" |
|
| 107 | ||
| 108 |
NEW_SHELFSLOT=`$SSH $HOST $SUDO $(vblade_get_shelfslot_for_device $DEFAULT_ETH $TARGET_DEV)` |
|
| 109 | ||
| 110 |
TEST_CMD=$(cat <<EOF |
|
| 111 |
set -e |
|
| 112 |
while [ ! -b /dev/etherd/$NEW_SHELFSLOT ]; do |
|
| 113 |
sleep 1 |
|
| 114 |
done |
|
| 115 |
EOF |
|
| 116 |
) |
|
| 117 | ||
| 118 |
ssh_exec_and_log "$DST_HOST" "$TEST_CMD" \ |
|
| 119 |
"Error waiting for $NEW_SHELFSLOT AoE LUN to appear in $DST_HOST" |
|
| 120 | ||
| 121 | ||
| 122 |
LINK_CMD=$(cat <<EOF |
|
| 123 |
set -e |
|
| 124 |
ln -s "/dev/etherd/$NEW_SHELFSLOT" "$DST_PATH" |
|
| 125 |
EOF |
|
| 126 |
) |
|
| 127 | ||
| 128 |
ssh_exec_and_log "$DST_HOST" "$LINK_CMD" \ |
|
| 129 |
"Error linking $NEW_IQN in $DST_HOST" |
|
| 130 | ||
| 131 |
exit 0 |
|
| src/tm_mad/aoe/delete | ||
|---|---|---|
| 1 |
#!/bin/bash |
|
| 2 | ||
| 3 |
# -------------------------------------------------------------------------- # |
|
| 4 |
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) # |
|
| 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 |
# DELETE <host:remote_system_ds/disk.i|host:remote_system_ds/> vmid dsid |
|
| 20 |
# - host is the target host to deploy the VM |
|
| 21 |
# - remote_system_ds is the path for the system datastore in the host |
|
| 22 |
# - vmid is the id of the VM |
|
| 23 |
# - dsid is the target datastore (0 is the system datastore) |
|
| 24 | ||
| 25 |
DST=$1 |
|
| 26 | ||
| 27 |
VMID=$2 |
|
| 28 |
DSID=$3 |
|
| 29 | ||
| 30 |
if [ -z "${ONE_LOCATION}" ]; then
|
|
| 31 |
TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh |
|
| 32 |
else |
|
| 33 |
TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh |
|
| 34 |
fi |
|
| 35 | ||
| 36 |
. $TMCOMMON |
|
| 37 | ||
| 38 |
DRIVER_PATH=$(dirname $0) |
|
| 39 | ||
| 40 |
source ${DRIVER_PATH}/../../datastore/aoe/aoe.conf
|
|
| 41 | ||
| 42 |
#------------------------------------------------------------------------------- |
|
| 43 |
# Return if deleting a disk, we will delete them when removing the |
|
| 44 |
# remote_system_ds directory for the VM (remotely) |
|
| 45 |
#------------------------------------------------------------------------------- |
|
| 46 |
DST_PATH=`arg_path $DST` |
|
| 47 |
DST_HOST=`arg_host $DST` |
|
| 48 | ||
| 49 |
#------------------------------------------------------------------------------- |
|
| 50 |
# Get IQN information |
|
| 51 |
#------------------------------------------------------------------------------- |
|
| 52 | ||
| 53 |
DISK_ID=$(echo "$DST_PATH" | $AWK -F. '{print $NF}')
|
|
| 54 | ||
| 55 |
XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin"
|
|
| 56 | ||
| 57 |
unset i XPATH_ELEMENTS |
|
| 58 | ||
| 59 |
while IFS= read -r -d '' element; do |
|
| 60 |
XPATH_ELEMENTS[i++]="$element" |
|
| 61 |
done < <(onevm show -x $VMID| $XPATH \ |
|
| 62 |
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/SOURCE \ |
|
| 63 |
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/IMAGE_ID \ |
|
| 64 |
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/PERSISTENT) |
|
| 65 | ||
| 66 |
SHELFSLOT_SOURCE="${XPATH_ELEMENTS[0]}"
|
|
| 67 |
IMAGE_ID="${XPATH_ELEMENTS[1]}"
|
|
| 68 |
PERSISTENT="${XPATH_ELEMENTS[2]}"
|
|
| 69 | ||
| 70 |
TARGET=`arg_path $SHELFSLOT` |
|
| 71 |
TARGET_HOST=$HOST |
|
| 72 | ||
| 73 |
#------------------------------------------------------------------------------- |
|
| 74 |
# Remove directory if dst_path is a directory |
|
| 75 |
#------------------------------------------------------------------------------- |
|
| 76 | ||
| 77 |
if [ `is_disk $DST_PATH` -eq 0 ]; then |
|
| 78 |
# Directory |
|
| 79 |
log "Deleting $DST_PATH" |
|
| 80 |
ssh_exec_and_log "$DST_HOST" "rm -rf $DST_PATH" "Error deleting $DST_PATH" |
|
| 81 |
exit 0 |
|
| 82 |
fi |
|
| 83 | ||
| 84 |
if [ "$PERSISTENT" = "YES" ]; then |
|
| 85 |
exit 0 |
|
| 86 |
fi |
|
| 87 | ||
| 88 |
#------------------------------------------------------------------------------- |
|
| 89 |
# Remove target and LV in the AoE server |
|
| 90 |
#------------------------------------------------------------------------------- |
|
| 91 | ||
| 92 | ||
| 93 |
TARGET_LV_NAME="lv-one-$IMAGE_ID-$VMID" |
|
| 94 |
ETHER_SRC=`$SSH $TARGET_HOST $SUDO $(vblade_get_shelfslot_for_device $DEFAULT_ETH /dev/$VG_NAME/$TARGET_LV_NAME)` |
|
| 95 |
SHELF=`echo $ETHER_SRC | sed 's/e//g' | awk -F. '{print \$1}'`
|
|
| 96 |
SLOT=`echo $ETHER_SRC | sed 's/e//g' | awk -F. '{print \$2}'`
|
|
| 97 | ||
| 98 |
DELETE_CMD=$(cat <<EOF |
|
| 99 |
set -e |
|
| 100 | ||
| 101 |
# remove aoe target |
|
| 102 |
$SUDO $(vblade_delete_shelfslot $SHELF $SLOT) |
|
| 103 | ||
| 104 |
# remove lv |
|
| 105 |
$SUDO $LVREMOVE -f $VG_NAME/$TARGET_LV_NAME |
|
| 106 |
EOF |
|
| 107 |
) |
|
| 108 | ||
| 109 |
ssh_exec_and_log "$TARGET_HOST" "$DELETE_CMD" \ |
|
| 110 |
"Error deleting $TARGET" |
|
| 111 | ||
| 112 |
exit 0 |
|
| src/tm_mad/aoe/ln | ||
|---|---|---|
| 1 |
#!/bin/bash |
|
| 2 | ||
| 3 |
# -------------------------------------------------------------------------- # |
|
| 4 |
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) # |
|
| 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 |
# clone fe:SOURCE host:remote_system_ds/disk.i size vmid dsid |
|
| 20 |
# - fe is the front-end hostname |
|
| 21 |
# - SOURCE is the path of the disk image in the form DS_BASE_PATH/disk |
|
| 22 |
# - host is the target host to deploy the VM |
|
| 23 |
# - remote_system_ds is the path for the system datastore in the host |
|
| 24 |
# - vmid is the id of the VM |
|
| 25 |
# - dsid is the target datastore (0 is the system datastore) |
|
| 26 | ||
| 27 |
SRC=$1 |
|
| 28 |
DST=$2 |
|
| 29 | ||
| 30 |
VMID=$3 |
|
| 31 |
DSID=$4 |
|
| 32 | ||
| 33 |
if [ -z "${ONE_LOCATION}" ]; then
|
|
| 34 |
TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh |
|
| 35 |
else |
|
| 36 |
TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh |
|
| 37 |
fi |
|
| 38 | ||
| 39 |
. $TMCOMMON |
|
| 40 | ||
| 41 |
DRIVER_PATH=$(dirname $0) |
|
| 42 | ||
| 43 |
source ${DRIVER_PATH}/../../datastore/aoe/aoe.conf
|
|
| 44 |
#------------------------------------------------------------------------------- |
|
| 45 |
# Set dst path and dir |
|
| 46 |
#------------------------------------------------------------------------------- |
|
| 47 | ||
| 48 | ||
| 49 |
IQN=$SRC |
|
| 50 | ||
| 51 |
log "SRC: $SRC" |
|
| 52 | ||
| 53 |
TARGET=`arg_path $SRC` |
|
| 54 |
DST_PATH=`arg_path $DST` |
|
| 55 |
DST_HOST=`arg_host $DST` |
|
| 56 |
DST_DIR=`dirname $DST_PATH` |
|
| 57 | ||
| 58 |
BASE_IQN=`echo $IQN|$CUT -d: -f1` |
|
| 59 |
TARGET=`echo $IQN|$CUT -d: -f2` |
|
| 60 | ||
| 61 |
log "dstdir: $DST_DIR" |
|
| 62 | ||
| 63 |
TEST_CMD=$(cat <<EOF |
|
| 64 |
set -e |
|
| 65 |
mkdir -p $DST_DIR |
|
| 66 |
/usr/sbin/aoe-discover |
|
| 67 |
while [ ! -b /dev/etherd/$TARGET ]; do |
|
| 68 |
sleep 1 |
|
| 69 |
done |
|
| 70 |
EOF |
|
| 71 |
) |
|
| 72 | ||
| 73 |
ssh_exec_and_log "$DST_HOST" "$TEST_CMD" \ |
|
| 74 |
"Error waiting for $TARGET etherd LUN to appear in $DST_HOST" |
|
| 75 | ||
| 76 |
LINK_CMD=$(cat <<EOF |
|
| 77 |
set -e |
|
| 78 |
ln -s "/dev/etherd/$TARGET" "$DST_PATH" |
|
| 79 |
EOF |
|
| 80 |
) |
|
| 81 | ||
| 82 |
ssh_exec_and_log "$DST_HOST" "$LINK_CMD" \ |
|
| 83 |
"Error linking $DST_HOST:$DEV" |
|
| 84 | ||
| 85 |
exit 0 |
|
| src/tm_mad/aoe/mv | ||
|---|---|---|
| 1 |
#!/bin/bash |
|
| 2 | ||
| 3 |
# -------------------------------------------------------------------------- # |
|
| 4 |
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) # |
|
| 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 |
# MV <hostA:system_ds/disk.i|hostB:system_ds/disk.i> vmid dsid |
|
| 20 |
# <hostA:system_ds/|hostB:system_ds/> |
|
| 21 |
# - hostX is the target host to deploy the VM |
|
| 22 |
# - system_ds is the path for the system datastore in the host |
|
| 23 |
# - vmid is the id of the VM |
|
| 24 |
# - dsid is the target datastore (0 is the system datastore) |
|
| 25 | ||
| 26 |
SRC=$1 |
|
| 27 |
DST=$2 |
|
| 28 | ||
| 29 |
VMID=$3 |
|
| 30 |
DSID=$4 |
|
| 31 | ||
| 32 |
if [ -z "${ONE_LOCATION}" ]; then
|
|
| 33 |
TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh |
|
| 34 |
else |
|
| 35 |
TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh |
|
| 36 |
fi |
|
| 37 | ||
| 38 |
. $TMCOMMON |
|
| 39 | ||
| 40 |
DRIVER_PATH=$(dirname $0) |
|
| 41 | ||
| 42 |
source ${DRIVER_PATH}/../../datastore/aoe/aoe.conf
|
|
| 43 | ||
| 44 |
#------------------------------------------------------------------------------- |
|
| 45 |
# Return if moving a disk, we will move them when moving the whole system_ds |
|
| 46 |
# directory for the VM |
|
| 47 |
#------------------------------------------------------------------------------- |
|
| 48 |
SRC_PATH=`arg_path $SRC` |
|
| 49 |
DST_PATH=`arg_path $DST` |
|
| 50 | ||
| 51 |
SRC_HOST=`arg_host $SRC` |
|
| 52 |
DST_HOST=`arg_host $DST` |
|
| 53 | ||
| 54 |
DST_DIR=`dirname $DST_PATH` |
|
| 55 | ||
| 56 |
if [ `is_disk $SRC_PATH` -eq 0 ]; then |
|
| 57 |
ssh_make_path $DST_HOST $DST_DIR |
|
| 58 | ||
| 59 |
log "Moving $SRC to $DST" |
|
| 60 | ||
| 61 |
exec_and_log "$SCP -r $SRC $DST" "Could not copy $SRC to $DST" |
|
| 62 | ||
| 63 |
ssh_exec_and_log "$SRC_HOST" "rm -rf $SRC_PATH" \ |
|
| 64 |
"Could not remove $SRC_HOST:$SRC_PATH" |
|
| 65 | ||
| 66 |
exit 0 |
|
| 67 |
fi |
|
| 68 | ||
| 69 |
if [ "$SRC" == "$DST" ]; then |
|
| 70 |
log "Not moving $SRC to $DST, they are the same path" |
|
| 71 |
exit 0 |
|
| 72 |
fi |
|
| 73 | ||
| 74 |
exit 0 |
|
| src/tm_mad/aoe/mvds | ||
|---|---|---|
| 1 |
#!/bin/bash |
|
| 2 | ||
| 3 |
# -------------------------------------------------------------------------- # |
|
| 4 |
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) # |
|
| 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 |
# mvds host:remote_system_ds/disk.i fe:SOURCE |
|
| 20 |
# - fe is the front-end hostname |
|
| 21 |
# - SOURCE is the path of the disk image in the form DS_BASE_PATH/disk |
|
| 22 |
# - host is the target host to deploy the VM |
|
| 23 |
# - remote_system_ds is the path for the system datastore in the host |
|
| 24 |
# - vmid is the id of the VM |
|
| 25 |
# - dsid is the target datastore (0 is the system datastore) |
|
| 26 | ||
| 27 |
SRC=$1 |
|
| 28 |
DST=$2 |
|
| 29 | ||
| 30 |
VMID=$3 |
|
| 31 |
DSID=$4 |
|
| 32 | ||
| 33 |
if [ -z "${ONE_LOCATION}" ]; then
|
|
| 34 |
TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh |
|
| 35 |
else |
|
| 36 |
TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh |
|
| 37 |
fi |
|
| 38 | ||
| 39 |
DRIVER_PATH=$(dirname $0) |
|
| 40 | ||
| 41 |
. $TMCOMMON |
|
| 42 | ||
| 43 |
source ${DRIVER_PATH}/../../datastore/aoe/aoe.conf
|
|
| 44 | ||
| 45 |
SRC_HOST=`arg_host $SRC` |
|
| 46 |
NEW_IQN="$DST" |
|
| 47 | ||
| 48 |
DISK_ID=$(echo $SRC|awk -F. '{print $NF}')
|
|
| 49 | ||
| 50 |
#------------------------------------------------------------------------------- |
|
| 51 |
# Get image information |
|
| 52 |
#------------------------------------------------------------------------------- |
|
| 53 | ||
| 54 |
XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin"
|
|
| 55 | ||
| 56 |
unset i XPATH_ELEMENTS |
|
| 57 | ||
| 58 |
while IFS= read -r -d '' element; do |
|
| 59 |
XPATH_ELEMENTS[i++]="$element" |
|
| 60 |
done < <(onevm show -x $VMID| $XPATH \ |
|
| 61 |
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/SOURCE \ |
|
| 62 |
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/SAVE_AS \ |
|
| 63 |
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/PERSISTENT \ |
|
| 64 |
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/IMAGE_ID) |
|
| 65 | ||
| 66 |
IQN="${XPATH_ELEMENTS[0]}"
|
|
| 67 |
SAVE_AS="${XPATH_ELEMENTS[1]}"
|
|
| 68 |
PERSISTENT="${XPATH_ELEMENTS[2]}"
|
|
| 69 |
IMAGE_ID="${XPATH_ELEMENTS[3]}"
|
|
| 70 | ||
| 71 |
# Exit if not save_as. We are finished if this was a persistent image. |
|
| 72 |
[ -z "$SAVE_AS" ] && exit 0 |
|
| 73 | ||
| 74 |
#------------------------------------------------------------------------------- |
|
| 75 |
# IQN and TARGETs |
|
| 76 |
#------------------------------------------------------------------------------- |
|
| 77 |
if [ -z "$PERSISTENT" ]; then |
|
| 78 |
LV_NAME="lv-one-$IMAGE_ID-$VMID" |
|
| 79 |
else |
|
| 80 |
LV_NAME="lv-one-$IMAGE_ID" |
|
| 81 |
fi |
|
| 82 |
SOURCE_DEV="/dev/$VG_NAME/$LV_NAME" |
|
| 83 |
OLD_ETHER_SRC=`$SSH $HOST $SUDO $(vblade_get_shelfslot_for_device $DEFAULT_ETH $SOURCE_DEV)` |
|
| 84 |
OLD_SHELF=`echo $OLD_ETHER_SRC | sed 's/e//g' | awk -F. '{print \$1}'`
|
|
| 85 |
OLD_SLOT=`echo $OLD_ETHER_SRC | sed 's/e//g' | awk -F. '{print \$2}'`
|
|
| 86 | ||
| 87 | ||
| 88 |
SHELF=`echo $NEW_IQN | sed 's/e//g' | awk -F. '{print \$1}'`
|
|
| 89 |
SLOT=`echo $NEW_IQN | sed 's/e//g' | awk -F. '{print \$2}'`
|
|
| 90 | ||
| 91 |
ETHER_SRC=`$SSH $HOST $SUDO $(vblade_get_device_for_shelfslot $DEFAULT_ETH $SHELF $SLOT)` |
|
| 92 | ||
| 93 |
TARGET_LV_NAME=`echo $ETHER_SRC|$AWK -F/ '{print $(NF)}'`
|
|
| 94 |
TARGET_DEV="/dev/$VG_NAME/$TARGET_LV_NAME" |
|
| 95 |
TARGET_HOST=$HOST |
|
| 96 | ||
| 97 |
CLONE_CMD=$(cat <<EOF |
|
| 98 |
set -e |
|
| 99 | ||
| 100 |
# clone lv with dd |
|
| 101 |
$SUDO $DD if=$SOURCE_DEV of=$TARGET_DEV bs=1M |
|
| 102 | ||
| 103 |
# remove if source_dev is not persistent |
|
| 104 |
if [ -z "$PERSISTENT" ]; then |
|
| 105 |
$SUDO $(vblade_delete_shelfslot $OLD_SHELF $OLD_SLOT) |
|
| 106 |
$SUDO $SYNC |
|
| 107 |
$SUDO $LVREMOVE -f $VG_NAME/$LV_NAME |
|
| 108 |
fi |
|
| 109 |
EOF |
|
| 110 |
) |
|
| 111 | ||
| 112 |
ssh_exec_and_log "$TARGET_HOST" "$CLONE_CMD" \ |
|
| 113 |
"Error cloning $DST_HOST:$TARGET_DEV or removing nonpersistent $IQN" |
|
| src/tm_mad/aoe/postmigrate | ||
|---|---|---|
| 1 |
#!/bin/bash |
|
| 2 | ||
| 3 |
# -------------------------------------------------------------------------- # |
|
| 4 |
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) # |
|
| 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 |
# POSTMIGRATE SOURCE DST remote_system_dir vmid dsid template |
|
| 19 |
# - SOURCE is the host where the VM is running |
|
| 20 |
# - DST is the host where the VM is to be migrated |
|
| 21 |
# - remote_system_dir is the path for the VM home in the system datastore |
|
| 22 |
# - vmid is the id of the VM |
|
| 23 |
# - dsid is the target datastore |
|
| 24 |
# - template is the template of the VM in XML and base64 encoded |
|
| 25 | ||
| 26 |
# To access the vm_template you can use the xpath.rb utility. Check the |
|
| 27 |
# datastore drivers for an example. |
|
| 28 | ||
| 29 |
exit 0 |
|
| src/tm_mad/aoe/premigrate | ||
|---|---|---|
| 1 |
#!/bin/bash |
|
| 2 | ||
| 3 |
# -------------------------------------------------------------------------- # |
|
| 4 |
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) # |
|
| 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 |
# PREMIGRATE SOURCE DST remote_system_dir vmid dsid template |
|
| 19 |
# - SOURCE is the host where the VM is running |
|
| 20 |
# - DST is the host where the VM is to be migrated |
|
| 21 |
# - remote_system_dir is the path for the VM home in the system datastore |
|
| 22 |
# - vmid is the id of the VM |
|
| 23 |
# - dsid is the target datastore |
|
| 24 |
# - template is the template of the VM in XML and base64 encoded |
|
| 25 | ||
| 26 |
# To access the vm_template you can use the xpath.rb utility. Check the |
|
| 27 |
# datastore drivers for an example. |
|
| 28 | ||
| 29 |
exit 1 |
|