From 89a0a475c93c5f1698fddaabefe6d82207465d47 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Wed, 7 Mar 2012 12:41:35 +0100 Subject: [PATCH 1/5] feature #1112: Small modifications in DS/TM scripts: * The DS directory is created specifically by each action only when needed * ssh_exec_and_log and ssh_make_path move to scripts_common.sh * Round the size up * drop unused remote2local_path function --- src/datastore_mad/remotes/fs/cp | 1 + src/datastore_mad/remotes/fs/mkfs | 10 ++--- src/datastore_mad/remotes/libfs.sh | 6 +-- src/datastore_mad/remotes/vmware/cp | 1 + src/datastore_mad/remotes/vmware/mkfs | 7 ++-- src/mad/sh/scripts_common.sh | 42 +++++++++++++++++++- src/tm_mad/tm_common.sh | 55 +-------------------------- 7 files changed, 51 insertions(+), 71 deletions(-) diff --git a/src/datastore_mad/remotes/fs/cp b/src/datastore_mad/remotes/fs/cp index b7fe2249f7..81a6b07679 100755 --- a/src/datastore_mad/remotes/fs/cp +++ b/src/datastore_mad/remotes/fs/cp @@ -57,6 +57,7 @@ SAFE_DIRS="${XPATH_ELEMENTS[2]}" UMASK="${XPATH_ELEMENTS[3]}" SRC="${XPATH_ELEMENTS[4]}" +mkdir -p "$BASE_PATH" set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS" "$UMASK" DST=`generate_image_path` diff --git a/src/datastore_mad/remotes/fs/mkfs b/src/datastore_mad/remotes/fs/mkfs index 4d3bda68e4..d6a3d8d484 100755 --- a/src/datastore_mad/remotes/fs/mkfs +++ b/src/datastore_mad/remotes/fs/mkfs @@ -49,7 +49,6 @@ 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/UMASK \ - /DS_DRIVER_ACTION_DATA/IMAGE/PATH \ /DS_DRIVER_ACTION_DATA/IMAGE/FSTYPE \ /DS_DRIVER_ACTION_DATA/IMAGE/SIZE) @@ -58,10 +57,10 @@ BASE_PATH="${XPATH_ELEMENTS[0]}" RESTRICTED_DIRS="${XPATH_ELEMENTS[1]}" SAFE_DIRS="${XPATH_ELEMENTS[2]}" UMASK="${XPATH_ELEMENTS[3]}" -SRC="${XPATH_ELEMENTS[4]}" -FSTYPE="${XPATH_ELEMENTS[5]}" -SIZE="${XPATH_ELEMENTS[6]}" +FSTYPE="${XPATH_ELEMENTS[4]}" +SIZE="${XPATH_ELEMENTS[5]}" +mkdir -p "$BASE_PATH" set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS" "$UMASK" DST=`generate_image_path` @@ -82,7 +81,4 @@ exec_and_log "$DD if=/dev/zero of=$DST bs=1 count=1 seek=${SIZE}M" \ exec_and_log "$MKFS_CMD" \ "Unable to create filesystem $FSTYPE in $DST" -# ---------------- Get the size of the image ------------ -SIZE=`fs_du $DST` - echo "$DST $SIZE" diff --git a/src/datastore_mad/remotes/libfs.sh b/src/datastore_mad/remotes/libfs.sh index e1b5f67717..76a91c6227 100644 --- a/src/datastore_mad/remotes/libfs.sh +++ b/src/datastore_mad/remotes/libfs.sh @@ -53,8 +53,6 @@ function set_up_datastore { export RESTRICTED_DIRS export SAFE_DIRS - mkdir -p $BASE_PATH - if [ -n "$UMASK" ]; then umask $UMASK else @@ -94,7 +92,7 @@ function fs_du { if [ $error -ne 0 ]; then SIZE=0 else - SIZE=$(($SIZE/1048576)) + SIZE=$((($SIZE+1048575)/1048576)) fi echo "$SIZE" @@ -111,7 +109,7 @@ function qemu_size { SIZE=`$QEMU_IMG info $DISK|grep "^virtual size:"|\ sed 's/^.*(\([0-9]\+\) bytes.*$/\1/g'` - SIZE=$(($SIZE/1048576)) + SIZE=$((($SIZE+1048575)/1048576)) echo "$SIZE" } diff --git a/src/datastore_mad/remotes/vmware/cp b/src/datastore_mad/remotes/vmware/cp index f216d95892..bb4995a5ef 100755 --- a/src/datastore_mad/remotes/vmware/cp +++ b/src/datastore_mad/remotes/vmware/cp @@ -57,6 +57,7 @@ SAFE_DIRS="${XPATH_ELEMENTS[2]}" UMASK="${XPATH_ELEMENTS[3]}" SRC="${XPATH_ELEMENTS[4]}" +mkdir -p "$BASE_PATH" set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS" "$UMASK" DST=`generate_image_path` diff --git a/src/datastore_mad/remotes/vmware/mkfs b/src/datastore_mad/remotes/vmware/mkfs index 0872965591..a4d38bccea 100755 --- a/src/datastore_mad/remotes/vmware/mkfs +++ b/src/datastore_mad/remotes/vmware/mkfs @@ -49,7 +49,6 @@ 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/UMASK \ - /DS_DRIVER_ACTION_DATA/IMAGE/PATH \ /DS_DRIVER_ACTION_DATA/IMAGE/FSTYPE \ /DS_DRIVER_ACTION_DATA/IMAGE/SIZE) @@ -57,10 +56,10 @@ BASE_PATH="${XPATH_ELEMENTS[0]}" RESTRICTED_DIRS="${XPATH_ELEMENTS[1]}" SAFE_DIRS="${XPATH_ELEMENTS[2]}" UMASK="${XPATH_ELEMENTS[3]}" -SRC="${XPATH_ELEMENTS[4]}" -FSTYPE="${XPATH_ELEMENTS[5]}" -SIZE="${XPATH_ELEMENTS[6]}" +FSTYPE="${XPATH_ELEMENTS[4]}" +SIZE="${XPATH_ELEMENTS[5]}" +mkdir -p "$BASE_PATH" set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS" "$UMASK" DST=`generate_image_path` diff --git a/src/mad/sh/scripts_common.sh b/src/mad/sh/scripts_common.sh index 307c5cf618..2679d8a014 100755 --- a/src/mad/sh/scripts_common.sh +++ b/src/mad/sh/scripts_common.sh @@ -115,7 +115,7 @@ function error_message function exec_and_log { message=$2 - + EXEC_LOG_ERR=`$1 2>&1 1>/dev/null` EXEC_LOG_RC=$? @@ -192,7 +192,7 @@ function mkfs_command { ;; "raw") echo "" - return 0 + return 0 ;; "swap") echo "$MKSWAP $DST" @@ -205,3 +205,41 @@ function mkfs_command { echo "$MKFS -t $FSTYPE $OPTS $DST" } + +#This function executes $2 at $1 host and report error $3 +function ssh_exec_and_log +{ + SSH_EXEC_ERR=`$SSH $1 bash -s 2>&1 1>/dev/null <&1 1>/dev/null < /dev/null 2>&1 + echo "$1" | $GREP '/disk\.[0-9]\+' > /dev/null 2>&1 if [ $? -eq 0 ]; then echo "1" @@ -70,56 +70,3 @@ function is_disk echo "0" fi } - -# ------------------------------------------------------------------------------ -# Function to get hosts and paths from arguments -# ------------------------------------------------------------------------------ - -#This function executes $2 at $1 host and report error $3 -function ssh_exec_and_log -{ - SSH_EXEC_ERR=`$SSH $1 bash -s 2>&1 1>/dev/null <&1 1>/dev/null < Date: Wed, 7 Mar 2012 12:42:21 +0100 Subject: [PATCH 2/5] feature #1112: DS iSCSI drivers --- install.sh | 7 ++ src/datastore_mad/remotes/iscsi/cp | 112 +++++++++++++++++++++ src/datastore_mad/remotes/iscsi/iscsi.conf | 24 +++++ src/datastore_mad/remotes/iscsi/mkfs | 101 +++++++++++++++++++ src/datastore_mad/remotes/iscsi/rm | 81 +++++++++++++++ src/datastore_mad/remotes/libfs.sh | 34 +++++++ src/mad/sh/scripts_common.sh | 3 +- 7 files changed, 361 insertions(+), 1 deletion(-) create mode 100755 src/datastore_mad/remotes/iscsi/cp create mode 100644 src/datastore_mad/remotes/iscsi/iscsi.conf create mode 100755 src/datastore_mad/remotes/iscsi/mkfs create mode 100755 src/datastore_mad/remotes/iscsi/rm diff --git a/install.sh b/install.sh index 263bc191cc..772aaadee9 100755 --- a/install.sh +++ b/install.sh @@ -237,6 +237,7 @@ VAR_DIRS="$VAR_LOCATION/remotes \ $VAR_LOCATION/remotes/datastore \ $VAR_LOCATION/remotes/datastore/fs \ $VAR_LOCATION/remotes/datastore/vmware \ + $VAR_LOCATION/remotes/datastore/iscsi \ $VAR_LOCATION/remotes/auth \ $VAR_LOCATION/remotes/auth/plain \ $VAR_LOCATION/remotes/auth/ssh \ @@ -390,6 +391,7 @@ INSTALL_FILES=( DATASTORE_DRIVER_COMMON_SCRIPTS:$VAR_LOCATION/remotes/datastore/ DATASTORE_DRIVER_FS_SCRIPTS:$VAR_LOCATION/remotes/datastore/fs DATASTORE_DRIVER_VMWARE_SCRIPTS:$VAR_LOCATION/remotes/datastore/vmware + DATASTORE_DRIVER_ISCSI_SCRIPTS:$VAR_LOCATION/remotes/datastore/iscsi NETWORK_FILES:$VAR_LOCATION/remotes/vnm NETWORK_8021Q_FILES:$VAR_LOCATION/remotes/vnm/802.1Q NETWORK_DUMMY_FILES:$VAR_LOCATION/remotes/vnm/dummy @@ -820,6 +822,11 @@ DATASTORE_DRIVER_VMWARE_SCRIPTS="src/datastore_mad/remotes/vmware/cp \ src/datastore_mad/remotes/vmware/mkfs \ src/datastore_mad/remotes/vmware/rm" +DATASTORE_DRIVER_ISCSI_SCRIPTS="src/datastore_mad/remotes/iscsi/cp \ + src/datastore_mad/remotes/iscsi/mkfs \ + src/datastore_mad/remotes/iscsi/rm \ + src/datastore_mad/remotes/iscsi/iscsi.conf" + #------------------------------------------------------------------------------- # Migration scripts for onedb command, to be installed under $LIB_LOCATION #------------------------------------------------------------------------------- diff --git a/src/datastore_mad/remotes/iscsi/cp b/src/datastore_mad/remotes/iscsi/cp new file mode 100755 index 0000000000..5e4a797899 --- /dev/null +++ b/src/datastore_mad/remotes/iscsi/cp @@ -0,0 +1,112 @@ +#!/bin/bash + +# -------------------------------------------------------------------------- # +# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) # +# # +# 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 +source ${DRIVER_PATH}/iscsi.conf + +# -------- Get cp and datastore arguments from OpenNebula core ------------ + +DRV_ACTION=$1 +ID=$2 + +XPATH="${DRIVER_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/UMASK \ + /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/HOST \ + /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/VG_NAME \ + /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/BASE_IQN \ + /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/BASE_TID \ + /DS_DRIVER_ACTION_DATA/IMAGE/PATH) + + +BASE_PATH="${XPATH_ELEMENTS[0]}" +RESTRICTED_DIRS="${XPATH_ELEMENTS[1]}" +SAFE_DIRS="${XPATH_ELEMENTS[2]}" +UMASK="${XPATH_ELEMENTS[3]}" +DST_HOST="${XPATH_ELEMENTS[4]}" +VG_NAME="${XPATH_ELEMENTS[5]:-$VG_NAME}" +BASE_IQN="${XPATH_ELEMENTS[6]:-$BASE_IQN}" +BASE_TID="${XPATH_ELEMENTS[7]:-$BASE_TID}" +SRC="${XPATH_ELEMENTS[8]}" + +set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS" "$UMASK" + +SIZE=`fs_du $SRC` +LV_NAME="lv-one-${ID}" +IQN="$BASE_IQN:$DST_HOST.$VG_NAME.$LV_NAME" +DEV="/dev/$VG_NAME/$LV_NAME" + +let TID=ID+BASE_TID + +REGISTER_CMD=$(cat <&2 + exit 1 + fi +EOF +) + +log "Removing $DST_HOST:$DEV from the image repository" + +ssh_exec_and_log "$DST_HOST" "$RM_COMMAND" \ + "Error removing $DST_HOST:$DEV" + +exit 0 diff --git a/src/datastore_mad/remotes/libfs.sh b/src/datastore_mad/remotes/libfs.sh index 76a91c6227..55d5aada37 100644 --- a/src/datastore_mad/remotes/libfs.sh +++ b/src/datastore_mad/remotes/libfs.sh @@ -136,3 +136,37 @@ function check_restricted { echo 0 } + + +# ------------------------------------------------------------------------------ +# iSCSI functions +# ------------------------------------------------------------------------------ + +#------------------------------------------------------------------------------- +# Returns the command to create a new target +# @param $1 - ID of the image +# @param $2 - Target Host +# @param $3 - Device +# @return the command to create a new target +#------------------------------------------------------------------------------- + +function iscsi_target_new { + ID="$1" + IQN="$2" + + echo "$TGTADM --lld iscsi --op new --mode target --tid $ID "\ + "--targetname $IQN" +} + +function iscsi_logicalunit_new { + ID="$1" + DEV="$2" + + echo "$TGTADM --lld iscsi --op new --mode logicalunit --tid $ID "\ + "--lun 1 --backing-store $DEV" +} + +function iscsi_target_delete { + ID="$1" + echo "$TGTADM --lld iscsi --op delete --mode target --tid $ID" +} diff --git a/src/mad/sh/scripts_common.sh b/src/mad/sh/scripts_common.sh index 2679d8a014..6b4ef552d9 100755 --- a/src/mad/sh/scripts_common.sh +++ b/src/mad/sh/scripts_common.sh @@ -22,6 +22,7 @@ CUT=cut DATE=date DD=dd DU=du +GREP=grep LVCREATE=lvcreate LVREMOVE=lvremove LVS=lvs @@ -35,8 +36,8 @@ SCP=scp SED=sed SSH=ssh SUDO=sudo +TGTADM=tgtadm WGET=wget -GREP=grep if [ "x$(uname -s)" = "xLinux" ]; then SED="$SED -r" From 5ec865cb3c49354274f99affde7ea9c8d13760ec Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Wed, 7 Mar 2012 12:45:49 +0100 Subject: [PATCH 3/5] feature #1112: improve debugging for one_datastore.rb --- src/datastore_mad/one_datastore.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/datastore_mad/one_datastore.rb b/src/datastore_mad/one_datastore.rb index 295a930bea..2ed7afc99b 100755 --- a/src/datastore_mad/one_datastore.rb +++ b/src/datastore_mad/one_datastore.rb @@ -83,9 +83,9 @@ class DatastoreDriver < OpenNebulaDriver register_action(ACTION[:mkfs].to_sym, method("mkfs")) end - ############################################################################ + ############################################################################ # Image Manager Protocol Actions (generic implementation) - ############################################################################ + ############################################################################ # TODO: Integrate this with TM # def mv(id, ds, src, dst) # do_image_action(id, ds, :mv, "'#{src}' '#{dst}' '#{id}'") @@ -112,7 +112,7 @@ class DatastoreDriver < OpenNebulaDriver if @types.include?(ds) return true else - send_message(ACTION[action], RESULT[:failure], id, + send_message(ACTION[action], RESULT[:failure], id, "Datastore driver '#{ds}' not available") return false end @@ -130,6 +130,8 @@ class DatastoreDriver < OpenNebulaDriver result, info = get_info_from_execution(rc) + + PP.pp([ACTION[action], result, id, info],STDERR) send_message(ACTION[action], result, id, info) end From 301447560d0f946f983b518fe8c351443743d5cb Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Wed, 7 Mar 2012 13:08:46 +0100 Subject: [PATCH 4/5] feature #1112: Add space in error message --- src/vm/VirtualMachine.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 5d5595b7f4..e56c197029 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -1216,7 +1216,7 @@ error_saved: goto error_common; error_image_id: - oss << "The DISK " << disk_id << "does not have a valid IMAGE_ID."; + oss << "The DISK " << disk_id << " does not have a valid IMAGE_ID."; goto error_common; error_not_found: From 62b5427c248f13952b1545e4d27326e7b6863547 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Wed, 7 Mar 2012 13:10:14 +0100 Subject: [PATCH 5/5] feature #924: Remove removed config.ru files from installer --- install.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/install.sh b/install.sh index fa2b593fe0..28e4e2b0a9 100755 --- a/install.sh +++ b/install.sh @@ -1079,8 +1079,7 @@ ETC_CLIENT_FILES="src/cli/etc/group.default" # Sunstone files #----------------------------------------------------------------------------- -SUNSTONE_FILES="src/sunstone/config.ru \ - src/sunstone/sunstone-server.rb \ +SUNSTONE_FILES="src/sunstone/sunstone-server.rb \ src/sunstone/OpenNebulaVNC.rb" SUNSTONE_BIN_FILES="src/sunstone/bin/sunstone-server" @@ -1225,8 +1224,7 @@ src/sunstone/public/locale/ru/ru_datatable.txt" # Ozones files #----------------------------------------------------------------------------- -OZONES_FILES="src/ozones/Server/config.ru \ - src/ozones/Server/ozones-server.rb" +OZONES_FILES="src/ozones/Server/ozones-server.rb" OZONES_BIN_FILES="src/ozones/Server/bin/ozones-server"