tm_ssh_cache.patch

Krzysztof Pawlik, 05/23/2011 12:05 PM

Download (4.56 KB)

View differences:

install.sh
168 168
          $ETC_LOCATION/vmm_sh \
169 169
          $ETC_LOCATION/tm_nfs \
170 170
          $ETC_LOCATION/tm_ssh \
171
          $ETC_LOCATION/tm_ssh_cache \
171 172
          $ETC_LOCATION/tm_dummy \
172 173
          $ETC_LOCATION/tm_lvm \
173 174
          $ETC_LOCATION/hm \
......
184 185
          $LIB_LOCATION/tm_commands \
185 186
          $LIB_LOCATION/tm_commands/nfs \
186 187
          $LIB_LOCATION/tm_commands/ssh \
188
          $LIB_LOCATION/tm_commands/ssh_cache \
187 189
          $LIB_LOCATION/tm_commands/dummy \
188 190
          $LIB_LOCATION/tm_commands/lvm \
189 191
          $LIB_LOCATION/mads \
......
275 277
    VMM_SSH_GANGLIA_POLL:$LIB_LOCATION/remotes/vmm/xen/poll_local
276 278
    NFS_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/nfs
277 279
    SSH_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/ssh
280
    SSH_CACHE_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/ssh_cache
278 281
    DUMMY_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/dummy
279 282
    LVM_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/lvm
280 283
    EXAMPLE_SHARE_FILES:$SHARE_LOCATION/examples
......
330 333
    IM_EC2_ETC_FILES:$ETC_LOCATION/im_ec2
331 334
    TM_NFS_ETC_FILES:$ETC_LOCATION/tm_nfs
332 335
    TM_SSH_ETC_FILES:$ETC_LOCATION/tm_ssh
336
    TM_SSH_CACHE_ETC_FILES:$ETC_LOCATION/tm_ssh_cache
333 337
    TM_DUMMY_ETC_FILES:$ETC_LOCATION/tm_dummy
334 338
    TM_LVM_ETC_FILES:$ETC_LOCATION/tm_lvm
335 339
    HM_ETC_FILES:$ETC_LOCATION/hm
......
502 506
                           src/tm_mad/ssh/tm_mv.sh \
503 507
                           src/tm_mad/ssh/tm_context.sh"
504 508

  
509
SSH_CACHE_TM_COMMANDS_LIB_FILES="src/tm_mad/ssh_cache/tm_clone.sh"
510

  
505 511
DUMMY_TM_COMMANDS_LIB_FILES="src/tm_mad/dummy/tm_dummy.sh"
506 512

  
507 513
LVM_TM_COMMANDS_LIB_FILES="src/tm_mad/lvm/tm_clone.sh \
......
547 553
# Storage drivers config. files, to be installed under $ETC_LOCATION
548 554
#   - nfs, $ETC_LOCATION/tm_nfs
549 555
#   - ssh, $ETC_LOCATION/tm_ssh
556
#   - ssh_cache, $ETC_LOCATION/tm_ssh_cache
550 557
#   - dummy, $ETC_LOCATION/tm_dummy
551 558
#   - lvm, $ETC_LOCATION/tm_lvm
552 559
#-------------------------------------------------------------------------------
......
557 564
TM_SSH_ETC_FILES="src/tm_mad/ssh/tm_ssh.conf \
558 565
                  src/tm_mad/ssh/tm_sshrc"
559 566

  
567
TM_SSH_CACHE_ETC_FILES="src/tm_mad/ssh_cache/tm_ssh_cache.conf \
568
                  src/tm_mad/ssh_cache/tm_ssh_cacherc"
569

  
560 570
TM_DUMMY_ETC_FILES="src/tm_mad/dummy/tm_dummy.conf \
561 571
                    src/tm_mad/dummy/tm_dummyrc"
562 572

  
src/tm_mad/ssh_cache/tm_clone.sh
1
#!/bin/bash
2
# (C) 2011 Krzysztof Pawlik
3
# Grupa Onet.pl S.A.
4

  
5
MY_UNIQUE_ID="${$}-${RANDOM}"
6
CACHE_DIRECTORY="/nebula/image-cache"
7

  
8
SRC="${1}"
9
DST="${2}"
10

  
11
if [ -z "${ONE_LOCATION}" ]; then
12
    TMCOMMON="/usr/lib/one/mads/tm_common.sh"
13
else
14
    TMCOMMON="${ONE_LOCATION}/lib/mads/tm_common.sh"
15
fi
16

  
17
. "${TMCOMMON}"
18

  
19
SRC_PATH="$(arg_path "${SRC}")"
20
DST_PATH="$(arg_path "${DST}")"
21

  
22
SRC_HOST="$(arg_host "${SRC}")"		# Unused
23
DST_HOST="$(arg_host "${DST}")"
24

  
25
DST_DIR="$(dirname "${DST_PATH}")"
26

  
27
CACHED_IMAGE="${CACHE_DIRECTORY}/$(basename "${SRC_PATH}")"
28

  
29
exec_and_log "${SSH} ${DST_HOST} mkdir -p ${CACHE_DIRECTORY}"
30
exec_and_log "${SSH} ${DST_HOST} mkdir -p ${DST_DIR}"
31

  
32
local_size="$(stat --format="%s" "${SRC_PATH}")"
33
remote_size="$(${SSH} ${DST_HOST} stat --format="%s" ${CACHED_IMAGE} 2> /dev/null)"
34
[[ -n "${remote_size}" ]] || remote_size="0"
35
log "ssh_cache: remote_size=${remote_size} local_size=${local_size}"
36

  
37
if [[ "${remote_size}" -ne "${local_size}" ]]; then
38
	exec_and_log "${SCP} ${SRC} ${DST_HOST}:${CACHED_IMAGE}-${MY_UNIQUE_ID}"
39
	exec_and_log "${SSH} ${DST_HOST} chmod 666 ${CACHED_IMAGE}-${MY_UNIQUE_ID}"
40
	exec_and_log "${SSH} ${DST_HOST} mv -f ${CACHED_IMAGE}-${MY_UNIQUE_ID} ${CACHED_IMAGE}"
41
fi
42

  
43
exec_and_log "${SSH} ${DST_HOST} cp -a ${CACHED_IMAGE} ${DST_PATH}"
44

  
45
exit 0
src/tm_mad/ssh_cache/tm_ssh_cache.conf
1
CLONE   = ssh_cache/tm_clone.sh
2
LN      = ssh/tm_ln.sh
3
MKSWAP  = ssh/tm_mkswap.sh
4
MKIMAGE = ssh/tm_mkimage.sh
5
DELETE  = ssh/tm_delete.sh
6
MV      = ssh/tm_mv.sh
7
CONTEXT = ssh/tm_context.sh