From de856c09debfd9776039150f0289e2ceff99b97d Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Fri, 7 Jun 2013 17:04:02 +0200 Subject: [PATCH] feature #1163: merge xen3 and xen4 drivers, added parameters in xenrc --- install.sh | 12 +-- .../remotes/xen/{xen4 => }/attach_disk | 8 +- src/vmm_mad/remotes/xen/{xen4 => }/deploy | 0 .../remotes/xen/{xen4 => }/detach_disk | 2 +- src/vmm_mad/remotes/xen/xen3/attach_disk | 78 ------------------- src/vmm_mad/remotes/xen/xen3/deploy | 59 -------------- src/vmm_mad/remotes/xen/xen3/detach_disk | 28 ------- src/vmm_mad/remotes/xen/xen3/xenrc | 6 +- src/vmm_mad/remotes/xen/xen4/xenrc | 5 +- 9 files changed, 19 insertions(+), 179 deletions(-) rename src/vmm_mad/remotes/xen/{xen4 => }/attach_disk (93%) rename src/vmm_mad/remotes/xen/{xen4 => }/deploy (100%) rename src/vmm_mad/remotes/xen/{xen4 => }/detach_disk (95%) delete mode 100755 src/vmm_mad/remotes/xen/xen3/attach_disk delete mode 100755 src/vmm_mad/remotes/xen/xen3/deploy delete mode 100755 src/vmm_mad/remotes/xen/xen3/detach_disk diff --git a/install.sh b/install.sh index 856c0ff16b..38eb8ba46c 100755 --- a/install.sh +++ b/install.sh @@ -714,7 +714,7 @@ VMM_EXEC_KVM_SCRIPTS="src/vmm_mad/remotes/kvm/cancel \ #------------------------------------------------------------------------------- VMM_EXEC_XEN3_SCRIPTS="src/vmm_mad/remotes/xen/cancel \ - src/vmm_mad/remotes/xen/xen3/deploy \ + src/vmm_mad/remotes/xen/deploy \ src/vmm_mad/remotes/xen/xen3/xenrc \ src/vmm_mad/remotes/xen/migrate \ src/vmm_mad/remotes/xen/restore \ @@ -723,8 +723,8 @@ VMM_EXEC_XEN3_SCRIPTS="src/vmm_mad/remotes/xen/cancel \ src/vmm_mad/remotes/xen/save \ src/vmm_mad/remotes/xen/poll \ src/vmm_mad/remotes/xen/poll_ganglia \ - src/vmm_mad/remotes/xen/xen3/attach_disk \ - src/vmm_mad/remotes/xen/xen3/detach_disk \ + src/vmm_mad/remotes/xen/attach_disk \ + src/vmm_mad/remotes/xen/detach_disk \ src/vmm_mad/remotes/xen/attach_nic \ src/vmm_mad/remotes/xen/detach_nic \ src/vmm_mad/remotes/xen/snapshot_create \ @@ -733,7 +733,7 @@ VMM_EXEC_XEN3_SCRIPTS="src/vmm_mad/remotes/xen/cancel \ src/vmm_mad/remotes/xen/shutdown" VMM_EXEC_XEN4_SCRIPTS="src/vmm_mad/remotes/xen/cancel \ - src/vmm_mad/remotes/xen/xen4/deploy \ + src/vmm_mad/remotes/xen/deploy \ src/vmm_mad/remotes/xen/xen4/xenrc \ src/vmm_mad/remotes/xen/migrate \ src/vmm_mad/remotes/xen/restore \ @@ -742,8 +742,8 @@ VMM_EXEC_XEN4_SCRIPTS="src/vmm_mad/remotes/xen/cancel \ src/vmm_mad/remotes/xen/save \ src/vmm_mad/remotes/xen/poll \ src/vmm_mad/remotes/xen/poll_ganglia \ - src/vmm_mad/remotes/xen/xen4/attach_disk \ - src/vmm_mad/remotes/xen/xen4/detach_disk \ + src/vmm_mad/remotes/xen/attach_disk \ + src/vmm_mad/remotes/xen/detach_disk \ src/vmm_mad/remotes/xen/attach_nic \ src/vmm_mad/remotes/xen/detach_nic \ src/vmm_mad/remotes/xen/snapshot_create \ diff --git a/src/vmm_mad/remotes/xen/xen4/attach_disk b/src/vmm_mad/remotes/xen/attach_disk similarity index 93% rename from src/vmm_mad/remotes/xen/xen4/attach_disk rename to src/vmm_mad/remotes/xen/attach_disk index 4549c34ace..a9ac9cea71 100755 --- a/src/vmm_mad/remotes/xen/xen4/attach_disk +++ b/src/vmm_mad/remotes/xen/attach_disk @@ -47,10 +47,8 @@ READONLY="${XPATH_ELEMENTS[2]}" BUS="${XPATH_ELEMENTS[3]}" CACHE="${XPATH_ELEMENTS[4]}" -DEFAULT_FILE_PREFIX="raw" - -if [ -n "$IMAGE_PREFIX" ]; then - DEFAULT_FILE_PREFIX="$IMAGE_PREFIX" +if [ -z "$DEFAULT_FILE_PREFIX" ]; then + DEFAULT_FILE_PREFIX="file" fi case "$TYPE" in @@ -74,5 +72,5 @@ else MODE="w" fi -exec_and_log "$XM_ATTACH_DISK $DOMAIN $FULL_DISK $TARGET $MODE" \ +exec_and_log "$XM_ATTACH_DISK $DOMAIN $FULL_DISK ${TARGET_PREFIX}$TARGET $MODE" \ "Could not attach $FULL_DISK ($TARGET) to $DOMAIN" diff --git a/src/vmm_mad/remotes/xen/xen4/deploy b/src/vmm_mad/remotes/xen/deploy similarity index 100% rename from src/vmm_mad/remotes/xen/xen4/deploy rename to src/vmm_mad/remotes/xen/deploy diff --git a/src/vmm_mad/remotes/xen/xen4/detach_disk b/src/vmm_mad/remotes/xen/detach_disk similarity index 95% rename from src/vmm_mad/remotes/xen/xen4/detach_disk rename to src/vmm_mad/remotes/xen/detach_disk index fa170cc022..07131b2f24 100755 --- a/src/vmm_mad/remotes/xen/xen4/detach_disk +++ b/src/vmm_mad/remotes/xen/detach_disk @@ -24,5 +24,5 @@ SOURCE="$2" TARGET="$3" TARGET_INDEX="$4" -exec_and_log "$XM_DETACH_DISK $DOMAIN $TARGET" \ +exec_and_log "$XM_DETACH_DISK $DOMAIN ${TARGET_PREFIX}$TARGET" \ "Could not detach $TARGET from $DOMAIN" diff --git a/src/vmm_mad/remotes/xen/xen3/attach_disk b/src/vmm_mad/remotes/xen/xen3/attach_disk deleted file mode 100755 index 64b32cf81c..0000000000 --- a/src/vmm_mad/remotes/xen/xen3/attach_disk +++ /dev/null @@ -1,78 +0,0 @@ -#!/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. # -#--------------------------------------------------------------------------- # - -source $(dirname $0)/xenrc -source $(dirname $0)/../../scripts_common.sh - -DRIVER_PATH=$(dirname $0) - -DOMAIN="$1" -SOURCE="$2" -TARGET="$3" -TARGET_INDEX="$4" -DRV_ACTION="$5" - -XPATH="${DRIVER_PATH}/../../datastore/xpath.rb -b $DRV_ACTION" - -unset i XPATH_ELEMENTS - -DISK_XPATH="/VMM_DRIVER_ACTION_DATA/VM/TEMPLATE/DISK[ATTACH='YES']" - -while IFS= read -r -d '' element; do - XPATH_ELEMENTS[i++]="$element" -done < <($XPATH $DISK_XPATH/DRIVER \ - $DISK_XPATH/TYPE \ - $DISK_XPATH/READONLY \ - $DISK_XPATH/BUS \ - $DISK_XPATH/CACHE) - -DRIVER="${XPATH_ELEMENTS[0]:-$DEFAULT_TYPE}" -TYPE="${XPATH_ELEMENTS[1]}" -READONLY="${XPATH_ELEMENTS[2]}" -BUS="${XPATH_ELEMENTS[3]}" -CACHE="${XPATH_ELEMENTS[4]}" - -DEFAULT_FILE_PREFIX="file" - -if [ -n "$IMAGE_PREFIX" ]; then - DEFAULT_FILE_PREFIX="$IMAGE_PREFIX" -fi - -case "$TYPE" in -block) - FILE_PREFIX="phy" - ;; -*) - FILE_PREFIX="$DEFAULT_FILE_PREFIX" - ;; -esac - -if [ -n "$DRIVER" ]; then - FILE_PREFIX="$DRIVER" -fi - -FULL_DISK="${FILE_PREFIX%:}:$SOURCE" - -if [ "$READONLY" = "YES" ]; then - MODE="r" -else - MODE="w" -fi - -exec_and_log "$XM_ATTACH_DISK $DOMAIN $FULL_DISK /dev/$TARGET $MODE" \ - "Could not attach $FULL_DISK ($TARGET) to $DOMAIN" diff --git a/src/vmm_mad/remotes/xen/xen3/deploy b/src/vmm_mad/remotes/xen/xen3/deploy deleted file mode 100755 index 19ee7b2bf6..0000000000 --- a/src/vmm_mad/remotes/xen/xen3/deploy +++ /dev/null @@ -1,59 +0,0 @@ -#!/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. # -#--------------------------------------------------------------------------- # - -source $(dirname $0)/xenrc -source $(dirname $0)/../../scripts_common.sh - -function error_exit() { - exit_code=$1 - message=$2 - if [ "x$exit_code" != "x0" ]; then - error_message $message - exit $exit_code - fi -} - -domain=$1 - -mkdir -p `dirname $domain` -cat > $domain - -output=`$XM_CREATE $domain` - -error_exit $? "Unable to create domain" - -domain_name=`echo $output | grep 'Started domain' | sed 's/^.*Started domain //' | tr -d '\n' | cut -d' ' -f1` - -out=`grep -e '^\#O CPU_CREDITS =' < $domain` - -if [ "x$?" = "x0" ]; then - credits=`echo $out | cut -d= -f2 | tr -d ' '` - - log_debug "Credits set to $credits" - - name=`grep -e '^name =' < $domain | cut -d= -f2 | tr -d ' ' | tr -d "\'" | cut -d' ' -f1` - - $XM_CREDITS -d $name -w $credits - - if [ "x$?" != "x0" ]; then - log_error "Unable to set VM credits" - fi -fi - -echo $domain_name - diff --git a/src/vmm_mad/remotes/xen/xen3/detach_disk b/src/vmm_mad/remotes/xen/xen3/detach_disk deleted file mode 100755 index 9cfa78f7d5..0000000000 --- a/src/vmm_mad/remotes/xen/xen3/detach_disk +++ /dev/null @@ -1,28 +0,0 @@ -#!/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. # -#--------------------------------------------------------------------------- # - -source $(dirname $0)/xenrc -source $(dirname $0)/../../scripts_common.sh - -DOMAIN="$1" -SOURCE="$2" -TARGET="$3" -TARGET_INDEX="$4" - -exec_and_log "$XM_DETACH_DISK $DOMAIN /dev/$TARGET" \ - "Could not detach $TARGET from $DOMAIN" diff --git a/src/vmm_mad/remotes/xen/xen3/xenrc b/src/vmm_mad/remotes/xen/xen3/xenrc index 9e9dd8b175..06405e8e72 100644 --- a/src/vmm_mad/remotes/xen/xen3/xenrc +++ b/src/vmm_mad/remotes/xen/xen3/xenrc @@ -41,7 +41,11 @@ export XM_NETWORK_LIST="sudo $XM_PATH network-list" # Xen 4 uses the new blktap2 and tap:aio handler is no longer supported. # To make it work uncomment this line. This will be used as the default # handler for disk hot plug -#export IMAGE_PREFIX="tap:tapdisk:aio" +#export DEFAULT_FILE_PREFIX="tap:tapdisk:aio" +export DEFAULT_FILE_PREFIX="file" + +# attach and detach disk target prefix +TARGET_PREFIX="/dev/" # Seconds to wait after shutdown until timeout export SHUTDOWN_TIMEOUT=300 diff --git a/src/vmm_mad/remotes/xen/xen4/xenrc b/src/vmm_mad/remotes/xen/xen4/xenrc index c1f6daad1b..f70e9ffb0a 100644 --- a/src/vmm_mad/remotes/xen/xen4/xenrc +++ b/src/vmm_mad/remotes/xen/xen4/xenrc @@ -41,7 +41,10 @@ export XM_CREDITS="sudo $XM_PATH sched-credit" # Xen 4 uses the new blktap2 and tap:aio handler is no longer supported. # To make it work uncomment this line. This will be used as the default # handler for disk hot plug -export IMAGE_PREFIX="raw" +export DEFAULT_FILE_PREFIX="raw" + +# attach and detach disk target prefix +TARGET_PREFIX="" # Seconds to wait after shutdown until timeout export SHUTDOWN_TIMEOUT=300