Revision ade6513a src/market_mad/remotes/http/import

View differences:

src/market_mad/remotes/http/import
35 35
DRIVER_PATH=$(dirname $0)
36 36
source ${DRIVER_PATH}/../../datastore/libfs.sh
37 37

  
38
XPATH_PATH="${DRIVER_PATH}/../../datastore"
38
UTILS_PATH="${DRIVER_PATH}/../../datastore"
39 39

  
40 40
# -------- Get arguments from OpenNebula core ------------
41 41

  
42 42
DRV_ACTION=$1
43 43
ID=$2
44 44

  
45
XPATH="$XPATH_PATH/xpath.rb -b $DRV_ACTION"
45
XPATH="$UTILS_PATH/xpath.rb -b $DRV_ACTION"
46 46

  
47 47
unset i XPATH_ELEMENTS
48 48

  
49 49
while IFS= read -r -d '' element; do
50 50
    XPATH_ELEMENTS[i++]="$element"
51 51
done < <($XPATH     /MARKET_DRIVER_ACTION_DATA/IMPORT_SOURCE \
52
                    /MARKET_DRIVER_ACTION_DATA/FORMAT \
53
                    /MARKET_DRIVER_ACTION_DATA/DISPOSE \
54
                    /MARKET_DRIVER_ACTION_DATA/SIZE \
55
                    /MARKET_DRIVER_ACTION_DATA/CHECKSUM \
52 56
                    /MARKET_DRIVER_ACTION_DATA/MARKETPLACE/TEMPLATE/BASE_URL \
57
                    /MARKET_DRIVER_ACTION_DATA/MARKETPLACE/TEMPLATE/BRIDGE_LIST \
53 58
                    /MARKET_DRIVER_ACTION_DATA/MARKETPLACE/TEMPLATE/PUBLIC_DIR)
54 59
unset i
55 60

  
56 61
IMPORT_SOURCE="${XPATH_ELEMENTS[i++]}"
62
FORMAT="${XPATH_ELEMENTS[i++]}"
63
DISPOSE="${XPATH_ELEMENTS[i++]}"
64
SIZE="${XPATH_ELEMENTS[i++]}"
65
CHECKSUM="${XPATH_ELEMENTS[i++]}"
57 66
BASE_URL="${XPATH_ELEMENTS[i++]}"
67
BRIDGE_LIST="${XPATH_ELEMENTS[i++]}"
58 68
PUBLIC_DIR="${XPATH_ELEMENTS[i++]}"
59 69

  
60 70
# -------- Copy source to public folder an generarte App data ------------
......
63 73
DST_PATH="${PUBLIC_DIR}/${APPNAME}"
64 74
SOURCE="${BASE_URL}/${APPNAME}"
65 75

  
66
if [ ! -f ${IMPORT_SOURCE} ]; then
67
    log_error "File ${IMPORT_SOURCE} does not exits"
68
    exit -1
69
fi
76
if [ -n "$BRIDGE_LIST" ]; then
77
    DST_HOST=`get_destination_host $ID`
78
    CP_CMD="$UTILS_PATH/downloader.sh ${IMPORT_SOURCE} -"
70 79

  
71
CHECKSUM=$(${MD5SUM} ${IMPORT_SOURCE} | cut -f1 -d' ')
80
    exec_and_log "eval $CP_CMD | $SSH ${DST_HOST} $DD of=${DST_PATH} bs=64k" \
81
                 "Error dumping ${IMPORT_SOURCE} to ${DST_HOST}:${DST_PATH}"
72 82

  
73
SIZE=$(fs_size ${IMPORT_SOURCE})
83
    #if [ "${DISPOSE}" = "YES" ]; then
84
    #TODO This should call a ds operation
85
    #fi
86
else
87
    CP_CMD="$UTILS_PATH/downloader.sh ${IMPORT_SOURCE} ${DST_PATH}"
88
    exec_and_log "$CP_CMD" "Error copying ${IMPORT_SOURCE} to ${DST_PATH}"
74 89

  
75
if [ "$SIZE" = "0" ]; then
76
    log_error "Cannot determine size for ${IMPORT_SOURCE}"
77
    exit -1
90
    if [ "${DISPOSE}" = "YES" ]; then
91
    #TODO This should call a ds operation
92
        exec_and_log "$RM ${IMPORT_SOURCE}" "Error removing ${IMPORT_SOURCE}"
93
    fi
78 94
fi
79 95

  
80
exec_and_log "$CP ${IMPORT_SOURCE} ${DST_PATH}" \
81
    "Error copying ${IMPORT_SOURCE} to ${DST_PATH}. ${IMPORT_SOURCE} not removed"
82

  
83
exec_and_log "$RM ${IMPORT_SOURCE}" "Error removing ${IMPORT_SOURCE}"
84

  
85 96
RESPONSE=$(cat << EOF
86 97
SOURCE="$SOURCE"
87 98
CHECKSUM="$CHECKSUM"
88 99
SIZE="$SIZE"
100
FORMAT="$FORMAT"
89 101
EOF
90 102
)
91 103

  

Also available in: Unified diff