mirror of
https://github.com/OpenNebula/one.git
synced 2024-12-23 17:33:56 +03:00
Merge branch 'feature-2460' into one-4.4
This commit is contained in:
commit
79252f0c2c
31
install.sh
31
install.sh
@ -224,7 +224,6 @@ else
|
||||
fi
|
||||
|
||||
SHARE_DIRS="$SHARE_LOCATION/examples \
|
||||
$SHARE_LOCATION/tgt \
|
||||
$SHARE_LOCATION/websockify"
|
||||
|
||||
ETC_DIRS="$ETC_LOCATION/vmm_exec \
|
||||
@ -288,7 +287,6 @@ VAR_DIRS="$VAR_LOCATION/remotes \
|
||||
$VAR_LOCATION/remotes/tm/qcow2 \
|
||||
$VAR_LOCATION/remotes/tm/ssh \
|
||||
$VAR_LOCATION/remotes/tm/vmfs \
|
||||
$VAR_LOCATION/remotes/tm/iscsi \
|
||||
$VAR_LOCATION/remotes/tm/lvm \
|
||||
$VAR_LOCATION/remotes/tm/ceph \
|
||||
$VAR_LOCATION/remotes/hooks \
|
||||
@ -297,7 +295,6 @@ VAR_DIRS="$VAR_LOCATION/remotes \
|
||||
$VAR_LOCATION/remotes/datastore/dummy \
|
||||
$VAR_LOCATION/remotes/datastore/fs \
|
||||
$VAR_LOCATION/remotes/datastore/vmfs \
|
||||
$VAR_LOCATION/remotes/datastore/iscsi \
|
||||
$VAR_LOCATION/remotes/datastore/lvm \
|
||||
$VAR_LOCATION/remotes/datastore/ceph \
|
||||
$VAR_LOCATION/remotes/auth \
|
||||
@ -474,7 +471,6 @@ INSTALL_FILES=(
|
||||
TM_QCOW2_FILES:$VAR_LOCATION/remotes/tm/qcow2
|
||||
TM_SSH_FILES:$VAR_LOCATION/remotes/tm/ssh
|
||||
TM_VMFS_FILES:$VAR_LOCATION/remotes/tm/vmfs
|
||||
TM_ISCSI_FILES:$VAR_LOCATION/remotes/tm/iscsi
|
||||
TM_LVM_FILES:$VAR_LOCATION/remotes/tm/lvm
|
||||
TM_CEPH_FILES:$VAR_LOCATION/remotes/tm/ceph
|
||||
TM_DUMMY_FILES:$VAR_LOCATION/remotes/tm/dummy
|
||||
@ -482,7 +478,6 @@ INSTALL_FILES=(
|
||||
DATASTORE_DRIVER_DUMMY_SCRIPTS:$VAR_LOCATION/remotes/datastore/dummy
|
||||
DATASTORE_DRIVER_FS_SCRIPTS:$VAR_LOCATION/remotes/datastore/fs
|
||||
DATASTORE_DRIVER_VMFS_SCRIPTS:$VAR_LOCATION/remotes/datastore/vmfs
|
||||
DATASTORE_DRIVER_ISCSI_SCRIPTS:$VAR_LOCATION/remotes/datastore/iscsi
|
||||
DATASTORE_DRIVER_LVM_SCRIPTS:$VAR_LOCATION/remotes/datastore/lvm
|
||||
DATASTORE_DRIVER_CEPH_SCRIPTS:$VAR_LOCATION/remotes/datastore/ceph
|
||||
NETWORK_FILES:$VAR_LOCATION/remotes/vnm
|
||||
@ -494,7 +489,6 @@ INSTALL_FILES=(
|
||||
NETWORK_OVSWITCH_BRCOMPAT_FILES:$VAR_LOCATION/remotes/vnm/ovswitch_brcompat
|
||||
NETWORK_VMWARE_FILES:$VAR_LOCATION/remotes/vnm/vmware
|
||||
EXAMPLE_SHARE_FILES:$SHARE_LOCATION/examples
|
||||
TGT_SHARE_FILES:$SHARE_LOCATION/tgt
|
||||
WEBSOCKIFY_SHARE_FILES:$SHARE_LOCATION/websockify
|
||||
INSTALL_GEMS_SHARE_FILE:$SHARE_LOCATION
|
||||
HOOK_FT_FILES:$VAR_LOCATION/remotes/hooks/ft
|
||||
@ -984,7 +978,6 @@ NETWORK_VMWARE_FILES="src/vnm_mad/remotes/vmware/clean \
|
||||
# - SSH TM, $VAR_LOCATION/tm/ssh
|
||||
# - DUMMY TM, $VAR_LOCATION/tm/dummy
|
||||
# - VMWARE TM, $VAR_LOCATION/tm/vmware
|
||||
# - ISCSI TM, $VAR_LOCATION/tm/iscsi
|
||||
# - LVM TM, $VAR_LOCATION/tm/lvm
|
||||
# - CEPH TM, $VAR_LOCATION/tm/ceph
|
||||
#-------------------------------------------------------------------------------
|
||||
@ -1060,15 +1053,6 @@ TM_VMFS_FILES="src/tm_mad/vmfs/clone \
|
||||
src/tm_mad/vmfs/postmigrate \
|
||||
src/tm_mad/vmfs/premigrate"
|
||||
|
||||
TM_ISCSI_FILES="src/tm_mad/iscsi/clone \
|
||||
src/tm_mad/iscsi/ln \
|
||||
src/tm_mad/iscsi/mv \
|
||||
src/tm_mad/iscsi/mvds \
|
||||
src/tm_mad/iscsi/cpds \
|
||||
src/tm_mad/iscsi/premigrate \
|
||||
src/tm_mad/iscsi/postmigrate \
|
||||
src/tm_mad/iscsi/delete"
|
||||
|
||||
TM_LVM_FILES="src/tm_mad/lvm/clone \
|
||||
src/tm_mad/lvm/ln \
|
||||
src/tm_mad/lvm/mv \
|
||||
@ -1092,7 +1076,6 @@ TM_CEPH_FILES="src/tm_mad/ceph/clone \
|
||||
# - Dummy Image Repository, $REMOTES_LOCATION/datastore/dummy
|
||||
# - FS based Image Repository, $REMOTES_LOCATION/datastore/fs
|
||||
# - VMFS based Image Repository, $REMOTES_LOCATION/datastore/vmfs
|
||||
# - iSCSI based Image Repository, $REMOTES_LOCATION/datastore/iscsi
|
||||
# - LVM based Image Repository, $REMOTES_LOCATION/datastore/lvm
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
@ -1122,14 +1105,6 @@ DATASTORE_DRIVER_VMFS_SCRIPTS="src/datastore_mad/remotes/vmfs/cp \
|
||||
src/datastore_mad/remotes/vmfs/rm \
|
||||
src/datastore_mad/remotes/vmfs/vmfs.conf"
|
||||
|
||||
DATASTORE_DRIVER_ISCSI_SCRIPTS="src/datastore_mad/remotes/iscsi/cp \
|
||||
src/datastore_mad/remotes/iscsi/mkfs \
|
||||
src/datastore_mad/remotes/iscsi/stat \
|
||||
src/datastore_mad/remotes/iscsi/rm \
|
||||
src/datastore_mad/remotes/iscsi/clone \
|
||||
src/datastore_mad/remotes/iscsi/monitor \
|
||||
src/datastore_mad/remotes/iscsi/iscsi.conf"
|
||||
|
||||
DATASTORE_DRIVER_LVM_SCRIPTS="src/datastore_mad/remotes/lvm/cp \
|
||||
src/datastore_mad/remotes/lvm/mkfs \
|
||||
src/datastore_mad/remotes/lvm/stat \
|
||||
@ -1229,12 +1204,6 @@ EXAMPLE_SHARE_FILES="share/examples/vm.template \
|
||||
share/examples/private.net \
|
||||
share/examples/public.net"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# File required to interact with a tgtd server
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
TGT_SHARE_FILES="share/scripts/tgt/tgt-setup-lun-one"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Files required to interact with the websockify server
|
||||
#-------------------------------------------------------------------------------
|
||||
|
@ -369,7 +369,7 @@ VM_MAD = [ name="dummy", executable="one_vmm_dummy", type="xml" ]
|
||||
|
||||
TM_MAD = [
|
||||
executable = "one_tm",
|
||||
arguments = "-t 15 -d dummy,lvm,shared,shared_lvm,qcow2,ssh,vmfs,iscsi,ceph"
|
||||
arguments = "-t 15 -d dummy,lvm,shared,shared_lvm,qcow2,ssh,vmfs,ceph"
|
||||
]
|
||||
|
||||
TM_MAD_CONF = [
|
||||
@ -421,13 +421,6 @@ TM_MAD_CONF = [
|
||||
shared = "yes"
|
||||
]
|
||||
|
||||
TM_MAD_CONF = [
|
||||
name = "iscsi",
|
||||
ln_target = "NONE",
|
||||
clone_target= "SELF",
|
||||
shared = "yes"
|
||||
]
|
||||
|
||||
TM_MAD_CONF = [
|
||||
name = "ceph",
|
||||
ln_target = "NONE",
|
||||
@ -450,7 +443,7 @@ TM_MAD_CONF = [
|
||||
|
||||
DATASTORE_MAD = [
|
||||
executable = "one_datastore",
|
||||
arguments = "-t 15 -d dummy,fs,vmfs,iscsi,lvm,ceph"
|
||||
arguments = "-t 15 -d dummy,fs,vmfs,lvm,ceph"
|
||||
]
|
||||
|
||||
#*******************************************************************************
|
||||
|
@ -390,7 +390,7 @@ VM_MAD = [
|
||||
|
||||
TM_MAD = [
|
||||
executable = "one_tm",
|
||||
arguments = "-t 15 -d dummy,lvm,shared,fs_lvm,qcow2,ssh,vmfs,iscsi,ceph"
|
||||
arguments = "-t 15 -d dummy,lvm,shared,fs_lvm,qcow2,ssh,vmfs,ceph"
|
||||
]
|
||||
|
||||
TM_MAD_CONF = [
|
||||
@ -442,13 +442,6 @@ TM_MAD_CONF = [
|
||||
shared = "yes"
|
||||
]
|
||||
|
||||
TM_MAD_CONF = [
|
||||
name = "iscsi",
|
||||
ln_target = "NONE",
|
||||
clone_target= "SELF",
|
||||
shared = "yes"
|
||||
]
|
||||
|
||||
TM_MAD_CONF = [
|
||||
name = "ceph",
|
||||
ln_target = "NONE",
|
||||
@ -471,7 +464,7 @@ TM_MAD_CONF = [
|
||||
|
||||
DATASTORE_MAD = [
|
||||
executable = "one_datastore",
|
||||
arguments = "-t 15 -d dummy,fs,vmfs,iscsi,lvm,ceph"
|
||||
arguments = "-t 15 -d dummy,fs,vmfs,lvm,ceph"
|
||||
]
|
||||
|
||||
#*******************************************************************************
|
||||
|
@ -1,279 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# LUN assignment script
|
||||
#
|
||||
# Copyright (C) 2007 Erez Zilber <erezz@voltaire.com>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License as
|
||||
# published by the Free Software Foundation, version 2 of the
|
||||
# License.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
# 02110-1301 USA
|
||||
|
||||
usage()
|
||||
{
|
||||
name=$(basename $0);
|
||||
echo "usage:";
|
||||
echo -e "\t$name -n tgt_name -d dev -b bs_name -t transport [initiator_IP1 initiator_IP2 ...]";
|
||||
echo "defaults:";
|
||||
echo -e "\tbacking store: rdwr";
|
||||
echo -e "\ttransport: iscsi";
|
||||
echo -e "\tinitiator: ALL";
|
||||
echo "examples:";
|
||||
echo -e "\t$name -n tgt-1 -d /dev/sdb1 192.168.1.2";
|
||||
echo -e "\t$name -n tgt-2 -d /tmp/null -b null -t iser";
|
||||
echo -e "\t$name -n tgt-3 -d ~/disk3.bin -b rdwr 192.168.1.2 192.168.1.3";
|
||||
}
|
||||
|
||||
verify_params()
|
||||
{
|
||||
if ! [ "$dev" -o "$bs_type" == "null" ]; then
|
||||
echo "Error: a device is mandatory";
|
||||
exit 1;
|
||||
else
|
||||
return;
|
||||
fi
|
||||
|
||||
# Make sure that the device exists
|
||||
if ! [ -b $dev -o -f $dev -o -c $dev ]; then
|
||||
echo "Error: $dev is not a device";
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
if ! [ "$tgt_name" ]; then
|
||||
echo "Error: target name is mandatory";
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
if ! [ "$lld_name" ]; then
|
||||
echo "Error: lld name empty";
|
||||
exit 1;
|
||||
fi
|
||||
}
|
||||
|
||||
find_vacant_tgt_id()
|
||||
{
|
||||
tmp_file=`mktemp`
|
||||
tgtadm --lld $lld_name --op show --mode target | strings > $tmp_file
|
||||
id_list=$(cat $tmp_file | grep Target | cut -d" " -f2 | sed s/://)
|
||||
next_vacant_id=1
|
||||
for id in $id_list; do
|
||||
if (($id > $next_vacant_id)); then
|
||||
break;
|
||||
else
|
||||
next_vacant_id=$((next_vacant_id+1))
|
||||
fi
|
||||
done
|
||||
rm -f $tmp_file
|
||||
echo $next_vacant_id
|
||||
}
|
||||
|
||||
find_vacant_lun()
|
||||
{
|
||||
tid=$1
|
||||
tgt_found=0
|
||||
next_vacant_lun=0
|
||||
tmp_file=`mktemp`
|
||||
|
||||
tgtadm --lld $lld_name --op show --mode target | strings | tgt-admin -s | grep 'LUN\|Target' > $tmp_file
|
||||
retcode=$?
|
||||
while read line; do
|
||||
# Check if we finished going over this target
|
||||
if ((tgt_found == 1 && $(echo $line | grep -c "^Target") == 1)); then
|
||||
break
|
||||
fi
|
||||
|
||||
# Check if we found the requested target
|
||||
if (($(echo $line | grep -c "Target $tid:") == 1)); then
|
||||
tgt_found=1
|
||||
continue
|
||||
fi
|
||||
|
||||
if ((tgt_found == 1 && $(echo $line | grep -c "LUN:") == 1)); then
|
||||
curr_lun=$(echo $line | cut -d" " -f2)
|
||||
if (($curr_lun > $next_vacant_lun)); then
|
||||
break
|
||||
else
|
||||
next_vacant_lun=$((next_vacant_lun+1))
|
||||
fi
|
||||
fi
|
||||
done < $tmp_file
|
||||
|
||||
rm -f $tmp_file
|
||||
|
||||
if ((tgt_found == 0)); then
|
||||
echo "Error: could not find a LUN for target $tid, guessing 1 as next vacant LUN"
|
||||
return 1
|
||||
fi
|
||||
if ((next_vacant_lun == 0)); then
|
||||
echo "Error: could not find a LUN for target $tid, guessing 1 as next vacant LUN"
|
||||
return 1
|
||||
fi
|
||||
|
||||
return $next_vacant_lun
|
||||
}
|
||||
|
||||
err_exit()
|
||||
{
|
||||
if ((new_tgt == 0)); then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Deleting new target, tid=$tid"
|
||||
tgtadm --lld $lld_name --op delete --mode target --tid $tid
|
||||
res=$?
|
||||
|
||||
if [ $res -ne 0 ]; then
|
||||
echo "Error: failed to delete target, tid=$tid"
|
||||
fi
|
||||
|
||||
exit 1
|
||||
}
|
||||
|
||||
check_if_tgt_exists()
|
||||
{
|
||||
tgt_list=$(tgtadm --lld $lld_name --op show --mode target | strings | grep Target | cut -d" " -f3)
|
||||
|
||||
for curr_tgt in $tgt_list; do
|
||||
if [ $tgt_name = $curr_tgt ]; then
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
lld_name="iscsi"
|
||||
|
||||
while getopts "d:n:b:t:h:" opt
|
||||
do
|
||||
case ${opt} in
|
||||
d)
|
||||
dev=$OPTARG;;
|
||||
n)
|
||||
tgt_name=$OPTARG;;
|
||||
b)
|
||||
bs_type=$OPTARG;;
|
||||
t)
|
||||
lld_name=$OPTARG;;
|
||||
h*)
|
||||
usage
|
||||
exit 1
|
||||
esac
|
||||
done
|
||||
|
||||
shift $(($OPTIND - 1))
|
||||
|
||||
initiators=$*
|
||||
|
||||
verify_params
|
||||
|
||||
# Check if tgtd is running (we should have 2 daemons)
|
||||
tgtd_count=`pidof tgtd | wc -w`
|
||||
if [ $tgtd_count -lt 1 ]; then
|
||||
echo "tgtd is not running"
|
||||
echo "Exiting..."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Using transport: $lld_name"
|
||||
|
||||
if ! [[ $tgt_name =~ ^iqn ]]; then
|
||||
tgt_name="iqn.2001-04.com.$(hostname -s)-$tgt_name"
|
||||
fi
|
||||
|
||||
# Make sure that a target with the same name doesn't exist
|
||||
check_if_tgt_exists
|
||||
if [ $? -eq 1 ]; then
|
||||
echo "Error: target named $tgt_name already exists"
|
||||
read -p "Add a new lun to the existing target? (yes/NO): " add_lun
|
||||
if [ $add_lun != "yes" ]; then
|
||||
exit 1
|
||||
fi
|
||||
tid=$(tgtadm --lld $lld_name --op show --mode target | strings | grep $tgt_name | cut -d" " -f2)
|
||||
tid=${tid%:}
|
||||
new_tgt=0
|
||||
else
|
||||
|
||||
i=0
|
||||
while [ true ]
|
||||
do
|
||||
let i=i+1
|
||||
tid=`find_vacant_tgt_id`
|
||||
#tid=$?
|
||||
# Create the new target
|
||||
echo -n "Creating new target (name=$tgt_name, tid=$tid)..."
|
||||
tgtoutput=`tgtadm --lld $lld_name --op new --mode target --tid $tid -T $tgt_name 2>&1`
|
||||
res=$?
|
||||
if [ "$tgtoutput" == "tgtadm: this target already exists" ]; then
|
||||
echo "Target already exists (this should not happen)... Attempt $i"
|
||||
elif [ $res -eq 0 ]; then # output is not about duplication and return value is zero, this is the normal condition
|
||||
break
|
||||
fi
|
||||
if [ $i -eq 100 ]; then
|
||||
echo "Too many attempts, giving up"
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ $res -ne 0 ]; then
|
||||
echo "Error: failed to create target (name=$tgt_name, tid=$tid)"
|
||||
exit 1
|
||||
fi
|
||||
new_tgt=1
|
||||
fi
|
||||
echo "OK"
|
||||
find_vacant_lun $tid
|
||||
lun=$?
|
||||
echo "LUN ok, $lun"
|
||||
|
||||
# Add a logical unit to the target
|
||||
echo "Adding a logical unit ($dev) to target, tid=$tid"
|
||||
if [ $bs_type ]; then
|
||||
echo "Setting backing store type: $bs_type"
|
||||
bs_opt="-E $bs_type"
|
||||
fi
|
||||
tgtadm --lld $lld_name --op new --mode logicalunit --tid $tid --lun $lun -b $dev $bs_opt
|
||||
res=$?
|
||||
|
||||
if [ $res -ne 0 ]; then
|
||||
echo "Error: failed to add a logical unit ($dev) to target, tid=$tid"
|
||||
err_exit
|
||||
fi
|
||||
|
||||
# Define which initiators can use this target
|
||||
if test "$initiators" ; then
|
||||
# Allow access only for specific initiators
|
||||
echo "Accepting connections only from $initiators"
|
||||
for initiator in $initiators; do
|
||||
tgtadm --lld $lld_name --op bind --mode target --tid $tid -I $initiator
|
||||
res=$?
|
||||
|
||||
if [ $res -ne 0 ]; then
|
||||
echo "Error: could not assign initiator $initiator to the target"
|
||||
fi
|
||||
done
|
||||
else
|
||||
# Allow access for everyone
|
||||
echo "Accepting connections from all initiators"
|
||||
tgtadm --lld $lld_name --op bind --mode target --tid $tid -I ALL
|
||||
res=$?
|
||||
|
||||
if [ $res -ne 0 ]; then
|
||||
echo "Error: failed to set access for all initiators"
|
||||
err_exit
|
||||
fi
|
||||
fi
|
@ -1,97 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
|
||||
# #
|
||||
# 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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
###############################################################################
|
||||
# This script is used to copy a VM image (SRC) to the image repository as DST
|
||||
# Several SRC types are supported
|
||||
###############################################################################
|
||||
# -------- Set up the environment to source common tools & conf ------------
|
||||
if [ -z "${ONE_LOCATION}" ]; then
|
||||
LIB_LOCATION=/usr/lib/one
|
||||
else
|
||||
LIB_LOCATION=$ONE_LOCATION/lib
|
||||
fi
|
||||
|
||||
. $LIB_LOCATION/sh/scripts_common.sh
|
||||
|
||||
DRIVER_PATH=$(dirname $0)
|
||||
source ${DRIVER_PATH}/../libfs.sh
|
||||
source ${DRIVER_PATH}/iscsi.conf
|
||||
|
||||
# -------- Get cp and datastore arguments from OpenNebula core ------------
|
||||
|
||||
DRV_ACTION=$1
|
||||
ID=$2
|
||||
|
||||
XPATH="${DRIVER_PATH}/../xpath.rb -b $DRV_ACTION"
|
||||
|
||||
unset i j XPATH_ELEMENTS
|
||||
|
||||
while IFS= read -r -d '' element; do
|
||||
XPATH_ELEMENTS[i++]="$element"
|
||||
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/BRIDGE_LIST \
|
||||
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/VG_NAME \
|
||||
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/BASE_IQN \
|
||||
/DS_DRIVER_ACTION_DATA/IMAGE/PATH \
|
||||
/DS_DRIVER_ACTION_DATA/IMAGE/SIZE)
|
||||
|
||||
BASE_PATH="${XPATH_ELEMENTS[j++]}"
|
||||
RESTRICTED_DIRS="${XPATH_ELEMENTS[j++]}"
|
||||
SAFE_DIRS="${XPATH_ELEMENTS[j++]}"
|
||||
BRIDGE_LIST="${XPATH_ELEMENTS[j++]}"
|
||||
VG_NAME="${XPATH_ELEMENTS[j++]:-$VG_NAME}"
|
||||
BASE_IQN="${XPATH_ELEMENTS[j++]:-$BASE_IQN}"
|
||||
SRC="${XPATH_ELEMENTS[j++]}"
|
||||
SIZE="${XPATH_ELEMENTS[j++]}"
|
||||
|
||||
DST_HOST=`get_destination_host $ID`
|
||||
|
||||
if [ -z "$DST_HOST" ]; then
|
||||
error_message "Datastore template missing 'BRIDGE_LIST' attribute."
|
||||
exit -1
|
||||
fi
|
||||
|
||||
# Check if 'TGTSETUPLUN' is installed
|
||||
tgt_setup_lun_install "$DST_HOST" "$BASE_PATH"
|
||||
|
||||
set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS"
|
||||
|
||||
LV_NAME="lv-one-${ID}"
|
||||
IQN="$BASE_IQN:$DST_HOST.$VG_NAME.$LV_NAME"
|
||||
DEV="/dev/$VG_NAME/$LV_NAME"
|
||||
|
||||
LV_SRC=$(echo $SRC|awk -F. '{print $NF}')
|
||||
DEV_SRC="/dev/$VG_NAME/$LV_SRC"
|
||||
|
||||
CLONE_CMD=$(cat <<EOF
|
||||
set -e
|
||||
$SUDO $LVCREATE -L${SIZE}M ${VG_NAME} -n ${LV_NAME}
|
||||
$SUDO $DD if=$DEV_SRC of=$DEV bs=2M
|
||||
|
||||
$SUDO $(tgt_setup_lun "$IQN" "$DEV")
|
||||
$SUDO $(tgt_admin_dump_config "$TARGET_CONF")
|
||||
EOF
|
||||
)
|
||||
|
||||
ssh_exec_and_log "$DST_HOST" "$CLONE_CMD" \
|
||||
"Error cloning $DEV_SRC to $DEV in $DST_HOST"
|
||||
|
||||
echo "$IQN"
|
@ -1,131 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
|
||||
# #
|
||||
# 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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
###############################################################################
|
||||
# This script is used to copy a VM image (SRC) to the image repository as DST
|
||||
# Several SRC types are supported
|
||||
###############################################################################
|
||||
|
||||
# -------- Set up the environment to source common tools & conf ------------
|
||||
|
||||
if [ -z "${ONE_LOCATION}" ]; then
|
||||
LIB_LOCATION=/usr/lib/one
|
||||
else
|
||||
LIB_LOCATION=$ONE_LOCATION/lib
|
||||
fi
|
||||
|
||||
. $LIB_LOCATION/sh/scripts_common.sh
|
||||
|
||||
DRIVER_PATH=$(dirname $0)
|
||||
source ${DRIVER_PATH}/../libfs.sh
|
||||
source ${DRIVER_PATH}/iscsi.conf
|
||||
|
||||
# -------- Get cp and datastore arguments from OpenNebula core ------------
|
||||
|
||||
DRV_ACTION=$1
|
||||
ID=$2
|
||||
|
||||
UTILS_PATH="${DRIVER_PATH}/.."
|
||||
|
||||
XPATH="$UTILS_PATH/xpath.rb -b $DRV_ACTION"
|
||||
|
||||
unset i j XPATH_ELEMENTS
|
||||
|
||||
while IFS= read -r -d '' element; do
|
||||
XPATH_ELEMENTS[i++]="$element"
|
||||
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/BRIDGE_LIST \
|
||||
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/VG_NAME \
|
||||
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/BASE_IQN \
|
||||
/DS_DRIVER_ACTION_DATA/IMAGE/PATH \
|
||||
/DS_DRIVER_ACTION_DATA/IMAGE/SIZE \
|
||||
/DS_DRIVER_ACTION_DATA/IMAGE/TEMPLATE/MD5 \
|
||||
/DS_DRIVER_ACTION_DATA/IMAGE/TEMPLATE/SHA1 \
|
||||
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/NO_DECOMPRESS \
|
||||
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/LIMIT_TRANSFER_BW)
|
||||
|
||||
BASE_PATH="${XPATH_ELEMENTS[j++]}"
|
||||
RESTRICTED_DIRS="${XPATH_ELEMENTS[j++]}"
|
||||
SAFE_DIRS="${XPATH_ELEMENTS[j++]}"
|
||||
BRIDGE_LIST="${XPATH_ELEMENTS[j++]}"
|
||||
VG_NAME="${XPATH_ELEMENTS[j++]:-$VG_NAME}"
|
||||
BASE_IQN="${XPATH_ELEMENTS[j++]:-$BASE_IQN}"
|
||||
SRC="${XPATH_ELEMENTS[j++]}"
|
||||
SIZE="${XPATH_ELEMENTS[j++]}"
|
||||
MD5="${XPATH_ELEMENTS[j++]}"
|
||||
SHA1="${XPATH_ELEMENTS[j++]}"
|
||||
NO_DECOMPRESS="${XPATH_ELEMENTS[j++]}"
|
||||
LIMIT_TRANSFER_BW="${XPATH_ELEMENTS[j++]}"
|
||||
|
||||
DST_HOST=`get_destination_host $ID`
|
||||
|
||||
if [ -z "$DST_HOST" ]; then
|
||||
error_message "Datastore template missing 'BRIDGE_LIST' attribute."
|
||||
exit -1
|
||||
fi
|
||||
|
||||
# Check if 'TGTSETUPLUN' is installed
|
||||
tgt_setup_lun_install "$DST_HOST" "$BASE_PATH"
|
||||
|
||||
set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS"
|
||||
|
||||
LV_NAME="lv-one-${ID}"
|
||||
IQN="$BASE_IQN:$DST_HOST.$VG_NAME.$LV_NAME"
|
||||
DEV="/dev/$VG_NAME/$LV_NAME"
|
||||
|
||||
REGISTER_CMD=$(cat <<EOF
|
||||
set -e
|
||||
$SUDO $LVCREATE -L${SIZE}M ${VG_NAME} -n ${LV_NAME}
|
||||
|
||||
$SUDO $(tgt_setup_lun "$IQN" "$DEV")
|
||||
$SUDO $(tgt_admin_dump_config "$TARGET_CONF")
|
||||
EOF
|
||||
)
|
||||
|
||||
DOWNLOADER_ARGS=`set_downloader_args "$MD5" "$SHA1" "$NO_DECOMPRESS" "$LIMIT_TRANSFER_BW" "$SRC" -`
|
||||
|
||||
COPY_COMMAND="$UTILS_PATH/downloader.sh $DOWNLOADER_ARGS"
|
||||
|
||||
case $SRC in
|
||||
http://*|https://*)
|
||||
log "Downloading $SRC to the image repository"
|
||||
|
||||
DUMP="$COPY_COMMAND"
|
||||
;;
|
||||
|
||||
*)
|
||||
if [ `check_restricted $SRC` -eq 1 ]; then
|
||||
log_error "Not allowed to copy images from $RESTRICTED_DIRS"
|
||||
error_message "Not allowed to copy image file $SRC"
|
||||
exit -1
|
||||
fi
|
||||
|
||||
log "Copying local image $SRC to the image repository"
|
||||
|
||||
DUMP="$COPY_COMMAND"
|
||||
;;
|
||||
esac
|
||||
|
||||
ssh_exec_and_log "$DST_HOST" "$REGISTER_CMD" "Error registering $DST_HOST:$DEV"
|
||||
|
||||
exec_and_log "eval $DUMP | $SSH $DST_HOST $SUDO $DD of=$DEV bs=2M" \
|
||||
"Error dumping $SRC to $DST_HOST:$DEV"
|
||||
|
||||
echo "$IQN"
|
@ -1,29 +0,0 @@
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
|
||||
# #
|
||||
# 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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
# Default IQN path
|
||||
BASE_IQN=iqn.2012-02.org.opennebula
|
||||
|
||||
# Default volume group
|
||||
VG_NAME=vg-one
|
||||
|
||||
# Lists of hosts (separated by spaces) for which no iscsiadm login or logout
|
||||
# is performed.
|
||||
NO_ISCSI="$HOSTNAME"
|
||||
|
||||
# File where the iSCSI configured is dumped to (tgt-admin --dump)
|
||||
# If it poings to /dev/null, iSCSI targets will not be persistent
|
||||
TARGET_CONF=/etc/tgt/targets.conf
|
@ -1,99 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
|
||||
# #
|
||||
# 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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
###############################################################################
|
||||
# This script is used to create a VM image (SRC) of size (SIZE) and formatted
|
||||
# as (FS)
|
||||
###############################################################################
|
||||
|
||||
# -------- Set up the environment to source common tools & conf ------------
|
||||
|
||||
if [ -z "${ONE_LOCATION}" ]; then
|
||||
LIB_LOCATION=/usr/lib/one
|
||||
else
|
||||
LIB_LOCATION=$ONE_LOCATION/lib
|
||||
fi
|
||||
|
||||
. $LIB_LOCATION/sh/scripts_common.sh
|
||||
|
||||
DRIVER_PATH=$(dirname $0)
|
||||
source ${DRIVER_PATH}/../libfs.sh
|
||||
source ${DRIVER_PATH}/iscsi.conf
|
||||
|
||||
# -------- Get mkfs and datastore arguments from OpenNebula core ------------
|
||||
|
||||
DRV_ACTION=$1
|
||||
ID=$2
|
||||
|
||||
XPATH="${DRIVER_PATH}/../xpath.rb -b $DRV_ACTION"
|
||||
|
||||
unset i j XPATH_ELEMENTS
|
||||
|
||||
while IFS= read -r -d '' element; do
|
||||
XPATH_ELEMENTS[i++]="$element"
|
||||
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/BRIDGE_LIST \
|
||||
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/VG_NAME \
|
||||
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/BASE_IQN \
|
||||
/DS_DRIVER_ACTION_DATA/IMAGE/FSTYPE \
|
||||
/DS_DRIVER_ACTION_DATA/IMAGE/SIZE)
|
||||
|
||||
BASE_PATH="${XPATH_ELEMENTS[j++]}"
|
||||
RESTRICTED_DIRS="${XPATH_ELEMENTS[j++]}"
|
||||
SAFE_DIRS="${XPATH_ELEMENTS[j++]}"
|
||||
BRIDGE_LIST="${XPATH_ELEMENTS[j++]}"
|
||||
VG_NAME="${XPATH_ELEMENTS[j++]:-$VG_NAME}"
|
||||
BASE_IQN="${XPATH_ELEMENTS[j++]:-$BASE_IQN}"
|
||||
FSTYPE="${XPATH_ELEMENTS[j++]}"
|
||||
SIZE="${XPATH_ELEMENTS[j++]:-0}"
|
||||
|
||||
DST_HOST=`get_destination_host $ID`
|
||||
|
||||
if [ -z "$DST_HOST" ]; then
|
||||
error_message "Datastore template missing 'BRIDGE_LIST' attribute."
|
||||
exit -1
|
||||
fi
|
||||
|
||||
# Check if 'TGTSETUPLUN' is installed
|
||||
tgt_setup_lun_install "$DST_HOST" "$BASE_PATH"
|
||||
|
||||
set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS"
|
||||
|
||||
LV_NAME="lv-one-${ID}"
|
||||
IQN="$BASE_IQN:$DST_HOST.$VG_NAME.$LV_NAME"
|
||||
DEV="/dev/$VG_NAME/$LV_NAME"
|
||||
|
||||
REGISTER_CMD=$(cat <<EOF
|
||||
set -e
|
||||
$SUDO $LVCREATE -L${SIZE}M ${VG_NAME} -n ${LV_NAME}
|
||||
|
||||
$SUDO $(tgt_setup_lun "$IQN" "$DEV")
|
||||
$SUDO $(tgt_admin_dump_config "$TARGET_CONF")
|
||||
|
||||
if [ "$FSTYPE" != "save_as" ]; then
|
||||
$SUDO $(mkfs_command "$DEV" "$FSTYPE")
|
||||
fi
|
||||
EOF
|
||||
)
|
||||
|
||||
ssh_exec_and_log "$DST_HOST" "$REGISTER_CMD" \
|
||||
"Error registering $DST_HOST:$DEV"
|
||||
|
||||
echo "$IQN"
|
@ -1,86 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
|
||||
# #
|
||||
# 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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
###############################################################################
|
||||
# This script is used to monitor the free and used space of a datastore
|
||||
###############################################################################
|
||||
|
||||
# -------- Set up the environment to source common tools & conf ------------
|
||||
|
||||
if [ -z "${ONE_LOCATION}" ]; then
|
||||
LIB_LOCATION=/usr/lib/one
|
||||
else
|
||||
LIB_LOCATION=$ONE_LOCATION/lib
|
||||
fi
|
||||
|
||||
. $LIB_LOCATION/sh/scripts_common.sh
|
||||
|
||||
DRIVER_PATH=$(dirname $0)
|
||||
source ${DRIVER_PATH}/../libfs.sh
|
||||
source ${DRIVER_PATH}/iscsi.conf
|
||||
|
||||
# -------- Get datastore arguments from OpenNebula core ------------
|
||||
|
||||
DRV_ACTION=$1
|
||||
ID=$2
|
||||
|
||||
XPATH="${DRIVER_PATH}/../xpath.rb -b $DRV_ACTION"
|
||||
|
||||
unset i j XPATH_ELEMENTS
|
||||
|
||||
while IFS= read -r -d '' element; do
|
||||
XPATH_ELEMENTS[i++]="$element"
|
||||
done < <($XPATH /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/BRIDGE_LIST \
|
||||
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/VG_NAME)
|
||||
|
||||
BRIDGE_LIST="${XPATH_ELEMENTS[j++]}"
|
||||
VG_NAME="${XPATH_ELEMENTS[j++]:-$VG_NAME}"
|
||||
|
||||
HOST=`get_destination_host`
|
||||
|
||||
if [ -z "$HOST" ]; then
|
||||
error_message "Datastore template missing 'BRIDGE_LIST' attribute."
|
||||
exit -1
|
||||
fi
|
||||
|
||||
# ------------ Compute datastore usage -------------
|
||||
|
||||
MONITOR_SCRIPT=$(cat <<EOF
|
||||
set -e
|
||||
|
||||
VG_OPTS="--units M -C --noheadings --nosuffix $VG_NAME"
|
||||
|
||||
TOTAL_MB=\$($SUDO $VGDISPLAY -o vg_size \$VG_OPTS | $TR -d ' ')
|
||||
FREE_MB=\$($SUDO $VGDISPLAY -o vg_free \$VG_OPTS | $TR -d ' ')
|
||||
USED_MB=\$($AWK "BEGIN {print \$TOTAL_MB - \$FREE_MB}")
|
||||
|
||||
echo "USED_MB=\$USED_MB"
|
||||
echo "TOTAL_MB=\$TOTAL_MB"
|
||||
echo "FREE_MB=\$FREE_MB"
|
||||
EOF
|
||||
)
|
||||
|
||||
MONITOR_DATA=$(ssh_monitor_and_log $HOST "$MONITOR_SCRIPT" 2>&1)
|
||||
MONITOR_STATUS=$?
|
||||
|
||||
if [ "$MONITOR_STATUS" = "0" ]; then
|
||||
echo "$MONITOR_DATA" | tr ' ' '\n'
|
||||
else
|
||||
echo "$MONITOR_DATA"
|
||||
exit $MONITOR_STATUS
|
||||
fi
|
@ -1,85 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
|
||||
# #
|
||||
# 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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
###############################################################################
|
||||
# This script is used to remove a VM image (SRC) from the image repository
|
||||
###############################################################################
|
||||
|
||||
# ------------ Set up the environment to source common tools ------------
|
||||
if [ -z "${ONE_LOCATION}" ]; then
|
||||
LIB_LOCATION=/usr/lib/one
|
||||
else
|
||||
LIB_LOCATION=$ONE_LOCATION/lib
|
||||
fi
|
||||
|
||||
. $LIB_LOCATION/sh/scripts_common.sh
|
||||
|
||||
DRIVER_PATH=$(dirname $0)
|
||||
source ${DRIVER_PATH}/../libfs.sh
|
||||
source ${DRIVER_PATH}/iscsi.conf
|
||||
|
||||
# -------- Get rm and datastore arguments from OpenNebula core ------------
|
||||
|
||||
DRV_ACTION=$1
|
||||
ID=$2
|
||||
|
||||
XPATH="${DRIVER_PATH}/../xpath.rb -b $DRV_ACTION"
|
||||
|
||||
unset i j XPATH_ELEMENTS
|
||||
|
||||
while IFS= read -r -d '' element; do
|
||||
XPATH_ELEMENTS[i++]="$element"
|
||||
done < <($XPATH /DS_DRIVER_ACTION_DATA/IMAGE/SOURCE \
|
||||
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/BRIDGE_LIST)
|
||||
|
||||
SRC="${XPATH_ELEMENTS[j++]}"
|
||||
BRIDGE_LIST="${XPATH_ELEMENTS[j++]}"
|
||||
|
||||
DST_HOST=`get_destination_host $ID`
|
||||
|
||||
if [ -z "$DST_HOST" ]; then
|
||||
error_message "Datastore template missing 'BRIDGE_LIST' attribute."
|
||||
exit -1
|
||||
fi
|
||||
|
||||
BASE_IQN=`echo $SRC|$CUT -d: -f1`
|
||||
TARGET=`echo $SRC|$CUT -d: -f2`
|
||||
LV_NAME=`echo $TARGET|$AWK -F. '{print $(NF)}'`
|
||||
VG_NAME=`echo $TARGET|$AWK -F. '{print $(NF-1)}'`
|
||||
DEV="/dev/$VG_NAME/$LV_NAME"
|
||||
|
||||
IQN="$BASE_IQN:$DST_HOST.$VG_NAME.$LV_NAME"
|
||||
|
||||
RM_COMMAND=$(cat <<EOF
|
||||
set -e
|
||||
|
||||
TID=\$($SUDO $(tgtadm_get_tid_for_iqn "$IQN"))
|
||||
|
||||
$SUDO $(tgtadm_target_delete "\$TID")
|
||||
$SUDO $SYNC
|
||||
$SUDO $LVREMOVE -f $VG_NAME/$LV_NAME
|
||||
$SUDO $(tgt_admin_dump_config "$TARGET_CONF")
|
||||
EOF
|
||||
)
|
||||
|
||||
log "Removing $DST_HOST:$DEV from the image repository"
|
||||
|
||||
ssh_exec_and_log "$DST_HOST" "$RM_COMMAND" \
|
||||
"Error removing $DST_HOST:$DEV"
|
||||
|
||||
exit 0
|
@ -1 +0,0 @@
|
||||
../common/stat
|
@ -394,6 +394,9 @@ EOF`
|
||||
fi
|
||||
}
|
||||
|
||||
# TODO -> Use a dynamically loaded scripts directory. Not removing this due
|
||||
# to iSCSI addon: https://github.com/OpenNebula/addon-iscsi
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# iSCSI functions
|
||||
|
@ -390,7 +390,7 @@ VM_MAD = [ name="dummy", executable="one_vmm_dummy", type="xml" ]
|
||||
|
||||
TM_MAD = [
|
||||
executable = "one_tm",
|
||||
arguments = "-t 15 -d dummy,lvm,shared,shared_lvm,qcow2,ssh,vmfs,iscsi,ceph"
|
||||
arguments = "-t 15 -d dummy,lvm,shared,shared_lvm,qcow2,ssh,vmfs,ceph"
|
||||
]
|
||||
|
||||
TM_MAD_CONF = [
|
||||
@ -442,13 +442,6 @@ TM_MAD_CONF = [
|
||||
shared = "yes"
|
||||
]
|
||||
|
||||
TM_MAD_CONF = [
|
||||
name = "iscsi",
|
||||
ln_target = "NONE",
|
||||
clone_target= "SELF",
|
||||
shared = "yes"
|
||||
]
|
||||
|
||||
TM_MAD_CONF = [
|
||||
name = "ceph",
|
||||
ln_target = "NONE",
|
||||
@ -471,7 +464,7 @@ TM_MAD_CONF = [
|
||||
|
||||
DATASTORE_MAD = [
|
||||
executable = "one_datastore",
|
||||
arguments = "-t 15 -d dummy,fs,vmfs,iscsi,lvm,ceph"
|
||||
arguments = "-t 15 -d dummy,fs,vmfs,lvm,ceph"
|
||||
]
|
||||
|
||||
#*******************************************************************************
|
||||
|
@ -102,7 +102,6 @@ var create_datastore_tmpl =
|
||||
<select id="presets" name="presets">\
|
||||
<option value="fs">' + tr("Filesystem") + '</option>\
|
||||
<option value="vmware_vmfs">' + tr("VMware VMFS") + '</option>\
|
||||
<option value="iscsi">' + tr("iSCSI") + '</option>\
|
||||
<option value="block_lvm">' + tr("Block LVM") + '</option>\
|
||||
<option value="fs_lvm">' + tr("FS LVM") + '</option>\
|
||||
<option value="ceph">' + tr("Ceph") + '</option>\
|
||||
@ -168,7 +167,6 @@ var create_datastore_tmpl =
|
||||
<select id="ds_mad" name="ds_mad">\
|
||||
<option value="fs">' + tr("Filesystem") + '</option>\
|
||||
<option value="vmware">' + tr("VMware") + '</option>\
|
||||
<option value="iscsi">' + tr("iSCSI") + '</option>\
|
||||
<option value="lvm">' + tr("LVM") + '</option>\
|
||||
<option value="vmfs">' + tr("VMFS") + '</option>\
|
||||
<option value="ceph">' + tr("Ceph") + '</option>\
|
||||
@ -191,7 +189,6 @@ var create_datastore_tmpl =
|
||||
<option value="shared">' + tr("Shared") + '</option>\
|
||||
<option value="ssh">' + tr("SSH") + '</option>\
|
||||
<option value="qcow2">' + tr("qcow2") + '</option>\
|
||||
<option value="iscsi">' + tr("iSCSI") + '</option>\
|
||||
<option value="dummy">' + tr("Dummy") + '</option>\
|
||||
<option value="lvm">' + tr("LVM") + '</option>\
|
||||
<option value="fs_lvm">' + tr("FS LVM") + '</option>\
|
||||
@ -943,9 +940,6 @@ function setupCreateDatastoreDialog(){
|
||||
case 'fs_lvm':
|
||||
select_fs_lvm();
|
||||
break;
|
||||
case 'iscsi':
|
||||
select_iscsi();
|
||||
break;
|
||||
case 'ceph':
|
||||
select_ceph();
|
||||
break;
|
||||
@ -1099,25 +1093,6 @@ function select_vmware_vmfs(){
|
||||
$('select#disk_type').attr('disabled', 'disabled');
|
||||
}
|
||||
|
||||
function select_iscsi(){
|
||||
$('select#ds_mad').val('iscsi');
|
||||
$('select#ds_mad').attr('disabled', 'disabled');
|
||||
$('select#tm_mad').val('iscsi');
|
||||
$('select#tm_mad').attr('disabled', 'disabled');
|
||||
$('label[for="bridge_list"],input#bridge_list').parent().parent().fadeIn();
|
||||
$('label[for="base_iqn"],input#base_iqn').fadeIn();
|
||||
$('label[for="vg_name"],input#vg_name').fadeIn();
|
||||
$('select#disk_type').children('option').each(function() {
|
||||
var value_str = $(this).val();
|
||||
$(this).attr('disabled', 'disabled');
|
||||
if (value_str == "file" ||
|
||||
value_str == "block")
|
||||
{
|
||||
$(this).removeAttr('disabled');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function select_ceph(){
|
||||
$('select#ds_mad').val('ceph');
|
||||
$('select#ds_mad').attr('disabled', 'disabled');
|
||||
|
@ -1,118 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
|
||||
# #
|
||||
# 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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
# clone fe:SOURCE host:remote_system_ds/disk.i size vmid dsid
|
||||
# - fe is the front-end hostname
|
||||
# - SOURCE is the path of the disk image in the form DS_BASE_PATH/disk
|
||||
# - host is the target host to deploy the VM
|
||||
# - remote_system_ds is the path for the system datastore in the host
|
||||
# - vmid is the id of the VM
|
||||
# - dsid is the target datastore (0 is the system datastore)
|
||||
|
||||
SRC=$1
|
||||
DST=$2
|
||||
|
||||
VMID=$3
|
||||
DSID=$4
|
||||
|
||||
if [ -z "${ONE_LOCATION}" ]; then
|
||||
TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
|
||||
else
|
||||
TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
|
||||
fi
|
||||
|
||||
DRIVER_PATH=$(dirname $0)
|
||||
|
||||
. $TMCOMMON
|
||||
|
||||
source ${DRIVER_PATH}/../../datastore/iscsi/iscsi.conf
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Set src, dst path and dir
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
TARGET=`arg_path $SRC`
|
||||
|
||||
DST_PATH=`arg_path $DST`
|
||||
DST_HOST=`arg_host $DST`
|
||||
DST_DIR=`dirname $DST_PATH`
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# IQN and TARGETs
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
IQN=$SRC
|
||||
NEW_IQN=$IQN-$VMID
|
||||
|
||||
VG_NAME=`echo $TARGET|$AWK -F. '{print $(NF-1)}'`
|
||||
LV_NAME=`echo $TARGET|$AWK -F. '{print $(NF)}'`
|
||||
SOURCE_DEV="/dev/$VG_NAME/$LV_NAME"
|
||||
|
||||
TARGET_LV_NAME=`echo $LV_NAME-$VMID`
|
||||
TARGET_DEV="/dev/${VG_NAME}/${TARGET_LV_NAME}"
|
||||
TARGET_HOST="${TARGET%.$VG_NAME.$LV_NAME}"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Clone script
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
CLONE_CMD=$(cat <<EOF
|
||||
set -e
|
||||
|
||||
# get size
|
||||
SIZE=\$($SUDO $LVS --noheadings -o lv_size "$SOURCE_DEV")
|
||||
|
||||
# create lv
|
||||
$SUDO $LVCREATE -L\${SIZE} ${VG_NAME} -n ${TARGET_LV_NAME}
|
||||
|
||||
# clone lv with dd
|
||||
$SUDO $DD if=$SOURCE_DEV of=$TARGET_DEV bs=2M
|
||||
|
||||
# new iscsi target
|
||||
$SUDO $(tgt_setup_lun "$NEW_IQN" "$TARGET_DEV")
|
||||
$SUDO $(tgt_admin_dump_config "$TARGET_CONF")
|
||||
EOF
|
||||
)
|
||||
|
||||
ssh_exec_and_log "$TARGET_HOST" "$CLONE_CMD" \
|
||||
"Error cloning $DST_HOST:$TARGET_DEV"
|
||||
|
||||
LINK_CMD=$(cat <<EOF
|
||||
set -e
|
||||
|
||||
# discover and login
|
||||
mkdir -p $DST_DIR
|
||||
$SUDO $(iscsiadm_discovery "$TARGET_HOST")
|
||||
$SUDO $(iscsiadm_login "$NEW_IQN" "$TARGET_HOST")
|
||||
|
||||
# poll
|
||||
while [ ! -L /dev/disk/by-path/*$NEW_IQN-lun-1 ]; do
|
||||
sleep 1
|
||||
done
|
||||
|
||||
# link
|
||||
DISK_BY_PATH=\$(ls /dev/disk/by-path/*$NEW_IQN-lun-1)
|
||||
ln -s "\$DISK_BY_PATH" "$DST_PATH"
|
||||
DISK_DEVNAME=\$(readlink -f \$DISK_BY_PATH | awk -F'/' '{ print \$NF }')
|
||||
EOF
|
||||
)
|
||||
|
||||
ssh_exec_and_log "$DST_HOST" "$LINK_CMD" \
|
||||
"Error linking $NEW_IQN in $DST_HOST"
|
||||
|
||||
exit 0
|
@ -1,92 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
|
||||
# #
|
||||
# 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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
# mvds host:remote_system_ds/disk.i fe:SOURCE
|
||||
# - fe is the front-end hostname
|
||||
# - SOURCE is the path of the disk image in the form DS_BASE_PATH/disk
|
||||
# - host is the target host to deploy the VM
|
||||
# - remote_system_ds is the path for the system datastore in the host
|
||||
# - vmid is the id of the VM
|
||||
# - dsid is the target datastore (0 is the system datastore)
|
||||
|
||||
SRC=$1
|
||||
DST=$2
|
||||
|
||||
VMID=$3
|
||||
DSID=$4
|
||||
|
||||
if [ -z "${ONE_LOCATION}" ]; then
|
||||
TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
|
||||
else
|
||||
TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
|
||||
fi
|
||||
|
||||
DRIVER_PATH=$(dirname $0)
|
||||
|
||||
. $TMCOMMON
|
||||
|
||||
source ${DRIVER_PATH}/../../datastore/iscsi/iscsi.conf
|
||||
|
||||
SRC_HOST=`arg_host $SRC`
|
||||
NEW_IQN="$DST"
|
||||
|
||||
DISK_ID=$(echo $SRC|awk -F. '{print $NF}')
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Get image information
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin"
|
||||
|
||||
unset i j XPATH_ELEMENTS
|
||||
|
||||
while IFS= read -r -d '' element; do
|
||||
XPATH_ELEMENTS[i++]="$element"
|
||||
done < <(onevm show -x $VMID| $XPATH \
|
||||
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/SOURCE \
|
||||
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/SAVE_AS \
|
||||
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/PERSISTENT)
|
||||
|
||||
IQN="${XPATH_ELEMENTS[j++]}"
|
||||
SAVE_AS="${XPATH_ELEMENTS[j++]}"
|
||||
PERSISTENT="${XPATH_ELEMENTS[j++]}"
|
||||
|
||||
if [ -z "$PERSISTENT" ]; then
|
||||
IQN=$IQN-$VMID
|
||||
fi
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# IQN and TARGETs
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
LV_NAME=`echo $IQN|$AWK -F. '{print $(NF)}'`
|
||||
VG_NAME=`echo $IQN|$AWK -F. '{print $(NF-1)}'`
|
||||
SOURCE_DEV="/dev/$VG_NAME/$LV_NAME"
|
||||
|
||||
TARGET=`arg_path $IQN`
|
||||
TARGET_LV_NAME=`echo $NEW_IQN|$AWK -F. '{print $(NF)}'`
|
||||
TARGET_DEV="/dev/$VG_NAME/$TARGET_LV_NAME"
|
||||
TARGET_HOST="${TARGET%.$VG_NAME.$LV_NAME}"
|
||||
|
||||
CLONE_CMD=$(cat <<EOF
|
||||
$SUDO $DD if=$SOURCE_DEV of=$TARGET_DEV bs=2M
|
||||
EOF
|
||||
)
|
||||
|
||||
ssh_exec_and_log "$TARGET_HOST" "$CLONE_CMD" \
|
||||
"Error cloning $DST_HOST:$TARGET_DEV"
|
@ -1,133 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
|
||||
# #
|
||||
# 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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
# DELETE <host:remote_system_ds/disk.i|host:remote_system_ds/> vmid dsid
|
||||
# - host is the target host to deploy the VM
|
||||
# - remote_system_ds is the path for the system datastore in the host
|
||||
# - vmid is the id of the VM
|
||||
# - dsid is the target datastore (0 is the system datastore)
|
||||
|
||||
DST=$1
|
||||
|
||||
VMID=$2
|
||||
DSID=$3
|
||||
|
||||
if [ -z "${ONE_LOCATION}" ]; then
|
||||
TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
|
||||
else
|
||||
TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
|
||||
fi
|
||||
|
||||
. $TMCOMMON
|
||||
|
||||
DRIVER_PATH=$(dirname $0)
|
||||
|
||||
source ${DRIVER_PATH}/../../datastore/iscsi/iscsi.conf
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Return if deleting a disk, we will delete them when removing the
|
||||
# remote_system_ds directory for the VM (remotely)
|
||||
#-------------------------------------------------------------------------------
|
||||
DST_PATH=`arg_path $DST`
|
||||
DST_HOST=`arg_host $DST`
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Get IQN information
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
DISK_ID=$(echo "$DST_PATH" | $AWK -F. '{print $NF}')
|
||||
|
||||
XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin"
|
||||
|
||||
unset i j XPATH_ELEMENTS
|
||||
|
||||
while IFS= read -r -d '' element; do
|
||||
XPATH_ELEMENTS[i++]="$element"
|
||||
done < <(onevm show -x $VMID| $XPATH \
|
||||
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/SOURCE \
|
||||
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/PERSISTENT)
|
||||
|
||||
IQN="${XPATH_ELEMENTS[j++]}"
|
||||
PERSISTENT="${XPATH_ELEMENTS[j++]}"
|
||||
|
||||
if [ -z "$PERSISTENT" ]; then
|
||||
NEW_IQN=$IQN-$VMID
|
||||
else
|
||||
NEW_IQN=$IQN
|
||||
fi
|
||||
|
||||
TARGET=`arg_path $IQN`
|
||||
VG_NAME=`echo $TARGET|$AWK -F. '{print $(NF-1)}'`
|
||||
LV_NAME=`echo $TARGET|$AWK -F. '{print $(NF)}'`
|
||||
DEV="/dev/$VG_NAME/$LV_NAME"
|
||||
TARGET_HOST="${TARGET%.$VG_NAME.$LV_NAME}"
|
||||
|
||||
TARGET_LV_NAME=`echo $NEW_IQN|$AWK -F. '{print $(NF)}'`
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Remove directory if dst_path is a directory
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
if [ `is_disk $DST_PATH` -eq 0 ]; then
|
||||
# Directory
|
||||
log "Deleting $DST_PATH"
|
||||
ssh_exec_and_log "$DST_HOST" "rm -rf $DST_PATH" "Error deleting $DST_PATH"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Logout from the iSCSI target in the hypervisor
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
LOGOUT_CMD=$(cat <<EOF
|
||||
set -e
|
||||
$SUDO $(iscsiadm_logout $NEW_IQN)
|
||||
EOF
|
||||
)
|
||||
|
||||
ssh_exec_and_log "$DST_HOST" "$LOGOUT_CMD" \
|
||||
"Error logging out $NEW_IQN"
|
||||
|
||||
if [ "$PERSISTENT" = "YES" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Remove target and LV in the iSCSI server
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
DELETE_CMD=$(cat <<EOF
|
||||
set -e
|
||||
# get tid for IQN
|
||||
TID=\$($SUDO $(tgtadm_get_tid_for_iqn "$NEW_IQN"))
|
||||
|
||||
# remove iscsi target
|
||||
$SUDO $(tgtadm_target_delete "\$TID")
|
||||
|
||||
# dump configuration
|
||||
$SUDO $(tgt_admin_dump_config "$TARGET_CONF")
|
||||
|
||||
# remove lv
|
||||
$SUDO $LVREMOVE -f $VG_NAME/$TARGET_LV_NAME
|
||||
EOF
|
||||
)
|
||||
|
||||
ssh_exec_and_log "$TARGET_HOST" "$DELETE_CMD" \
|
||||
"Error logging out $IQN"
|
||||
|
||||
exit 0
|
@ -1,83 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
|
||||
# #
|
||||
# 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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
# clone fe:SOURCE host:remote_system_ds/disk.i size vmid dsid
|
||||
# - fe is the front-end hostname
|
||||
# - SOURCE is the path of the disk image in the form DS_BASE_PATH/disk
|
||||
# - host is the target host to deploy the VM
|
||||
# - remote_system_ds is the path for the system datastore in the host
|
||||
# - vmid is the id of the VM
|
||||
# - dsid is the target datastore (0 is the system datastore)
|
||||
|
||||
SRC=$1
|
||||
DST=$2
|
||||
|
||||
VMID=$3
|
||||
DSID=$4
|
||||
|
||||
if [ -z "${ONE_LOCATION}" ]; then
|
||||
TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
|
||||
else
|
||||
TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
|
||||
fi
|
||||
|
||||
. $TMCOMMON
|
||||
|
||||
DRIVER_PATH=$(dirname $0)
|
||||
|
||||
source ${DRIVER_PATH}/../../datastore/iscsi/iscsi.conf
|
||||
#-------------------------------------------------------------------------------
|
||||
# Set dst path and dir
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
IQN=$SRC
|
||||
TARGET=`arg_path $SRC`
|
||||
DST_PATH=`arg_path $DST`
|
||||
DST_HOST=`arg_host $DST`
|
||||
DST_DIR=`dirname $DST_PATH`
|
||||
|
||||
BASE_IQN=`echo $IQN|$CUT -d: -f1`
|
||||
TARGET=`echo $IQN|$CUT -d: -f2`
|
||||
LV_NAME=`echo $TARGET|$AWK -F. '{print $(NF)}'`
|
||||
VG_NAME=`echo $TARGET|$AWK -F. '{print $(NF-1)}'`
|
||||
TARGET_DEV="/dev/$VG_NAME/$LV_NAME"
|
||||
TARGET_HOST=${TARGET%.$VG_NAME.$LV_NAME}
|
||||
|
||||
LINK_CMD=$(cat <<EOF
|
||||
set -e
|
||||
|
||||
# discover and login
|
||||
mkdir -p $DST_DIR
|
||||
$SUDO $(iscsiadm_discovery "$TARGET_HOST")
|
||||
$SUDO $(iscsiadm_login "$IQN" "$TARGET_HOST")
|
||||
|
||||
# poll
|
||||
while [ ! -L /dev/disk/by-path/*$IQN-lun-1 ]; do
|
||||
sleep 1
|
||||
done
|
||||
|
||||
# link
|
||||
DISK_BY_PATH=\$(ls /dev/disk/by-path/*$IQN-lun-1)
|
||||
ln -s "\$DISK_BY_PATH" "$DST_PATH"
|
||||
EOF
|
||||
)
|
||||
|
||||
ssh_exec_and_log "$DST_HOST" "$LINK_CMD" \
|
||||
"Error linking $DST_HOST:$TARGET_DEV"
|
||||
|
||||
exit 0
|
@ -1,142 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
|
||||
# #
|
||||
# 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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
# MV <hostA:system_ds/disk.i|hostB:system_ds/disk.i> vmid dsid
|
||||
# <hostA:system_ds/|hostB:system_ds/>
|
||||
# - hostX is the target host to deploy the VM
|
||||
# - system_ds is the path for the system datastore in the host
|
||||
# - vmid is the id of the VM
|
||||
# - dsid is the target datastore (0 is the system datastore)
|
||||
|
||||
SRC=$1
|
||||
DST=$2
|
||||
|
||||
VMID=$3
|
||||
DSID=$4
|
||||
|
||||
if [ -z "${ONE_LOCATION}" ]; then
|
||||
TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
|
||||
else
|
||||
TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
|
||||
fi
|
||||
|
||||
. $TMCOMMON
|
||||
|
||||
DRIVER_PATH=$(dirname $0)
|
||||
|
||||
source ${DRIVER_PATH}/../../datastore/iscsi/iscsi.conf
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Return if moving a disk, we will move them when moving the whole system_ds
|
||||
# directory for the VM
|
||||
#-------------------------------------------------------------------------------
|
||||
SRC_PATH=`arg_path $SRC`
|
||||
DST_PATH=`arg_path $DST`
|
||||
|
||||
SRC_HOST=`arg_host $SRC`
|
||||
DST_HOST=`arg_host $DST`
|
||||
|
||||
DST_DIR=`dirname $DST_PATH`
|
||||
|
||||
if [ `is_disk $SRC_PATH` -eq 0 ]; then
|
||||
ssh_make_path $DST_HOST $DST_DIR
|
||||
|
||||
log "Moving $SRC to $DST"
|
||||
|
||||
exec_and_log "$SCP -r $SRC $DST" "Could not copy $SRC to $DST"
|
||||
|
||||
ssh_exec_and_log "$SRC_HOST" "rm -rf $SRC_PATH" \
|
||||
"Could not remove $SRC_HOST:$SRC_PATH"
|
||||
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$SRC" == "$DST" ]; then
|
||||
log "Not moving $SRC to $DST, they are the same path"
|
||||
exit 0
|
||||
fi
|
||||
#-------------------------------------------------------------------------------
|
||||
# Get image information
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin"
|
||||
|
||||
unset i j XPATH_ELEMENTS
|
||||
|
||||
DISK_ID=$(echo "$SRC_PATH" | $AWK -F. '{print $NF}')
|
||||
|
||||
while IFS= read -r -d '' element; do
|
||||
XPATH_ELEMENTS[i++]="$element"
|
||||
done < <(onevm show -x $VMID| $XPATH \
|
||||
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/SOURCE \
|
||||
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/PERSISTENT)
|
||||
|
||||
IQN="${XPATH_ELEMENTS[j++]}"
|
||||
PERSISTENT="${XPATH_ELEMENTS[j++]}"
|
||||
|
||||
if [ -z "$PERSISTENT" ]; then
|
||||
IQN=$IQN-$VMID
|
||||
fi
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Start actions
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
if is_iscsi "$SRC_HOST"; then
|
||||
log "Logging out of $IQN in $SRC_HOST"
|
||||
|
||||
LOGOUT_CMD=$(cat <<EOF
|
||||
set -e
|
||||
$SUDO $(iscsiadm_logout "$IQN")
|
||||
EOF
|
||||
)
|
||||
ssh_exec_and_log "$SRC_HOST" "$LOGOUT_CMD" \
|
||||
"Error logging out $SRC_HOST:$SRC_PATH ($IQN)"
|
||||
fi
|
||||
|
||||
if is_iscsi "$DST_HOST"; then
|
||||
log "Logging in to $IQN in $SRC_HOST"
|
||||
|
||||
TARGET_HOST=$(iqn_get_host "$IQN")
|
||||
|
||||
LINK_CMD=$(cat <<EOF
|
||||
set -e
|
||||
|
||||
# discover and login
|
||||
mkdir -p $DST_DIR
|
||||
$SUDO $(iscsiadm_discovery "$TARGET_HOST")
|
||||
$SUDO $(iscsiadm_login "$IQN" "$TARGET_HOST")
|
||||
|
||||
# poll
|
||||
while [ ! -L /dev/disk/by-path/*$IQN-lun-1 ]; do
|
||||
sleep 1
|
||||
done
|
||||
|
||||
# link
|
||||
DISK_BY_PATH=\$(ls /dev/disk/by-path/*$IQN-lun-1)
|
||||
ln -sf "\$DISK_BY_PATH" "$DST_PATH"
|
||||
EOF
|
||||
)
|
||||
|
||||
ssh_exec_and_log "$DST_HOST" "$LINK_CMD" \
|
||||
"Error linking to $DISK_BY_PATH $DST_PATH"
|
||||
|
||||
|
||||
fi
|
||||
|
||||
exit 0
|
@ -1,119 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
|
||||
# #
|
||||
# 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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
# mvds host:remote_system_ds/disk.i fe:SOURCE
|
||||
# - fe is the front-end hostname
|
||||
# - SOURCE is the path of the disk image in the form DS_BASE_PATH/disk
|
||||
# - host is the target host to deploy the VM
|
||||
# - remote_system_ds is the path for the system datastore in the host
|
||||
# - vmid is the id of the VM
|
||||
# - dsid is the target datastore (0 is the system datastore)
|
||||
|
||||
SRC=$1
|
||||
DST=$2
|
||||
|
||||
VMID=$3
|
||||
DSID=$4
|
||||
|
||||
if [ -z "${ONE_LOCATION}" ]; then
|
||||
TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
|
||||
else
|
||||
TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
|
||||
fi
|
||||
|
||||
DRIVER_PATH=$(dirname $0)
|
||||
|
||||
. $TMCOMMON
|
||||
|
||||
source ${DRIVER_PATH}/../../datastore/iscsi/iscsi.conf
|
||||
|
||||
SRC_HOST=`arg_host $SRC`
|
||||
NEW_IQN="$DST"
|
||||
|
||||
DISK_ID=$(echo $SRC|awk -F. '{print $NF}')
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Get image information
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin"
|
||||
|
||||
unset i j XPATH_ELEMENTS
|
||||
|
||||
while IFS= read -r -d '' element; do
|
||||
XPATH_ELEMENTS[i++]="$element"
|
||||
done < <(onevm show -x $VMID| $XPATH \
|
||||
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/SOURCE \
|
||||
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/SAVE_AS \
|
||||
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/PERSISTENT)
|
||||
|
||||
IQN="${XPATH_ELEMENTS[j++]}"
|
||||
SAVE_AS="${XPATH_ELEMENTS[j++]}"
|
||||
PERSISTENT="${XPATH_ELEMENTS[j++]}"
|
||||
|
||||
if [ -z "$PERSISTENT" ]; then
|
||||
IQN=$IQN-$VMID
|
||||
fi
|
||||
|
||||
log "Logging out $IQN"
|
||||
|
||||
LOGOUT_CMD=$(cat <<EOF
|
||||
set -e
|
||||
$SUDO $(iscsiadm_logout "$IQN")
|
||||
EOF
|
||||
)
|
||||
|
||||
ssh_exec_and_log "$SRC_HOST" "$LOGOUT_CMD" \
|
||||
"Error logging out $IQN"
|
||||
|
||||
# Exit if not save_as. We are finished if this was a persistent image.
|
||||
[ -z "$SAVE_AS" ] && exit 0
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# IQN and TARGETs
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
LV_NAME=`echo $IQN|$AWK -F. '{print $(NF)}'`
|
||||
VG_NAME=`echo $IQN|$AWK -F. '{print $(NF-1)}'`
|
||||
SOURCE_DEV="/dev/$VG_NAME/$LV_NAME"
|
||||
|
||||
TARGET=`arg_path $IQN`
|
||||
TARGET_LV_NAME=`echo $NEW_IQN|$AWK -F. '{print $(NF)}'`
|
||||
TARGET_DEV="/dev/$VG_NAME/$TARGET_LV_NAME"
|
||||
TARGET_HOST="${TARGET%.$VG_NAME.$LV_NAME}"
|
||||
|
||||
CLONE_CMD=$(cat <<EOF
|
||||
set -e
|
||||
|
||||
# clone lv with dd
|
||||
$SUDO $DD if=$SOURCE_DEV of=$TARGET_DEV bs=2M
|
||||
|
||||
# remove if source_dev is not persistent
|
||||
if [ -z "$PERSISTENT" ]; then
|
||||
TID=\$($SUDO $(tgtadm_get_tid_for_iqn "$IQN"))
|
||||
|
||||
$SUDO $(tgtadm_target_delete "\$TID")
|
||||
$SUDO $SYNC
|
||||
$SUDO $LVREMOVE -f $VG_NAME/$LV_NAME
|
||||
$SUDO $(tgt_admin_dump_config "$TARGET_CONF")
|
||||
fi
|
||||
EOF
|
||||
)
|
||||
|
||||
ssh_exec_and_log "$TARGET_HOST" "$CLONE_CMD" \
|
||||
"Error cloning $DST_HOST:$TARGET_DEV or removing nonpersistent $IQN"
|
@ -1 +0,0 @@
|
||||
../common/postmigrate
|
@ -1 +0,0 @@
|
||||
../common/premigrate
|
Loading…
Reference in New Issue
Block a user