1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-30 22:50:10 +03:00

feature : add attach and detach scripts to xen

This commit is contained in:
Javi Fontan 2012-06-19 18:46:29 +02:00
parent f43779e0e7
commit b44f650dd5
3 changed files with 102 additions and 0 deletions
src/vmm_mad/remotes/xen

@ -0,0 +1,72 @@
#!/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. #
#--------------------------------------------------------------------------- #
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]}"
case "$TYPE" in
block)
FILE_PREFIX="phy"
;;
*)
FILE_PREFIX="tap:aio"
;;
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"

@ -0,0 +1,28 @@
#!/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. #
#--------------------------------------------------------------------------- #
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"

@ -28,6 +28,8 @@ export XM_RESTORE="sudo $XM_PATH restore"
export XM_LIST="sudo $XM_PATH list"
export XM_SHUTDOWN="sudo $XM_PATH shutdown"
export XM_POLL="sudo /usr/sbin/xentop -bi2"
export XM_ATTACH_DISK="sudo $XM_PATH block-attach"
export XM_DETACH_DISK="sudo $XM_PATH block-detach"
# In xen 4.1 the credit scheduler command is called sched-credit,
# uncomment this line if you are using this version