tm_lvmssh-issue1240.patch

Nicolas AGIUS, 04/20/2012 05:09 PM

Download (32.3 KB)

View differences:

install.sh
872 872

  
873 873
ETC_FILES="share/etc/oned.conf \
874 874
           share/etc/defaultrc \
875
           share/etc/tm_lvmsshrc \
875 876
           src/scheduler/etc/sched.conf \
876 877
           src/cli/etc/group.default"
877 878

  
share/etc/tm_lvmsshrc
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
# -------------------------------------------------------------------------- #
18

  
19
# Volume Group to create logical volumes
20
VG_NAME="LVM_XEN"
21

  
22
# Prefix for each logical volume
23
LV_PREFIX="lv-one"
24

  
25
# Default size for logical volumes if not specified
26
DEFAULT_LV_SIZE="6G"
27

  
28
# Type of images to store in the filesystem datastore
29
#
30
# Could be TGZ, GZIP or RAW. Default: RAW
31
#  - RAW : raw image is dumped into the lv
32
#  - GZIP : raw image is (un)gzipped before dump
33
#  - TGZ : image is a gzipped tarball extracted in a new filesystem
34
# 
35
# If you use TGZ, the LV  contain a filesystem (not a disk) and you 
36
# have to specify the TARGET device in the image template.
37
# Ex : TARGET=xvda1
38
MODE="RAW"
39

  
40
# Compression level for TGZ and GZIP copy mode
41
COMPRESS_LEVEL="1"
42

  
43
# Block size used by dd
44
BLOCK_SIZE="64k"
45

  
46
# Default filesystem type for logical volumes if TGZ mode is used
47
DEFAULT_FSTYPE="ext3"
48

  
49
# -------------------------------------------------------------------------- #
50
# Helper functions for the LVM plugin                                        #
51
# -------------------------------------------------------------------------- #
52

  
53
function get_vid 
54
{
55
    [[ $1 =~ datastores/[0-9]+/([0-9]+)/ ]] && echo ${BASH_REMATCH[1]}
56
}
57

  
58
function get_lv_name 
59
{
60
    VID=`get_vid $1`
61
    DISK=`echo $1|$AWK -F. '{printf $NF}'`
62
    echo "${LV_PREFIX}-${VID}-${DISK}"
63
}
64

  
65
function send_rawfile_to_lv
66
{
67
    local DST_HOST=$1
68
    local FILE=$2
69
    local LV_NAME=$3
70

  
71
    exec_and_log "eval cat $FILE | $SSH $DST_HOST $SUDO $DD of=/dev/$VG_NAME/$LV_NAME bs=$BLOCK_SIZE"
72
}
73

  
74
function send_gzipfile_to_lv
75
{
76
    local DST_HOST=$1
77
    local FILE=$2
78
    local LV_NAME=$3
79

  
80
    exec_and_log "eval cat $FILE | $SSH $DST_HOST '$GZIP -d | $SUDO $DD of=/dev/$VG_NAME/$LV_NAME bs=$BLOCK_SIZE'"
81
}
82

  
83
function send_tgzfile_to_lv
84
{
85
    local HOST=$1
86
    local FILE=$2
87
    local LV_NAME=$3
88
    local FSTYPE=${4:-$DEFAULT_FSTYPE}
89

  
90
    local TMP_DIR=$($SSH $HOST $SUDO mktemp -d)
91
    exec_and_log "eval $SSH $HOST '$SUDO $(mkfs_command /dev/$VG_NAME/$LV_NAME $FSTYPE) && $SUDO mount /dev/$VG_NAME/$LV_NAME $TMP_DIR'"
92
    exec_and_log "eval cat $FILE | $SSH $HOST '$SUDO $TAR -xzf - -C $TMP_DIR'"
93
    exec_and_log "eval $SSH $HOST '$SUDO umount $TMP_DIR && $SUDO rmdir $TMP_DIR'"
94
}
95

  
96
function get_rawfile_from_lv
97
{
98
    local HOST=$1
99
    local FILE=$2
100
    local LV=$3
101

  
102
    exec_and_log "eval $SSH $HOST $SUDO $DD if=$LV bs=$BLOCK_SIZE | cat - >$FILE"
103
}
104

  
105
function get_gzipfile_from_lv
106
{
107
    local HOST=$1
108
    local FILE=$2
109
    local LV=$3
110

  
111
    exec_and_log "eval $SSH $HOST '$SUDO $DD if=$LV bs=$BLOCK_SIZE | $GZIP -$COMPRESS_LEVEL ' | cat - >$FILE"
112
}
113

  
114
function get_tgzfile_from_lv
115
{
116
    local HOST=$1
117
    local FILE=$2
118
    local LV=$3
119

  
120
    TMP_DIR=$($SSH $HOST $SUDO mktemp -d)
121
    exec_and_log "$SSH $HOST $SUDO mount $LV $TMP_DIR"
122
    exec_and_log "eval $SSH $HOST '$SUDO $TAR -cf - -C $TMP_DIR . | $GZIP -$COMPRESS_LEVEL ' | cat - >$FILE"
123
    exec_and_log "eval $SSH $HOST '$SUDO umount $TMP_DIR && $SUDO rmdir $TMP_DIR'"
124
}
125

  
126
function send_file_to_lv
127
{
128
    local HOST=$1
129
    local FILE=$2
130
    local LV_NAME=$3
131
    local FSTYPE=${4:-$DEFAULT_FSTYPE}
132

  
133
    MIME=$(file -b --mime-type $FILE)
134
    case "$MIME" in
135
        "application/x-gzip")
136
            INNER_MIME=$(file -bz --mime-type $FILE)
137
            case "$INNER_MIME" in
138
                "application/x-tar")
139
                    send_tgzfile_to_lv $HOST $FILE $LV_NAME $FSTYPE
140
                    ;;
141
                *)
142
                    send_gzipfile_to_lv $HOST $FILE $LV_NAME
143
                    ;;
144
            esac
145
            ;;
146
        *)
147
            send_rawfile_to_lv $HOST $FILE $LV_NAME
148
            ;;
149
    esac
150
}
151

  
152
function get_file_from_lv
153
{
154
    local HOST=$1
155
    local FILE=$2
156
    local LV=$3
157
    local TYPE=$4
158

  
159
    case "$MODE" in
160
        "TGZ")
161
            case "$TYPE" in
162
                "FS")
163
                    get_tgzfile_from_lv $HOST $FILE $LV
164
                    ;;
165
                *)
166
                    get_gzipfile_from_lv $HOST $FILE $LV
167
                    ;;
168
            esac
169
            ;;
170
        "GZIP")
171
            get_gzipfile_from_lv $HOST $FILE $LV
172
            ;;
173
        *)
174
            get_rawfile_from_lv $HOST $FILE $LV
175
            ;;
176
    esac
177
}
178

  
179
function get_disk
180
{
181
    local SRC_HOST=$1
182
    local SRC_PATH=$2
183
    local DST_PATH=$3
184

  
185
    # Retrieve informations on logical volume
186
    read TYPE LV FSTYPE DUMMY < <(echo "
187
        LV=\$(readlink $SRC_PATH)
188
        MIME=\$(sudo file -bsL --mime-type \$LV)
189
        case \"\$MIME\" in
190
            \"application/octet-stream\")
191
                # This is a filesystem, try to detect the type
192
                TMP_DIR=\$(mktemp -d)
193
                sudo mount \$LV \$TMP_DIR 2>/dev/null
194
                if [ \$? -eq 0 ]; then
195
                    FSTYPE=\$(grep \$TMP_DIR /proc/mounts | awk {'print \$3'})
196
                    echo \"FS \$LV \$FSTYPE\"
197
                    sudo umount \$TMP_DIR
198
                else
199
                    echo \"RAW \$LV \"
200
                fi
201
                rmdir \$TMP_DIR
202
                ;;
203
            \"application/x-iso9660-image\")
204
                echo \"RAW \$LV \"
205
                ;;
206
            *)
207
                echo \"RAW \$LV \"
208
                ;;
209
        esac
210
    " | $SSH $SRC_HOST "$BASH -s")
211

  
212
    if [ "$?" != "0" ]; then
213
        log_error "Error retrieving LV informations."
214
        exit 1
215
    fi
216

  
217
    get_file_from_lv $SRC_HOST $DST_PATH $LV $TYPE
218
}
219

  
220
function get_all_disks
221
{
222
    local SRC_HOST=$1
223
    local SRC_PATH=$2
224
    local DST_PATH=$3
225
    local MAPFILE="$SRC_PATH/diskmap"
226

  
227
    # Retrieve informations on logical volumes
228
    echo "
229
        echo -e \"declare -a DISKS\nDISKS=(\" > $MAPFILE
230
        for DISK in \$(find $SRC_PATH -type l -regex '.*disk\.[0-9]+'); do
231
            LV=\$(readlink \$DISK)
232
            MIME=\$(sudo file -bsL --mime-type \$LV)
233
            SIZE=\$(sudo lvs -o lv_size \$LV --noheadings)
234
            case \"\$MIME\" in
235
                \"application/octet-stream\")
236
                    # This is a filesystem, try to detect the type
237
                    TMP_DIR=\$(mktemp -d)
238
                    sudo mount \$LV \$TMP_DIR 2>/dev/null
239
                    if [ \$? -eq 0 ]; then
240
                        FSTYPE=\$(grep \$TMP_DIR /proc/mounts | awk {'print \$3'})
241
                        echo \"\\\"FS \$DISK \$LV \$SIZE \$FSTYPE\\\"\" >>$MAPFILE
242
                        sudo umount \$TMP_DIR
243
                    else
244
                        echo \"\\\"RAW \$DISK \$LV \$SIZE\\\"\" >>$MAPFILE
245
                    fi
246
                    rmdir \$TMP_DIR
247
                    ;;
248
                \"application/x-iso9660-image\")
249
                    echo \"\\\"RAW \$DISK \$LV \$SIZE\\\"\" >>$MAPFILE
250
                    ;;
251
                *)
252
                    echo \"\\\"RAW \$DISK \$LV \$SIZE\\\"\" >>$MAPFILE
253
                    ;;
254
            esac
255
        done
256
        echo \")\" >> $MAPFILE
257
    " | $SSH $SRC_HOST "$BASH -s"
258

  
259
    if [ "$?" != "0" ]; then
260
        log_error "Error retrieving LV informations."
261
        exit 1
262
    fi
263

  
264
    # Transfert configuration files (will not transfert symlinks)
265
    exec_and_log "$RSYNC --compress-level=$COMPRESS_LEVEL -re ssh $SRC/* $DST_PATH"
266
    local MAPFILE="$DST_PATH/diskmap"
267

  
268
    # Dump logicals volume to file
269
    [ -r "$MAPFILE" ] || log_error "Cannot read diskmap : $MAPFILE"
270
    source $MAPFILE
271
    for DISK in "${DISKS[@]}"; do
272
        read TYPE NAME LV SIZE FSTYPE DUMMY < <(echo $DISK)
273
        get_file_from_lv $SRC_HOST $NAME $LV $TYPE
274
    done
275
}
276

  
277
function send_all_disks
278
{
279
    local SRC_PATH=$1
280
    local DST_HOST=$2
281
    local DST_PATH=$3
282
    local MAPFILE="$SRC_PATH/diskmap"
283

  
284
    # Send all fils but disks
285
    exec_and_log "$SCP -r $(ls $SRC_PATH -I disk.\* | xargs -I{} echo $SRC_PATH/{}) $DST_HOST:$DST_PATH"
286

  
287
    # Dump file to logical volumes
288
    [ -r "$MAPFILE" ] || log_error "Cannot read diskmap : $MAPFILE"
289
    source $MAPFILE
290
    for DISK in "${DISKS[@]}"; do
291
        read TYPE NAME LV SIZE FSTYPE DUMMY < <(echo $DISK)
292
        LV_NAME=$(basename $LV)
293

  
294
        # Create LV 
295
        log "Creating LV $LV_NAME"
296
        create_lv $DST_HOST $LV_NAME "$DST_PATH/$(basename $NAME)" $SIZE
297

  
298
        send_file_to_lv $DST_HOST $NAME $LV_NAME $FSTYPE
299
    done
300
}
301

  
302
function remove_lv
303
{
304
    local HOST=$1
305
    local FILE=$2
306

  
307
    local CMD=$(cat <<EOF
308
        set -e
309
        LV=\$(readlink $FILE)
310
        $SUDO $LVCHANGE -an \$LV
311
        $SUDO $LVREMOVE -f \$LV
312
        $SUDO rm -f $FILE
313
EOF
314
    )
315

  
316
    ssh_exec_and_log "$HOST" "$CMD" "Cannot remove LV $FILE"
317
}
318

  
319
function remove_all_lv
320
{
321
    local HOST=$1
322
    local DST_PATH=$2
323

  
324
    DISK_LIST=$($SSH $HOST "find $DST_PATH -type l -regex '.*disk\.[0-9]+'")
325

  
326
    if [ "$?" != "0" ]; then
327
        log_error "Error retrieving disks informations."
328
        exit 1
329
    fi
330

  
331
    for DISK in $DISK_LIST; do
332
        log "Deleting LV $DISK"
333
        remove_lv $HOST $DISK
334
    done
335
}
336

  
337
function create_lv
338
{
339
    local HOST=$1
340
    local LV_NAME=$2
341
    local FILE=$3
342
    local SIZE=${4:-$DEFAULT_LV_SIZE}
343

  
344
    local CMD=$(cat <<EOF
345
        set -e
346
        $SUDO $LVCREATE -L$SIZE -n $LV_NAME $VG_NAME
347
        ln -s /dev/$VG_NAME/$LV_NAME $FILE
348
EOF
349
    )
350

  
351
    ssh_exec_and_log "$HOST" "$CMD" "Cannot create LV $LV_NAME"
352
}
353

  
354
# EOF
src/mad/sh/scripts_common.sh
23 23
DD=dd
24 24
DU=du
25 25
GREP=grep
26
GZIP=gzip
26 27
ISCSIADM=iscsiadm
27 28
LVCREATE=lvcreate
28 29
LVREMOVE=lvremove
30
LVCHANGE=lvchange
29 31
LVS=lvs
30 32
LN=ln
31 33
MD5SUM=md5sum
......
34 36
MKSWAP=mkswap
35 37
QEMU_IMG=qemu-img
36 38
READLINK=readlink
39
RSYNC=rsync
37 40
SCP=scp
38 41
SED=sed
39 42
SSH=ssh
src/tm_mad/lvmssh/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
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

  
25
SRC=$1
26
DST=$2
27

  
28
# TODO get SIZE and FSTYPE from template
29
SIZE=""     # Empty stings: will take default values
30
FSTYPE=""
31

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

  
40
. $TMCOMMON
41
. $LVMRC
42

  
43
#-------------------------------------------------------------------------------
44
# Set dst path and dir
45
#-------------------------------------------------------------------------------
46

  
47
SRC_PATH=`arg_path $SRC`
48
DST_PATH=`arg_path $DST`
49
DST_HOST=`arg_host $DST`
50

  
51
DST_DIR=`dirname $DST_PATH`
52

  
53
LV_NAME=`get_lv_name $DST_PATH`
54

  
55
ssh_make_path $DST_HOST $DST_DIR
56

  
57
#-------------------------------------------------------------------------------
58
# Copy files to the remote host
59
#-------------------------------------------------------------------------------
60

  
61
log "Creating LV $LV_NAME"
62
create_lv $DST_HOST $LV_NAME $DST_PATH $SIZE
63

  
64
case $SRC in
65
http://*)
66
    log "Downloading $SRC into /dev/$VG_NAME/$LV_NAME"
67
    RMT_CMD="$WGET $SRC -q -O- | $SUDO $DD of=/dev/$VG_NAME/$LV_NAME bs=$BLOCK_SIZE"
68
    exec_and_log "eval $SSH $DST_HOST '$RMT_CMD'" "Error downloading $SRC"
69
    ;;
70

  
71
*)
72
    log "Dumping $SRC into /dev/$VG_NAME/$LV_NAME..."
73
    send_file_to_lv $DST_HOST $SRC_PATH $LV_NAME $FSTYPE
74
    ;;
75
esac
src/tm_mad/lvmssh/context
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
# context context.sh file1 file2 ... fileN host:remote_system_ds/disk.i
20
#   - context.sh file are the contents of the context ISO
21
#   - host is the target host to deploy the VM
22
#   - remote_system_ds is the path for the system datastore in the host
23

  
24
while (( "$#" )); do
25
    if [ "$#" == "1" ]; then
26
        DST=$1
27
    else
28
        SRC="$SRC $1"
29
    fi
30
    shift
31
done
32

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

  
41
. $TMCOMMON
42
. $LVMRC
43

  
44
#-------------------------------------------------------------------------------
45
# Set dst path and dirs
46
#-------------------------------------------------------------------------------
47
DST_PATH=`arg_path $DST`
48
DST_HOST=`arg_host $DST`
49
DST_DIR=`dirname $DST_PATH`
50

  
51
ssh_make_path $DST_HOST $DST_DIR
52

  
53
#-------------------------------------------------------------------------------
54
# Build the Context Block device (locally) and copy it remotely
55
#-------------------------------------------------------------------------------
56
log "Generating context block device at $DST"
57

  
58
VM_ID=`basename $DST_DIR`
59
ISO_DIR="$DS_DIR/.isofiles/$VM_ID"
60
ISO_FILE="$ISO_DIR/$VM_ID.iso"
61
LV_NAME=`get_lv_name $DST_PATH`
62

  
63
exec_and_log "mkdir -p $ISO_DIR" "Could not create tmp dir to make context dev"
64

  
65
for f in $SRC; do
66
    case $f in
67
    http://*)
68
        exec_and_log "$WGET -P $ISO_DIR $f" "Error downloading $f"
69
        ;;
70
    *)
71
        exec_and_log "cp -R $f $ISO_DIR" "Error copying $f to $ISO_DIR"
72
        ;;
73
    esac
74
done
75

  
76
exec_and_log "$MKISOFS -o $ISO_FILE -J -R $ISO_DIR" "Error creating iso fs"
77
SIZE="$(stat -c %s $TMP_DIR/$DST_FILE)B"
78

  
79
log "Creating LV $LV_NAME"
80
create_lv $DST_HOST $LV_NAME $DST_PATH $SIZE
81
exec_and_log "eval cat $ISO_FILE | $SSH $DST_HOST $SUDO $DD of=/dev/$VG_NAME/$LV_NAME bs=$BLOCK_SIZE"
82

  
83
rm -rf $ISO_DIR &>/dev/null
84

  
85
exit 0
src/tm_mad/lvmssh/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/>
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

  
23
DST=$1
24

  
25
if [ -z "${ONE_LOCATION}" ]; then
26
    TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
27
    LVMRC=/etc/one/tm_lvmsshrc
28
else
29
    TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
30
    LVMRC=$ONE_LOCATION/etc/tm_lvmsshrc
31
fi
32

  
33
. $TMCOMMON
34
. $LVMRC
35

  
36
DST_PATH=`arg_path $DST`
37
DST_HOST=`arg_host $DST`
38

  
39
if [ `is_disk $DST_PATH` -eq 1 ]; then
40
    # Disk
41
    log "Deleting LV $DST_PATH"
42
    remove_lv $DST_HOST $DST_PATH
43
else
44
    # Directory
45
    remove_all_lv $DST_HOST $DST_PATH
46

  
47
    log "Deleting directory $DST_PATH"
48
    ssh_exec_and_log $DST_HOST "$SUDO rm -rf $DST_PATH" "Error deleting $DST_PATH"
49
fi
50

  
51
exit 0
src/tm_mad/lvmssh/ln
1
clone
src/tm_mad/lvmssh/mkimage
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
# mkimage size format host:remote_system_ds/disk.i size
20
#   - size in MB of the image
21
#   - format for the image
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

  
25
SIZE=$1
26
FSTYPE=$2
27
DST=$3
28

  
29
if [ -z "${ONE_LOCATION}" ]; then
30
    TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
31
    LVMRC=/etc/one/tm_lvmsshrc
32
else
33
    TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
34
    LVMRC=$ONE_LOCATION/etc/tm_lvmsshrc
35
fi
36

  
37
. $TMCOMMON
38
. $LVMRC
39

  
40
#-------------------------------------------------------------------------------
41
# Set dst path and dir
42
#-------------------------------------------------------------------------------
43
DST_PATH=`arg_path $DST`
44
DST_HOST=`arg_host $DST`
45
DST_DIR=`dirname $DST_PATH`
46

  
47
ssh_make_path $DST_HOST $DST_DIR
48

  
49
#-------------------------------------------------------------------------------
50
# Make the new image (logical volume-based)
51
#-------------------------------------------------------------------------------
52
LV_NAME=`get_lv_name $DST_PATH`
53
FSTYPE=${FSTYPE:-$DEFAULT_FSTYPE}
54
MKFS_CMD=`mkfs_command /dev/$VG_NAME/$LV_NAME $FSTYPE $SIZE`
55

  
56
log "Making filesystem of ${SIZE}M and type $FSTYPE at $DST"
57

  
58
create_lv $DST_HOST $LV_NAME $DST_PATH $SIZE
59
ssh_exec_and_log $DST_HOST "$SUDO $MKFS_CMD" "Could not create LV /dev/$VG_NAME/$LV_NAME"
60

  
61
exit 0
src/tm_mad/lvmssh/mkswap
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
# mkswap size host:remote_system_ds/disk.i size
20
#   - size in MB of the image
21
#   - host is the target host to deploy the VM
22
#   - remote_system_ds is the path for the system datastore in the host
23

  
24
SIZE=$1
25
DST=$2
26

  
27
if [ -z "${ONE_LOCATION}" ]; then
28
    TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
29
    LVMRC=/etc/one/tm_lvmsshrc
30
else
31
    TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
32
    LVMRC=$ONE_LOCATION/etc/tm_lvmsshrc
33
fi
34

  
35
. $TMCOMMON
36
. $LVMRC
37

  
38
#-------------------------------------------------------------------------------
39
# Set dst path and dir
40
#-------------------------------------------------------------------------------
41

  
42
DST_PATH=`arg_path $DST`
43
DST_HOST=`arg_host $DST`
44

  
45
DST_DIR=`dirname $DST_PATH`
46

  
47
LV_NAME=`get_lv_name $DST_PATH`
48

  
49
ssh_make_path $DST_HOST $DST_DIR
50

  
51
#-------------------------------------------------------------------------------
52
# Create swap LV on the remote host
53
#-------------------------------------------------------------------------------
54

  
55
log "Creating LV $LV_NAME"
56
create_lv $DST_HOST $LV_NAME $DST_PATH $SIZE
57

  
58
log "Initializing swap space"
59
ssh_exec_and_log $DST_HOST "$SUDO $MKSWAP /dev/$VG_NAME/$LV_NAME"
60

  
61
exit 0
src/tm_mad/lvmssh/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>
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

  
24
SRC=$1
25
DST=$2
26

  
27
if [ -z "${ONE_LOCATION}" ]; then
28
    TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
29
    LVMRC=/etc/one/tm_lvmsshrc
30
else
31
    TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
32
    LVMRC=$ONE_LOCATION/etc/tm_lvmsshrc
33
fi
34

  
35
. $TMCOMMON
36
. $LVMRC
37

  
38
#-------------------------------------------------------------------------------
39
# Set dst path and dir
40
#-------------------------------------------------------------------------------
41
SRC_PATH=`arg_path $SRC`
42
DST_PATH=`arg_path $DST`
43

  
44
SRC_HOST=`arg_host $SRC`
45
DST_HOST=`arg_host $DST`
46

  
47
DST_DIR=`dirname $DST_PATH`
48

  
49
SRC_DS_DIR=`dirname  $SRC_PATH`
50
SRC_VM_DIR=`basename $SRC_PATH`
51

  
52
#-------------------------------------------------------------------------------
53
# Return if moving a disk, we will move them when moving the whole system_ds
54
# directory for the VM
55
#-------------------------------------------------------------------------------
56
if [ `is_disk $DST_PATH` -eq 1 ]; then
57
	exit 0
58
fi
59

  
60
if [ "$SRC" == "$DST" ]; then
61
    log "Not moving $SRC to $DST, they are the same path"
62
	exit 0
63
fi
64

  
65
ssh_exec_and_log "$DST_HOST" "rm -rf '$DST_PATH'" \
66
    "Error removing target path to prevent overwrite errors"
67

  
68
ssh_make_path "$DST_HOST" "$DST_PATH"
69

  
70
log "Moving $SRC to $DST"
71

  
72
if [ "$SRC_HOST" == "$HOSTNAME" ]; then
73
    # From frontend to host, SRC is localhost
74
    send_all_disks $SRC_PATH $DST_HOST $DST_PATH
75

  
76
    # Clean source
77
    exec_and_log "rm -rf $SRC_PATH"
78

  
79
elif [ "$DST_HOST" == "$HOSTNAME" ]; then
80
    # From host to frontend, DST is localhost
81
    get_all_disks $SRC_HOST $SRC_PATH $DST_PATH
82
    remove_all_lv $SRC_HOST $SRC_PATH
83

  
84
    # Clean source
85
    ssh_exec_and_log $SRC_HOST "rm -rf $SRC_PATH"
86

  
87
else
88
    log_error "MIGRATE not supported by this TM."
89
    exit 0
90
fi
91

  
92
exit 0
src/tm_mad/lvmssh/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

  
25
SRC=$1
26
DST=$2
27

  
28
if [ -z "${ONE_LOCATION}" ]; then
29
    TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
30
    LVMRC=/etc/one/tm_lvmsshrc
31
else
32
    TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
33
    LVMRC=$ONE_LOCATION/etc/tm_lvmsshrc
34
fi
35

  
36
. $TMCOMMON
37
. $LVMRC
38

  
39
set_ds_location
40

  
41
#-------------------------------------------------------------------------------
42
# Set dst path and dir
43
#-------------------------------------------------------------------------------
44
SRC_PATH=`arg_path $SRC`
45
DST_PATH=`arg_path $DST`
46

  
47
DST_PATH="$RMT_DS_DIR/${DST_PATH##"$DS_DIR/"}"
48

  
49
SRC_HOST=`arg_host $SRC`
50

  
51
#-------------------------------------------------------------------------------
52
# Move the image back to the datastore
53
#-------------------------------------------------------------------------------
54
log "Moving $SRC_PATH to datastore as $DST_PATH"
55
get_disk $SRC_HOST $SRC_PATH $DST_PATH
56

  
57
exit 0
0
-