tm_mv.sh

Marco Gomes, 21 Mar 2012 12:36

Download (2.96 KB)

 
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
    LVMRC=/etc/one/tm_lvm/tm_lvmrc
25
else
26
    TMCOMMON=$ONE_LOCATION/lib/mads/tm_common.sh
27
    LVMRC=$ONE_LOCATION/etc/tm_lvm/tm_lvmrc
28
fi
29

    
30
. $TMCOMMON
31
. $LVMRC
32

    
33
SRC_PATH=`arg_path $SRC`
34
DST_PATH=`arg_path $DST`
35

    
36
SRC_HOST=`arg_host $SRC`
37
DST_HOST=`arg_host $DST`
38

    
39
DST_DIR=`dirname $DST_PATH`
40

    
41
VID=`get_vid $SRC_PATH`
42

    
43
# Check that we are not stopping, migrating or resuming
44
if echo `basename $SRC_PATH`|grep -vq '^disk'; then
45
    log_error "This TM does not support stop, migrating or resuming."
46
    exit 1
47
fi
48

    
49
    log "Retrieving iSCSI information"
50
    SCSI_DEVICE=$($SSH $SRC_HOST $MOUNT | $GREP $SRC_PATH | $AWK '{ print $1 }' | $CUT -d \"/\" -f3)
51
    ISCSI_TARGET=$($LS -l /dev/disk/by-path | $GREP $SCSI_DEVICE | $AWK \'{ print $8 }\' | $AWK -F \"-iscsi-\" \'{ print $2 }\' | $AWK -F \"-lun-\" \'{ print $1 }\')
52
    ISCSI_HOST=$($LS -l /dev/disk/by-path | $GREP $SCSI_DEVICE | $AWK \'{ print $8 }\' | $AWK -F \"-iscsi-\" \'{ print $1 }\' | $CUT -d \"-\" -f2)
53
    
54
    log "Unmounting and excluding iSCSI Disk"
55
    exec_and_log "$SSH $SRC_HOST $SUDO $UMOUNT $SRC_PATH"
56
    exec_and_log "$SSH $SRC_HOST rm -rf $SRC_PATH"
57

    
58
    log "Logging out iSCSI device"
59
    exec_and_log "$SSH $SRC_HOST $SUDO $ISCSIADM -m node --targetname \"$ISCSI_TARGET\" --portal \"$ISCSI_HOST\" --logout"
60

    
61
    log "Initiating iscsi target"
62
    exec_and_log "$SSH $DST_HOST $SUDO $ISCSIADM -m node --targetname \"$ISCSI_TARGET\" --portal \"$ISCSI_HOST\" --login"
63
    
64
    log "Mounting the iscsi device"
65
    exec_and_log "$SSH $DST_HOST $SUDO $MOUNT /dev/disk/by-path/ip-$(echo $ISCSI_HOST | $CUT -d \":\" -f1)\:$(echo $ISCSI_HOST | $CUT -d \":\" -f2)-iscsi-$(echo $ISCSI_TARGET | $CUT -d \":\" -f1)\:$(echo $ISCSI_TARGET | $CUT -d \":\" -f2)-lun-0-part1 $DST_PATH"