Statistics
| Branch: | Tag: | Revision:

one / src / tm_mad / qcow2 / cpds @ 528dcb41

History | View | Annotate | Download (3.62 KB)

1
#!/bin/bash
2

    
3
# -------------------------------------------------------------------------- #
4
# Copyright 2002-2015, OpenNebula Project (OpenNebula.org), C12G Labs        #
5
#                                                                            #
6
# Licensed under the Apache License, Version 2.0 (the "License"); you may    #
7
# not use this file except in compliance with the License. You may obtain    #
8
# a copy of the License at                                                   #
9
#                                                                            #
10
# http://www.apache.org/licenses/LICENSE-2.0                                 #
11
#                                                                            #
12
# Unless required by applicable law or agreed to in writing, software        #
13
# distributed under the License is distributed on an "AS IS" BASIS,          #
14
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
15
# See the License for the specific language governing permissions and        #
16
# limitations under the License.                                             #
17
#--------------------------------------------------------------------------- #
18

    
19
# mvds host:remote_system_ds/disk.i fe:SOURCE snapid 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
#   - snapid is the snapshot id. "-1" for none
27

    
28
SRC=$1
29
DST=$2
30
SNAP_ID=$3
31
VMID=$4
32
DSID=$5
33

    
34
if [ -z "${ONE_LOCATION}" ]; then
35
    TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
36
else
37
    TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
38
fi
39

    
40
DRIVER_PATH=$(dirname $0)
41

    
42
. $TMCOMMON
43

    
44
#-------------------------------------------------------------------------------
45
# Get Image information
46
#-------------------------------------------------------------------------------
47

    
48
DISK_ID=$(basename ${SRC} | cut -d. -f2)
49

    
50
XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin"
51

    
52
unset i j XPATH_ELEMENTS
53

    
54
while IFS= read -r -d '' element; do
55
    XPATH_ELEMENTS[i++]="$element"
56
done < <(onevm show -x $VMID| $XPATH \
57
                    /VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/SOURCE \
58
                    /VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/CLONE)
59

    
60
DISK_SRC="${XPATH_ELEMENTS[j++]}"
61
CLONE="${XPATH_ELEMENTS[j++]}"
62

    
63
#-------------------------------------------------------------------------------
64
# Set dst path and dir
65
#-------------------------------------------------------------------------------
66
SRC_PATH=`arg_path $SRC`
67
SRC_HOST=`arg_host $SRC`
68
SRC_DIR=`dirname $SRC_PATH`
69

    
70
DST_ARG_PATH=`arg_path $DST`
71

    
72
SRC_DS_PATH="$(dirname $(dirname $(dirname $SRC_PATH)))"
73
DST_DS_PATH="$(dirname $(dirname $DST_ARG_PATH))"
74

    
75
DST_PATH="${SRC_DS_PATH}${DST_ARG_PATH##$DST_DS_PATH}"
76

    
77
if [ "$CLONE" != "YES" ]; then
78
    SRC_PATH="$DISK_SRC"
79
fi
80

    
81
if [ "$SNAP_ID" != "-1" ]; then
82
    SRC_PATH="$SRC_PATH.snap/$(($SNAP_ID+1))"
83
fi
84

    
85
#-------------------------------------------------------------------------------
86
# Move the image back to the datastore
87
#-------------------------------------------------------------------------------
88
CPSCRIPT=$(cat <<EOF
89
SRC_READLN=\$($READLINK -f $SRC_PATH)
90
DST_READLN=\$($READLINK -f $DST_PATH)
91

    
92
if [ \( -L $SRC_PATH \) -a \( "\$SRC_READLN" = "\$DST_READLN" \) ] ; then
93
    echo "Not moving files to image repo, they are the same"
94
else
95
    $QEMU_IMG convert $SRC_PATH -O qcow2 $DST_PATH
96
fi
97
EOF
98
)
99

    
100
log "Copying $SRC_PATH to datastore as $DST_PATH"
101

    
102
ssh_exec_and_log $SRC_HOST "$CPSCRIPT" "Could not move image $DST_PATH"
103

    
104
exit 0