|
1
|
#!/bin/bash
|
|
2
|
|
|
3
|
# -------------------------------------------------------------------------- #
|
|
4
|
# Copyright 2002-2011, 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
|
SRC=$1
|
|
20
|
DST=$2
|
|
21
|
|
|
22
|
if [ -z "${ONE_LOCATION}" ]; then
|
|
23
|
TMCOMMON=/usr/lib/one/mads/tm_common.sh
|
|
24
|
ISCSIRC=/etc/one/tm_iscsi/tm_iscsirc
|
|
25
|
else
|
|
26
|
TMCOMMON=$ONE_LOCATION/lib/mads/tm_common.sh
|
|
27
|
ISCSIRC=$ONE_LOCATION/etc/tm_iscsi/tm_iscsirc
|
|
28
|
fi
|
|
29
|
|
|
30
|
. $TMCOMMON
|
|
31
|
. $ISCSIRC
|
|
32
|
|
|
33
|
SRC_PATH=`arg_path $SRC`
|
|
34
|
SRC_HOST=`arg_host $SRC`
|
|
35
|
|
|
36
|
VID=`get_vid $SRC_PATH`
|
|
37
|
|
|
38
|
log "Retrieving iSCSI information"
|
|
39
|
SCSI_DEVICE=$($SSH $SRC_HOST $LS -l $SRC_PATH | $GREP dev | $AWK '{ print $10 }' | $CUT -d "/" -f5)
|
|
40
|
for i in $SCSI_DEVICE
|
|
41
|
do
|
|
42
|
ISCSI_TARGET=$($ECHO $i | $AWK -F "-iscsi-" '{ print $2 }' | $AWK -F "-lun-" '{ print $1 }')
|
|
43
|
ISCSI_HOST=$($ECHO $i | $AWK -F "-iscsi-" '{ print $1 }' | $CUT -d "-" -f2)
|
|
44
|
exec_and_log "$SSH $SRC_HOST $SUDO $ISCSIADM -m node --targetname \"$ISCSI_TARGET\" --portal \"$ISCSI_HOST\" --logout"
|
|
45
|
exec_and_log "$SSH $STORAGE_HOST $SUDO $ISCSIRM $ISCSI_TARGET"
|
|
46
|
exec_and_log "$SSH $STORAGE_HOST $SUDO $LVREMOVE -f $($ECHO $VG_NAME/$($ECHO $ISCSI_TARGET | $CUT -d ":" -f2))"
|
|
47
|
done
|
|
48
|
|
|
49
|
log "Deleting $SRC_PATH"
|
|
50
|
exec_and_log "$SSH $SRC_HOST rm -rf $SRC_PATH"
|
|
51
|
|