Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:onielsen:Virtualization:Testing
opennebula
feature-for-upstream-susestudio_downloader.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File feature-for-upstream-susestudio_downloader.patch of Package opennebula
diff -ruN opennebula-5.2.0/src/datastore_mad/remotes/cp_susestudio.sh opennebula-5.2.0-new/src/datastore_mad/remotes/cp_susestudio.sh --- opennebula-5.2.0/src/datastore_mad/remotes/cp_susestudio.sh 1970-01-01 01:00:00.000000000 +0100 +++ opennebula-5.2.0-new/src/datastore_mad/remotes/cp_susestudio.sh 2017-01-05 22:22:37.366892148 +0100 @@ -0,0 +1,54 @@ +####################### +# SuSE Studio support # +####################### +# +# Source this file after COPY_COMMAND in /var/lib/one/remotes/datastore/fs/cp +# +# Get Template variables +while IFS= read -r -d '' element; do + SUSESTUDIO_ELEMENTS[i++]="$element" +done < <($XPATH /DS_DRIVER_ACTION_DATA/IMAGE/TEMPLATE/SUSESTUDIO_EXTRACT \ + /DS_DRIVER_ACTION_DATA/IMAGE/TEMPLATE/SUSESTUDIO_CONVERT \ + /DS_DRIVER_ACTION_DATA/IMAGE/TEMPLATE/SUSESTUDIO_RESIZE) + +SUSESTUDIO_EXTRACT="${SUSESTUDIO_ELEMENTS[0]}" +SUSESTUDIO_CONVERT="${SUSESTUDIO_ELEMENTS[1]}" +SUSESTUDIO_RESIZE="${SUSESTUDIO_ELEMENTS[2]}" + + + +# Automatic convert & resize +case $SRC in + http://susestudio.com/*.oem.*|https://susestudio.com/*.oem.*) + SUSESTUDIO_EXTRACT="*.raw" + if [ -z "$SUSESTUDIO_RESIZE" ]; then + SUSESTUDIO_RESIZE="+1G" + fi + ;; + http://susestudio.com/*.ovf.*|https://susestudio.com/*.ovf.*|http://susestudio.com/*.vmx.*|https://susestudio.com/*.vmx.*) + SUSESTUDIO_EXTRACT="*.vmdk" + if [ -z "$SUSESTUDIO_CONVERT" ]; then + SUSESTUDIO_CONVERT="qcow2" + fi + ;; +esac + + + +# SuSE Studio extensions +if [ -n "$SUSESTUDIO_EXTRACT" ]; then + DOWNLOADER_ARGS="$DOWNLOADER_ARGS --susestudio_extract $SUSESTUDIO_EXTRACT" +fi +if [ -n "$SUSESTUDIO_CONVERT" ]; then + DOWNLOADER_ARGS="$DOWNLOADER_ARGS --susestudio_convert $SUSESTUDIO_CONVERT" +fi +if [ -n "$SUSESTUDIO_RESIZE" ]; then + DOWNLOADER_ARGS="$DOWNLOADER_ARGS --susestudio_resize $SUSESTUDIO_RESIZE" +fi + + + +# Override default COPY_COMMAND if needed +if test "${DOWNLOADER_ARGS#*--susestudio_}" != "$DOWNLOADER_ARGS"; then + COPY_COMMAND="$UTILS_PATH/susestudio-downloader.sh $DOWNLOADER_ARGS" +fi diff -ruN opennebula-5.2.0/src/datastore_mad/remotes/fs/cp opennebula-5.2.0-new/src/datastore_mad/remotes/fs/cp --- opennebula-5.2.0/src/datastore_mad/remotes/fs/cp 2016-10-17 10:39:32.000000000 +0200 +++ opennebula-5.2.0-new/src/datastore_mad/remotes/fs/cp 2017-01-05 22:22:37.366892148 +0100 @@ -92,6 +92,7 @@ fi COPY_COMMAND="$UTILS_PATH/downloader.sh $DOWNLOADER_ARGS" +. ${UTILS_PATH}/cp_susestudio.sh if echo "$SRC" | grep -vq '^https\?://'; then if [ `check_restricted $SRC` -eq 1 ]; then diff -ruN opennebula-5.2.0/src/datastore_mad/remotes/fs/cp.orig opennebula-5.2.0-new/src/datastore_mad/remotes/fs/cp.orig --- opennebula-5.2.0/src/datastore_mad/remotes/fs/cp.orig 1970-01-01 01:00:00.000000000 +0100 +++ opennebula-5.2.0-new/src/datastore_mad/remotes/fs/cp.orig 2016-10-17 10:39:32.000000000 +0200 @@ -0,0 +1,122 @@ +#!/bin/bash + +# -------------------------------------------------------------------------- # +# Copyright 2002-2016, OpenNebula Project, OpenNebula Systems # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + +############################################################################### +# This script is used to copy a VM image (SRC) to the image repository as DST +# Several SRC types are supported +############################################################################### + +# -------- Set up the environment to source common tools & conf ------------ + +if [ -z "${ONE_LOCATION}" ]; then + LIB_LOCATION=/usr/lib/one +else + LIB_LOCATION=$ONE_LOCATION/lib +fi + +. $LIB_LOCATION/sh/scripts_common.sh + +DRIVER_PATH=$(dirname $0) +source ${DRIVER_PATH}/../libfs.sh + +# -------- Get cp and datastore arguments from OpenNebula core ------------ + +DRV_ACTION=$1 +ID=$2 + +export DRV_ACTION + +UTILS_PATH="${DRIVER_PATH}/.." + +XPATH="$UTILS_PATH/xpath.rb -b $DRV_ACTION" + +unset i XPATH_ELEMENTS + +while IFS= read -r -d '' element; do + XPATH_ELEMENTS[i++]="$element" +done < <($XPATH /DS_DRIVER_ACTION_DATA/DATASTORE/BASE_PATH \ + /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/RESTRICTED_DIRS \ + /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/SAFE_DIRS \ + /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/BRIDGE_LIST \ + /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/STAGING_DIR \ + /DS_DRIVER_ACTION_DATA/DATASTORE/TYPE \ + /DS_DRIVER_ACTION_DATA/IMAGE/PATH \ + /DS_DRIVER_ACTION_DATA/IMAGE/TEMPLATE/MD5 \ + /DS_DRIVER_ACTION_DATA/IMAGE/TEMPLATE/SHA1 \ + /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/NO_DECOMPRESS \ + /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/LIMIT_TRANSFER_BW) + +unset i + +BASE_PATH="${XPATH_ELEMENTS[i++]}" +RESTRICTED_DIRS="${XPATH_ELEMENTS[i++]}" +SAFE_DIRS="${XPATH_ELEMENTS[i++]}" +BRIDGE_LIST="${XPATH_ELEMENTS[i++]}" +STAGING_DIR="${XPATH_ELEMENTS[i++]:-/var/tmp}" +TYPE="${XPATH_ELEMENTS[i++]}" +SRC="${XPATH_ELEMENTS[i++]}" +MD5="${XPATH_ELEMENTS[i++]}" +SHA1="${XPATH_ELEMENTS[i++]}" +NO_DECOMPRESS="${XPATH_ELEMENTS[i++]}" +LIMIT_TRANSFER_BW="${XPATH_ELEMENTS[i++]}" + +DST=`generate_image_path` +IMAGE_HASH=`basename $DST` + +set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS" + +# Disable auto-decompress for the 'files' datastores (type 2) +if [ "$TYPE" = "2" ]; then + NO_DECOMPRESS="${NO_DECOMPRESS:-yes}" +fi + +if [ -n "$BRIDGE_LIST" ]; then + DOWNLOADER_ARGS=`set_downloader_args "$MD5" "$SHA1" "$NO_DECOMPRESS" "$LIMIT_TRANSFER_BW" "$SRC" -` +else + DOWNLOADER_ARGS=`set_downloader_args "$MD5" "$SHA1" "$NO_DECOMPRESS" "$LIMIT_TRANSFER_BW" "$SRC" "$DST"` +fi + +COPY_COMMAND="$UTILS_PATH/downloader.sh $DOWNLOADER_ARGS" + +if echo "$SRC" | grep -vq '^https\?://'; then + if [ `check_restricted $SRC` -eq 1 ]; then + log_error "Not allowed to copy images from $RESTRICTED_DIRS" + error_message "Not allowed to copy image file $SRC" + exit -1 + fi + + log "Copying local image $SRC to the image repository" +else + log "Downloading image $SRC to the image repository" +fi + +if [ -n "$BRIDGE_LIST" ]; then + DST_HOST=`get_destination_host $ID` + TMP_DST="$STAGING_DIR/$IMAGE_HASH" + + exec_and_log "eval $COPY_COMMAND | $SSH $DST_HOST $DD of=$TMP_DST bs=64k" \ + "Error dumping $SRC to $DST_HOST:$TMP_DST" + + ssh_exec_and_log "$DST_HOST" "mkdir -p $BASE_PATH; mv -f $TMP_DST $DST" \ + "Error moving $TMP_DST to $DST in $DST_HOST" +else + mkdir -p "$BASE_PATH" + exec_and_log "$COPY_COMMAND" "Error copying $SRC to $DST" +fi + +echo "$DST" diff -ruN opennebula-5.2.0/src/datastore_mad/remotes/susestudio-downloader.sh opennebula-5.2.0-new/src/datastore_mad/remotes/susestudio-downloader.sh --- opennebula-5.2.0/src/datastore_mad/remotes/susestudio-downloader.sh 1970-01-01 01:00:00.000000000 +0100 +++ opennebula-5.2.0-new/src/datastore_mad/remotes/susestudio-downloader.sh 2017-01-05 22:22:37.366892148 +0100 @@ -0,0 +1,325 @@ +#!/bin/bash + +# -------------------------------------------------------------------------- # +# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + +# Execute a command (first parameter) and use the first kb of stdout +# to determine the file type +function get_type +{ + if [ "$NO_DECOMPRESS" = "yes" ]; then + echo "application/octet-stream" + else + command=$1 + + ( $command | head -n 1024 | file -b --mime-type - ) 2>/dev/null + fi +} + +# Gets the command needed to decompress an stream. +function get_decompressor +{ + type=$1 + + case "$type" in + "application/x-gzip") + echo "gunzip -c -" + ;; + "application/x-bzip2") + echo "bunzip2 -c -" + ;; + *) + echo "cat" + ;; + esac +} + +# Function called to decompress a stream. The first parameter is the command +# used to decompress the stream. Second parameter is the output file or +# - for stdout. +function decompress +{ + command="$1" + to="$2" + + if [ "$to" = "-" ]; then + $command + else + $command > "$to" + fi +} + +# Function called to hash a stream. First parameter is the algorithm name. +function hasher +{ + if [ -n "$1" ]; then + openssl dgst -$1 | awk '{print $NF}' > $HASH_FILE + else + # Needs something consuming stdin or the pipe will break + cat >/dev/null + fi +} + +# Unarchives a tar or a zip a file to a directory with the same name. +function unarchive +{ + TO="$1" + + file_type=$(get_type "cat $TO") + + tmp="$TO" + + # Add full path if it is relative + if [ ${tmp:0:1} != "/" ]; then + tmp="$PWD/$tmp" + fi + + IN="$tmp.tmp" + OUT="$tmp" + + case "$file_type" in + "application/x-tar") + command="tar -xf $IN -C $OUT" + ;; + "application/zip") + command="unzip -d $OUT $IN" + ;; + *) + command="" + ;; + esac + + if [ -n "$command" ]; then + mv "$OUT" "$IN" + mkdir "$OUT" + + $command + + if [ "$?" != "0" ]; then + echo "Error uncompressing archive" >&2 + exit -1 + fi + + rm "$IN" + fi +} + +# Unarchives a tar or a zip a file to a file with the same name. +function unarchive_file +{ + TO="$1" + WILDCARDS="$2" + + file_type=$(get_type "cat $TO") + + tmp="$TO" + + # Add full path if it is relative + if [ ${tmp:0:1} != "/" ]; then + tmp="$PWD/$tmp" + fi + + IN="$tmp.tmp" + OUT="$tmp" + + if [ -n "$WILDCARDS" ]; then + TAR_OPT="--wildcards $WILDCARDS" + ZIP_OPT="$WILDCARDS" + fi + + case "$file_type" in + "application/x-tar") + command="tar -xOf $IN $TAR_OPT" + ;; + "application/zip") + command="unzip -p $IN $ZIP_OPT" + ;; + *) + command="" + ;; + esac + + if [ -n "$command" ]; then + mv "$OUT" "$IN" + + $command >"$OUT" + + if [ "$?" != "0" ]; then + echo "Error uncompressing archive" >&2 + exit -1 + fi + + rm "$IN" + fi +} + +# Convert image +function convert +{ + TO="$1" + FORMAT="$2" + + tmp="$TO" + + # Add full path if it is relative + if [ ${tmp:0:1} != "/" ]; then + tmp="$PWD/$tmp" + fi + + IN="$tmp.tmp" + OUT="$tmp" + + mv "$OUT" "$IN" + + qemu-img convert -O "$FORMAT" "$IN" "$OUT" >/dev/null 2>&1 + + if [ "$?" != "0" ]; then + echo "Error converting image" >&2 + rm "$IN" "$OUT" + exit -1 + fi + + rm "$IN" +} + +# Resize image +function resize +{ + TO="$1" + SIZE="$2" + + qemu-img resize "$TO" "$SIZE" >/dev/null 2>&1 + if [ "$?" != "0" ]; then + echo "Error resizing image" >&2 + rm "$TO" + exit -1 + fi +} + +TEMP=`getopt -o m:s:l:n -l md5:,sha1:,limit:,nodecomp,susestudio_extract:,susestudio_convert:,susestudio_resize: -- "$@"` + +if [ $? != 0 ] ; then + echo "Arguments error" + exit -1 +fi + +eval set -- "$TEMP" + +while true; do + case "$1" in + -m|--md5) + HASH_TYPE=md5 + HASH=$2 + shift 2 + ;; + -s|--sha1) + HASH_TYPE=sha1 + HASH=$2 + shift 2 + ;; + -n|--nodecomp) + export NO_DECOMPRESS="yes" + shift + ;; + -l|--limit) + export LIMIT_RATE="$2" + shift 2 + ;; + --susestudio_extract) + export SUSESTUDIO_EXTRACT="$2" + shift 2 + ;; + --susestudio_convert) + export SUSESTUDIO_CONVERT="$2" + shift 2 + ;; + --susestudio_resize) + export SUSESTUDIO_RESIZE="$2" + shift 2 + ;; + --) + shift + break + ;; + *) + shift + ;; + esac +done + +FROM="$1" +TO="$2" + +# File used by the hasher function to store the resulting hash +export HASH_FILE="/tmp/downloader.hash.$$" + +case "$FROM" in +http://*|https://*) + # -k so it does not check the certificate + # -L to follow redirects + # -sS to hide output except on failure + # --limit_rate to limit the bw + curl_args="-sS -k -L $FROM" + + if [ -n "$LIMIT_RATE" ]; then + curl_args="--limit-rate $LIMIT_RATE $curl_args" + fi + + command="curl $curl_args" + ;; +*) + command="cat $FROM" + ;; +esac + +file_type=$(get_type "$command") +decompressor=$(get_decompressor "$file_type") + +$command | tee >( decompress "$decompressor" "$TO" ) \ + >( hasher $HASH_TYPE ) >/dev/null + +if [ "$?" != "0" ]; then + echo "Error copying" >&2 + exit -1 +fi + +if [ -n "$HASH_TYPE" ]; then + HASH_RESULT=$( cat $HASH_FILE) + rm $HASH_FILE + if [ "$HASH_RESULT" != "$HASH" ]; then + echo "Hash does not match" >&2 + exit -1 + fi +fi + +# Unarchive only if the destination is filesystem +if [ "$TO" != "-" ]; then + if [ -n "$SUSESTUDIO_EXTRACT" ]; then + unarchive_file "$TO" "$SUSESTUDIO_EXTRACT" + else + unarchive "$TO" + fi + + # Convert image + if [ -n "$SUSESTUDIO_CONVERT" ]; then + convert "$TO" "$SUSESTUDIO_CONVERT" + fi + + # Resize image + if [ -n "$SUSESTUDIO_RESIZE" ]; then + resize "$TO" "$SUSESTUDIO_RESIZE" + fi +fi
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor