1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

Merge branch 'feature-1437'

This commit is contained in:
Ruben S. Montero 2012-09-28 23:28:31 +02:00
commit cf15130c8c
37 changed files with 1082 additions and 69 deletions

View File

@ -228,7 +228,7 @@ VAR_DIRS="$VAR_LOCATION/remotes \
$VAR_LOCATION/remotes/tm/shared \
$VAR_LOCATION/remotes/tm/qcow2 \
$VAR_LOCATION/remotes/tm/ssh \
$VAR_LOCATION/remotes/tm/vmware \
$VAR_LOCATION/remotes/tm/vmfs \
$VAR_LOCATION/remotes/tm/iscsi \
$VAR_LOCATION/remotes/tm/lvm \
$VAR_LOCATION/remotes/hooks \
@ -237,6 +237,7 @@ VAR_DIRS="$VAR_LOCATION/remotes \
$VAR_LOCATION/remotes/datastore/dummy \
$VAR_LOCATION/remotes/datastore/fs \
$VAR_LOCATION/remotes/datastore/vmware \
$VAR_LOCATION/remotes/datastore/vmfs \
$VAR_LOCATION/remotes/datastore/iscsi \
$VAR_LOCATION/remotes/datastore/lvm \
$VAR_LOCATION/remotes/auth \
@ -416,7 +417,7 @@ INSTALL_FILES=(
TM_SHARED_FILES:$VAR_LOCATION/remotes/tm/shared
TM_QCOW2_FILES:$VAR_LOCATION/remotes/tm/qcow2
TM_SSH_FILES:$VAR_LOCATION/remotes/tm/ssh
TM_VMWARE_FILES:$VAR_LOCATION/remotes/tm/vmware
TM_VMFS_FILES:$VAR_LOCATION/remotes/tm/vmfs
TM_ISCSI_FILES:$VAR_LOCATION/remotes/tm/iscsi
TM_LVM_FILES:$VAR_LOCATION/remotes/tm/lvm
TM_DUMMY_FILES:$VAR_LOCATION/remotes/tm/dummy
@ -424,6 +425,7 @@ INSTALL_FILES=(
DATASTORE_DRIVER_DUMMY_SCRIPTS:$VAR_LOCATION/remotes/datastore/dummy
DATASTORE_DRIVER_FS_SCRIPTS:$VAR_LOCATION/remotes/datastore/fs
DATASTORE_DRIVER_VMWARE_SCRIPTS:$VAR_LOCATION/remotes/datastore/vmware
DATASTORE_DRIVER_VMFS_SCRIPTS:$VAR_LOCATION/remotes/datastore/vmfs
DATASTORE_DRIVER_ISCSI_SCRIPTS:$VAR_LOCATION/remotes/datastore/iscsi
DATASTORE_DRIVER_LVM_SCRIPTS:$VAR_LOCATION/remotes/datastore/lvm
NETWORK_FILES:$VAR_LOCATION/remotes/vnm
@ -877,16 +879,17 @@ TM_DUMMY_FILES="src/tm_mad/dummy/clone \
src/tm_mad/dummy/postmigrate \
src/tm_mad/dummy/mvds"
TM_VMWARE_FILES="src/tm_mad/vmware/clone \
src/tm_mad/vmware/delete
src/tm_mad/vmware/ln \
src/tm_mad/vmware/mkswap \
src/tm_mad/vmware/mkimage \
src/tm_mad/vmware/mv \
src/tm_mad/vmware/context \
src/tm_mad/vmware/premigrate \
src/tm_mad/vmware/postmigrate \
src/tm_mad/vmware/mvds"
TM_VMFS_FILES="src/tm_mad/vmfs/clone \
src/tm_mad/vmfs/delete
src/tm_mad/vmfs/ln \
src/tm_mad/vmfs/mkswap \
src/tm_mad/vmfs/mkimage \
src/tm_mad/vmfs/mv \
src/tm_mad/vmfs/context \
src/tm_mad/vmfs/mvds \
src/tm_mad/vmfs/tm_vmfs.conf \
src/tm_mad/vmfs/postmigrate \
src/tm_mad/vmfs/premigrate"
TM_ISCSI_FILES="src/tm_mad/iscsi/clone \
src/tm_mad/iscsi/ln \
@ -909,6 +912,7 @@ TM_LVM_FILES="src/tm_mad/lvm/clone \
# - Dummy Image Repository, $REMOTES_LOCATION/datastore/dummy
# - FS based Image Repository, $REMOTES_LOCATION/datastore/fs
# - VMware based Image Repository, $REMOTES_LOCATION/datastore/vmware
# - VMFS based Image Repository, $REMOTES_LOCATION/datastore/vmfs
# - iSCSI based Image Repository, $REMOTES_LOCATION/datastore/iscsi
# - LVM based Image Repository, $REMOTES_LOCATION/datastore/lvm
#-------------------------------------------------------------------------------
@ -935,6 +939,13 @@ DATASTORE_DRIVER_VMWARE_SCRIPTS="src/datastore_mad/remotes/vmware/cp \
src/datastore_mad/remotes/vmware/clone \
src/datastore_mad/remotes/vmware/rm"
DATASTORE_DRIVER_VMFS_SCRIPTS="src/datastore_mad/remotes/vmfs/cp \
src/datastore_mad/remotes/vmfs/mkfs \
src/datastore_mad/remotes/vmfs/stat \
src/datastore_mad/remotes/vmfs/clone \
src/datastore_mad/remotes/vmfs/rm \
src/datastore_mad/remotes/vmfs/vmfs.conf"
DATASTORE_DRIVER_ISCSI_SCRIPTS="src/datastore_mad/remotes/iscsi/cp \
src/datastore_mad/remotes/iscsi/mkfs \
src/datastore_mad/remotes/iscsi/stat \

View File

@ -286,7 +286,7 @@ VM_MAD = [
TM_MAD = [
executable = "one_tm",
arguments = "-t 15 -d dummy,lvm,shared,qcow2,ssh,vmware,iscsi" ]
arguments = "-t 15 -d dummy,lvm,shared,qcow2,ssh,vmfs,iscsi" ]
#*******************************************************************************
# Datastore Driver Configuration
@ -303,7 +303,7 @@ TM_MAD = [
DATASTORE_MAD = [
executable = "one_datastore",
arguments = "-t 15 -d fs,vmware,iscsi,lvm"
arguments = "-t 15 -d fs,vmware,vmfs,iscsi,lvm"
]
#*******************************************************************************

View File

@ -894,20 +894,18 @@ function popUpCreateVMDialog(){
$('#network_box,#disk_box',dialog).change(function(){
$(this).val("");
return false;
});
$('#network_box option,#disk_box option',dialog).click(function(){
var clicked = $(this).attr('clicked');
var option = $('option:selected', this);
var clicked = option.attr('clicked');
if (clicked){//unbold, unmark
$(this).text($(this).text().replace(/☒/g,'☐'));
$(this).removeAttr('clicked');
option.text(option.text().replace(/☒/g,'☐'));
option.removeAttr('clicked');
}
else {//bold,mark
$(this).text($(this).text().replace(/☐/g,'☒'));
$(this).attr('clicked','clicked');
option.text(option.text().replace(/☐/g,'☒'));
option.attr('clicked','clicked');
}
$(this).val("");
return false;
});

View File

@ -152,3 +152,15 @@ function check_restricted {
echo 0
}
#-------------------------------------------------------------------------------
# Gets the ESX host to be used as bridge to register a VMware disk
# Implements a round robin for the bridges
# @param $1 - Path to the list of ESX hosts to be used as bridges
# @return host to be used as bridge
#-------------------------------------------------------------------------------
function get_destination_host {
HOSTS_ARRAY=($BRIDGE_LIST)
ARRAY_INDEX=`expr $1 % ${#HOSTS_ARRAY[@]}`
echo ${HOSTS_ARRAY[$ARRAY_INDEX]}
}

View File

@ -0,0 +1,89 @@
#!/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
VMWARERC=/etc/one/vmwarerc
else
LIB_LOCATION=$ONE_LOCATION/lib
VMWARERC=$ONE_LOCATION/etc/vmwarerc
fi
. $LIB_LOCATION/sh/scripts_common.sh
DRIVER_PATH=$(dirname $0)
source ${DRIVER_PATH}/../libfs.sh
source ${DRIVER_PATH}/vmfs.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/UMASK \
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/BRIDGE_LIST \
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/DS_USE_SSH \
/DS_DRIVER_ACTION_DATA/DATASTORE/ID \
/DS_DRIVER_ACTION_DATA/IMAGE/PATH \
/DS_DRIVER_ACTION_DATA/IMAGE/ID)
BASE_PATH="${XPATH_ELEMENTS[0]}"
UMASK="${XPATH_ELEMENTS[1]}"
BRIDGE_LIST="${XPATH_ELEMENTS[2]}"
USE_SSH="${XPATH_ELEMENTS[3]:-$DS_USE_SSH}"
DS_ID="${XPATH_ELEMENTS[4]}"
SRC="${XPATH_ELEMENTS[5]}"
IMAGE_ID="${XPATH_ELEMENTS[6]}"
SRC_FOLDER=`basename $SRC`
DST=`generate_image_path`
DST_FOLDER=`basename $DST`
DST_HOST=`get_destination_host $IMAGE_ID`
# ------------ Set up datastore -------------
set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS" "$UMASK"
vmfs_set_up
# ------------ Copy the image to the repository -------------
log "Copying local image $SRC to the image repository"
if [ "$USE_SSH" == "yes" ]; then
ssh_exec_and_log "$VMKFSTOOLS $VI_PARAMS $SRC $DST" "Error copying $SRC to $DST"
else
exec_and_log "vifs $VI_PARAMS --copy [$DS_ID]$SRC_FOLDER [$DS_ID]$DST_FOLDER" \
"Error copying $SRC to $DST"
fi
echo "$DST"

162
src/datastore_mad/remotes/vmfs/cp Executable file
View File

@ -0,0 +1,162 @@
#!/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
VMWARERC=/etc/one/vmwarerc
else
LIB_LOCATION=$ONE_LOCATION/lib
VMWARERC=$ONE_LOCATION/etc/vmwarerc
fi
. $LIB_LOCATION/sh/scripts_common.sh
DRIVER_PATH=$(dirname $0)
source ${DRIVER_PATH}/../libfs.sh
source ${DRIVER_PATH}/vmfs.conf
# -------- Get cp and datastore arguments from OpenNebula core ------------
DRV_ACTION=$1
ID=$2
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/ID \
/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/DS_USE_SSH \
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/DS_TMP_DIR \
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/UMASK \
/DS_DRIVER_ACTION_DATA/IMAGE/PATH \
/DS_DRIVER_ACTION_DATA/IMAGE/TEMPLATE/MD5 \
/DS_DRIVER_ACTION_DATA/IMAGE/TEMPLATE/SHA1 \
/DS_DRIVER_ACTION_DATA/IMAGE/ID)
BASE_PATH="${XPATH_ELEMENTS[0]}"
DS_ID="${XPATH_ELEMENTS[1]}"
RESTRICTED_DIRS="${XPATH_ELEMENTS[2]}"
SAFE_DIRS="${XPATH_ELEMENTS[3]}"
BRIDGE_LIST="${XPATH_ELEMENTS[4]}"
USE_SSH="${XPATH_ELEMENTS[5]:-$DS_USE_SSH}"
TMP_DIR="${XPATH_ELEMENTS[6]:-$DS_TMP_DIR}"
UMASK="${XPATH_ELEMENTS[7]}"
SRC="${XPATH_ELEMENTS[8]}"
MD5="${XPATH_ELEMENTS[9]}"
SHA1="${XPATH_ELEMENTS[10]}"
IMAGE_ID="${XPATH_ELEMENTS[11]}"
FE_DST=`generate_image_path`
DST_FOLDER=`basename $FE_DST`
DST="/vmfs/volumes/$DS_ID/$DST_FOLDER"
DST_HOST=`get_destination_host $IMAGE_ID`
# ------------ Set up datastore -------------
set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS" "$UMASK"
vmfs_set_up
vmfs_create_remote_path $DS_ID
# ------------ Prepare for a possible download in the front-end -------------
if [ ! -d $TMP_DIR ]; then
mkdir -p $TMP_DIR
fi
HASHES=""
if [ -n "$MD5" ]; then
HASHES="$HASHES --md5 $MD5"
fi
if [ -n "$SHA1" ]; then
HASHES="$HASHES --sha1 $SHA1"
fi
COPY_COMMAND="$UTILS_PATH/downloader.sh $HASHES $SRC $TMP_DIR/$IMAGE_HASH"
# ------------ Copy the image to the repository -------------
case $SRC in
http://*|https://* )
log "Downloading $SRC to the image repository"
exec_and_log "$COPY_COMMAND" "Error downloading $SRC"
SRC="$TMP_DIR/$IMAGE_HASH"
;;
*)
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 disk folder $SRC to the image repository"
if [ ! -d $SRC ]; then
exec_and_log "$COPY_COMMAND" "Error copying $SRC to $TMP_DIR/$IMAGE_HASH"
SRC="$TMP_DIR/$IMAGE_HASH"
fi
;;
esac
# Rename the disk filename to disk.vmdk (warning: it does so in SRC)
if [ ! -f $SRC/disk.vmdk ]; then
BASE_DISK_FILE=`ls $SRC | grep -v '\-\(flat\|delta\|s[0-9]*\)\.vmdk$'`
exec_and_log "mv -f $SRC/$BASE_DISK_FILE $SRC/disk.vmdk" \
"Error renaming disk file $SRC/$BASE_DISK_FILE to $SRC/disk.vmdk"
fi
# Make the final hop, front-end -> VMFS Datastore
if [ "$USE_SSH" == "yes" ]; then
exec_and_log "$SCP -r $SRC/* $DST_HOST:$DST" "Error copying $SRC to $DST through SCP"
else
cd $SRC
for file in $(find . -type f); do
FNAME=$(basename $file)
exec_and_log "vifs $VI_PARAMS -p $file [$DS_ID]$DST_FOLDER/$FNAME" \
"Cannot upload $file to $DST/$FNAME on $DST_HOST"
done
fi
if [ -d "$TMP_DIR/$IMAGE_HASH" -a -n "$IMAGE_HASH" ]; then
rm -rf "$TMP_DIR/$IMAGE_HASH" > /dev/null 2>&1
fi
echo "$DST"

View File

@ -0,0 +1,107 @@
#!/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 create a VM image (SRC) of size (SIZE) and formatted
# as (FS)
###############################################################################
# -------- Set up the environment to source common tools & conf ------------
if [ -z "${ONE_LOCATION}" ]; then
LIB_LOCATION=/usr/lib/one
VMWARERC=/etc/one/vmwarerc
else
LIB_LOCATION=$ONE_LOCATION/lib
VMWARERC=$ONE_LOCATION/etc/vmwarerc
fi
. $LIB_LOCATION/sh/scripts_common.sh
DRIVER_PATH=$(dirname $0)
source ${DRIVER_PATH}/../libfs.sh
source ${DRIVER_PATH}/vmfs.conf
# -------- Get mkfs 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/DS_USE_SSH \
/DS_DRIVER_ACTION_DATA/DATASTORE/ID \
/DS_DRIVER_ACTION_DATA/IMAGE/FSTYPE \
/DS_DRIVER_ACTION_DATA/IMAGE/SIZE \
/DS_DRIVER_ACTION_DATA/IMAGE/ID)
BASE_PATH="${XPATH_ELEMENTS[0]}"
RESTRICTED_DIRS="${XPATH_ELEMENTS[1]}"
SAFE_DIRS="${XPATH_ELEMENTS[2]}"
UMASK="${XPATH_ELEMENTS[3]}"
USE_SSH="${XPATH_ELEMENTS[4]:-$DS_USE_SSH}"
DS_ID="${XPATH_ELEMENTS[5]}"
FSTYPE="${XPATH_ELEMENTS[6]}"
SIZE="${XPATH_ELEMENTS[7]}"
IMAGE_ID="${XPATH_ELEMENTS[8]}"
DST=`generate_image_path`
DST_DIR=`dirname $DST`
DST_FOLDER=`basename $DST`
DST_HOST=`get_destination_host $IMAGE_ID`
# ------------ Set up datastore -------------
set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS" "$UMASK"
vmfs_set_up
vmfs_create_remote_path $DS_ID
# ------------ Image to save_as disk, no need to create a FS ------------
if [ "$FSTYPE" = "save_as" ]; then
echo "$DST"
exit 0
fi
# ------------ Create the image within the image datastore ------------
log "Making filesystem of ${SIZE}M (with no format) at [$DS_ID]$DST_FOLDER on $DST_HOST"
IMAGE_FORMAT=vmdk
VMWARE_DISK_TYPE=`echo $FSTYPE|cut -d'_' -f 2`
if [ "$USE_SSH" == "yes" ]; then
$SSH $DST_HOST $VMKFSTOOLS -U [$DS_ID]$DST_FOLDER/disk.vmdk &> /dev/null
ssh_exec_and_log $DST_HOST "$VMKFSTOOLS -c ${SIZE}M -d ${VMWARE_DISK_TYPE} /vmfs/volumes/$DS_ID/$DST_FOLDER/disk.vmdk" \
"Cannot create [$DS_ID] $DST_FOLDER/disk.vmdk on $DST_HOST"
else
$VMKFSTOOLS $VI_PARAMS -U [$DS_ID]$DST_FOLDER/disk.vmdk &> /dev/null
exec_and_log "$VMKFSTOOLS $VI_PARAMS -c ${SIZE}M -d ${VMWARE_DISK_TYPE} [$DS_ID]$DST_FOLDER/disk.vmdk" \
"Cannot create $DS_ID]$DST_FOLDER/disk.vmdk on $DST_HOST"
fi
echo "/vmfs/volumes/$DS_ID/$DST_FOLDER"

View File

@ -0,0 +1,87 @@
#!/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 remove a VM image (SRC) from the image repository
###############################################################################
# ------------ Set up the environment to source common tools ------------
if [ -z "${ONE_LOCATION}" ]; then
LIB_LOCATION=/usr/lib/one
VMWARERC=/etc/one/vmwarerc
else
LIB_LOCATION=$ONE_LOCATION/lib
VMWARERC=$ONE_LOCATION/etc/vmwarerc
fi
. $LIB_LOCATION/sh/scripts_common.sh
DRIVER_PATH=$(dirname $0)
source ${DRIVER_PATH}/../libfs.sh
source ${DRIVER_PATH}/vmfs.conf
# -------- Get rm 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/IMAGE/SOURCE \
/DS_DRIVER_ACTION_DATA/DATASTORE/ID \
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/DS_USE_SSH \
/DS_DRIVER_ACTION_DATA/IMAGE/ID)
SRC="${XPATH_ELEMENTS[0]}"
DS_ID="${XPATH_ELEMENTS[1]}"
USE_SSH="${XPATH_ELEMENTS[4]:-$DS_USE_SSH}"
IMAGE_ID="${XPATH_ELEMENTS[2]}"
DST_HOST=`get_destination_host $IMAGE_ID`
DST_FOLDER=`basename $SRC`
# ------------ Set up datastore ------------
vmfs_set_up
# ------------ Remove the image from the repository ------------
log "Removing $SRC from the image repository"
if [ "$USE_SSH" == "yes" ]; then
if [ -n $DS_ID -a -n $DST_FOLDER ]; then
ssh_exec_and_log $DST_HOST "rm -rf /vmfs/volumes/$DS_ID/$DST_FOLDER" \
"Error deleting $SRC"
fi
else
# We have to erase the contents of the folder one by one
FILES_TO_ERASE=`vifs $VI_PARAMS --dir [$DS_ID]$DST_FOLDER|grep -v "Content Listing"|grep -v "\-\-\-\-\-\-\-\-"|egrep -v "^[[:space:]]*$"`
for file in $FILES_TO_ERASE; do
exec_and_log "vifs $VI_PARAMS --force --rm [$DS_ID]$DST_FOLDER/$file" \
"Cannot delete $DST_FOLDER/$file in $DST_HOST"
done
exec_and_log "vifs $VI_PARAMS --force --rm [$DS_ID]$DST_FOLDER" \
"Cannot delete $DST_FOLDER in $DST_HOST"
fi
exit 0

View File

@ -0,0 +1 @@
../common/stat

View File

@ -0,0 +1,25 @@
# -------------------------------------------------------------------------- #
# 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. #
#--------------------------------------------------------------------------- #
# Default values in case they are not defined in the Datastore template
DS_TMP_DIR=/var/lib/one/tmp
# Whether the VMFS Datastore driver should use to invoke the VMFS native commands
# * remote API calls (value set to "no")
# * ssh connection (value set to "yes")
DS_USE_SSH=no

View File

@ -99,7 +99,11 @@ conf = YAML::load(File.read(CONF_FILE))
@uri = conf[:libvirt_uri].gsub!('@HOST@', host)
@user = conf[:username]
@pass = conf[:password]
if conf[:password] and !conf[:password].empty?
@pass=conf[:password]
else
@pass="\"\""
end
# Poll the VMware hypervisor

View File

@ -409,3 +409,37 @@ function iqn_get_host {
VG_NAME=$(iqn_get_vg_name "$IQN")
echo ${TARGET%%.$VG_NAME.$LV_NAME}
}
function vmfs_create_remote_path {
DS_ID=$1
# Create DST in DST_HOST
if [ "$USE_SSH" == "yes" ]; then
exec_and_log "ssh_make_path $DST_HOST $DST" \
"Cannot create $DST in $DST_HOST"
else
exec_and_log "vifs $VI_PARAMS --mkdir [$DS_ID]$DST_FOLDER" \
"Cannot create [$DS_ID]$DST_FOLDER in $DST_HOST"
fi
}
function vmfs_set_up {
if [ "$USE_SSH" != "yes" ]; then
USERNAME=`echo $(cat $VMWARERC |grep ":username:"|cut -d":" -f 3|tr -d '"')`
PASSWORD=`echo $(cat $VMWARERC |grep ":password:"|cut -d":" -f 3|tr -d '"')`
if [ -z $PASSWORD ]; then
VI_PARAMS="--server $DST_HOST --username $USERNAME --password \"\""
else
VI_PARAMS="--server $DST_HOST --username $USERNAME --password $PASSWORD"
fi
fi
}
function vmfs_create_double_path {
DS_ID=$1
FIRST_FOLDER=$2
SECOND_FOLDER=$3
# Two calls needed since vifs cannot do a mkdir -p
vifs $VI_PARAMS --force --mkdir [$DS_ID]$FIRST_FOLDER &> /dev/null
vifs $VI_PARAMS --force --mkdir [$DS_ID]$FIRST_FOLDER/$SECOND_FOLDER &> /dev/null
}

View File

@ -128,7 +128,7 @@ $(document).ready(function () {
applyDefaultStyles: false
, center__paneSelector: ".outer-center"
, west__paneSelector: ".outer-west"
, west__size: 200
, west__size: 210
, north__size: 26
, south__size: 26
, spacing_open: 0 // ALL panes

View File

@ -73,8 +73,8 @@ var create_datastore_tmpl =
<option value="ssh">' + tr("SSH") + '</option>\
<option value="iscsi">' + tr("iSCSI") + '</option>\
<option value="dummy">' + tr("Dummy") + '</option>\
</select><br />\
<label>' + tr("Disk type") + ':</label>\
</select><div class="clear">\
<label for="disk_type">' + tr("Disk type") + ':</label>\
<select id="disk_type" name="disk_type">\
<option value="file">' + tr("File") + '</option>\
<option value="block">' + tr("Block") + '</option>\

View File

@ -813,7 +813,7 @@ function setupCreateImageDialog(){
});
//we pop up an upload progress dialog
var pos_top = $(window).height() - 120;
var pos_left = 190;
var pos_left = 220;
var pb_dialog = $('<div id="pb_dialog" title="'+
tr("Uploading...")+'">'+
'<div id="upload-progress"></div>'+

View File

@ -85,7 +85,7 @@ function humanize_size(value,from_bytes) {
if (typeof(value) === "undefined") {
value = 0;
}
var binarySufix = from_bytes ?
var binarySufix = from_bytes ?
["", "K", "M", "G", "T" ] : ["K", "M", "G", "T" ];
var i=0;
while (value > 1024 && i < 3){
@ -567,8 +567,8 @@ function getSelectedNodes(dataTable){
return selected_nodes;
}
//returns a HTML string with options for
//a select input code generated from a dataTable.
//returns a HTML string with options for
//a select input code generated from a dataTable.
//Allows filtering elements specifing status columns
//and bad status (if the values of the columns match the bad status)
//then this elem is skipped.
@ -590,7 +590,7 @@ function makeSelectOptions(dataTable,
//ASSUMPTION: elem id in column 1
var id = elem[1];
var name = elem[option_name_col];
var status, bad_status;
var ok=true;
@ -826,7 +826,9 @@ function popUpTemplateUpdateDialog(elem_str,select_items,sel_elems){
//Shows run a custom action when clicking on rows.
function infoListener(dataTable, info_action){
$('tbody tr',dataTable).live("click",function(e){
if ($(e.target).is('input')) {return true;}
if ($(e.target).is('input') ||
$(e.target).is('select') ||
$(e.target).is('option')) return true;
var aData = dataTable.fnGetData(this);
var id = $(aData[0]).val();

View File

@ -10,6 +10,11 @@
<script type="text/javascript" src="vendor/jQuery/jquery-1.7.2.min.js"></script>
<!-- End Vendor Libraries -->
<!--[if IE]>
<script type="text/javascript" src="vendor/crypto-js/core-min.js"></script>
<script type="text/javascript" src="vendor/crypto-js/enc-base64-min.js"></script>
<![endif]-->
<script type="text/javascript" src="js/opennebula.js"></script>
<script type="text/javascript" src="js/login.js"></script>

View File

@ -79,7 +79,7 @@ else
log "Linking $SRC_PATH in $DST"
ssh_exec_and_log $DST_HOST \
"cd $DST_DIR; ln -s $SRC_PATH $DST_PATH" \
"cd $DST_DIR; rm $DST_PATH ; ln -s $SRC_PATH $DST_PATH" \
"Error linking $SRC to $DST"
fi

View File

@ -88,3 +88,25 @@ function make_relative {
echo $dots${src#$common/}
}
# Gets wether the vmfs drivers should use ssh or not
function get_tm_use_ssh {
DATASTORE_ID=$1
#-------------------------------------------------------------------------------
# Get datastore information
#-------------------------------------------------------------------------------
XPATH="${ONE_LOCAL_VAR}/remotes/datastore/xpath.rb --stdin"
unset i XPATH_ELEMENTS
while IFS= read -r -d '' element; do
XPATH_ELEMENTS[i++]="$element"
done < <(onedatastore show -x $DATASTORE_ID| $XPATH \
/DATASTORE/TEMPLATE/TM_USE_SSH)
TM_USE_SSH="${XPATH_ELEMENTS[0]:-$TM_USE_SSH}"
echo $TM_USE_SSH
}

109
src/tm_mad/vmfs/clone Executable file
View File

@ -0,0 +1,109 @@
#!/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. #
#--------------------------------------------------------------------------- #
# clone fe:SOURCE host:remote_system_ds/disk.i vmid dsid
# - fe is the front-end hostname
# - SOURCE is the path of the disk image in the form DS_BASE_PATH/disk
# - host is the target host to deploy the VM
# - remote_system_ds is the path for the system datastore in the host
# - vmid is the id of the VM
# - dsid is the target datastore (0 is the system datastore)
SRC=$1
DST=$2
VMID=$3
DSID=$4
if [ -z "${ONE_LOCATION}" ]; then
TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
VMWARERC=/etc/one/vmwarerc
else
TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
VMWARERC=$ONE_LOCATION/etc/vmwarerc
fi
. $TMCOMMON
source $(dirname $0)/tm_vmfs.conf
#-------------------------------------------------------------------------------
# Retrieve needed information, set dst path and dir
#-------------------------------------------------------------------------------
SRC_PATH=`arg_path $SRC`
SRC_FOLDER=`basename $SRC_PATH`
DST_PATH=`arg_path $DST`
DST_HOST=`arg_host $DST`
DST_DIR=`dirname $DST_PATH`
DST_FOLDER=`basename $DST_PATH`
IMAGE_DS_NAME=`basename $(dirname $SRC_PATH)`
SYSTEM_DS_NAME=`basename $(dirname $(dirname $DST_PATH))`
USE_SSH=$(get_tm_use_ssh $IMAGE_DS_NAME)
#-------------------------------------------------------------------------------
# Set up datastore
#-------------------------------------------------------------------------------
vmfs_set_up
#-------------------------------------------------------------------------------
# Create remote folder
#-------------------------------------------------------------------------------
if [ "$USE_SSH" == "yes" ]; then
ssh_make_path $DST_HOST $DST_PATH
else
vmfs_create_double_path $SYSTEM_DS_NAME $VMID $DST_FOLDER
fi
#-------------------------------------------------------------------------------
# Clone (cp) SRC into DST
#-------------------------------------------------------------------------------
log "Cloning $SRC_PATH in $DST"
if [ "$USE_SSH" == "yes" ]; then
CLONESCRIPT=$(cat <<EOF
cd $DST_DIR
export PATH=/usr/sbin:/sbin:\$PATH
if which sudo > /dev/null; then
SUDO_CMD="sudo "
fi
\$SUDO_CMD $VMKFSTOOLS -U $DST_PATH/disk.vmdk
\$SUDO rm $DST_PATH/*
\$SUDO_CMD $VMKFSTOOLS -i $SRC_PATH/disk.vmdk -d thin $DST_PATH/disk.vmdk
EOF
)
ssh_exec_and_log $DST_HOST "$CLONESCRIPT" "Error cloning $SRC to $DST"
else
$VMKFSTOOLS $VI_PARAMS -U [$SYSTEM_DS_NAME]$VMID/$DST_FOLDER/disk.vmdk &> /dev/null
# Erase in case that vmkfstool didn't recognize the disk
FILES_TO_ERASE=`vifs $VI_PARAMS --dir [$SYSTEM_DS_NAME]$VMID/$DST_FOLDER|grep -v "Content Listing"|grep -v "\-\-\-\-\-\-\-\-"|egrep -v "^[[:space:]]*$"`
for file in $FILES_TO_ERASE; do
vifs $VI_PARAMS --force --rm [$SYSTEM_DS_NAME]$VMID/$DST_FOLDER/$file
done
exec_and_log "$VMKFSTOOLS $VI_PARAMS -i [$IMAGE_DS_NAME]$SRC_FOLDER/disk.vmdk -d thin [$SYSTEM_DS_NAME]$VMID/$DST_FOLDER/disk.vmdk" \
"Error cloning $SRC to $DST"
fi
exit 0

103
src/tm_mad/vmfs/context Executable file
View File

@ -0,0 +1,103 @@
#!/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. #
#--------------------------------------------------------------------------- #
# context context.sh file1 file2 ... fileN host:remote_system_ds/disk.i vmid 0
# - context.sh file are the contents of the context ISO
# - host is the target host to deploy the VM
# - remote_system_ds is the path for the system datastore in the host
# - vmid is the id of the VM
# - 0 is the target datastore (system)
ARGV=("$@")
DS_ID="${ARGV[$(($#-1))]}"
VM_ID="${ARGV[$(($#-2))]}"
DST="${ARGV[$(($#-3))]}"
SRC="${ARGV[@]:0:$(($#-3))}"
if [ -z "${ONE_LOCATION}" ]; then
TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
VMWARERC=/etc/one/vmwarerc
else
TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
VMWARERC=$ONE_LOCATION/etc/vmwarerc
fi
. $TMCOMMON
source $(dirname $0)/tm_vmfs.conf
#-------------------------------------------------------------------------------
# Retrieve needed information, set dst path and dir
#-------------------------------------------------------------------------------
DST_PATH=`arg_path $DST`
DST_HOST=`arg_host $DST`
DST_DIR=`dirname $DST_PATH`
DST_FOLDER=`basename $DST_PATH`
USE_SSH=$(get_tm_use_ssh $DS_ID)
#-------------------------------------------------------------------------------
# Set up datastore
#-------------------------------------------------------------------------------
vmfs_set_up
#-------------------------------------------------------------------------------
# Create remote folder
#-------------------------------------------------------------------------------
if [ "$USE_SSH" == "yes" ]; then
ssh_make_path $DST_HOST $DST_DIR
else
vmfs_create_double_path $DS_ID $VM_ID $DST_FOLDER
fi
#-------------------------------------------------------------------------------
# Build the Context Block device (locally) and copy it remotely
#-------------------------------------------------------------------------------
log "Generating context block device at $DST"
ISO_DIR="$DS_DIR/.isofiles/$VM_ID"
ISO_FILE="$ISO_DIR/$VM_ID.iso"
exec_and_log "mkdir -p $ISO_DIR" "Could not create tmp dir to make context dev"
for f in $SRC; do
case $f in
http://*)
exec_and_log "$WGET -P $ISO_DIR $f" "Error downloading $f"
;;
*)
exec_and_log "cp -R $f $ISO_DIR" "Error copying $f to $ISO_DIR"
;;
esac
done
exec_and_log "$MKISOFS -o $ISO_FILE -J -R $ISO_DIR" "Error creating iso fs"
if [ "$USE_SSH" == "yes" ]; then
exec_and_log "$SCP $ISO_FILE $DST_PATH.iso" "Error copying context ISO to $DST"
else
# Copies the iso file with .iso suffix, needed for VMware CDROMs
vifs $VI_PARAMS -rm [$DS_ID]$VM_ID/$DST_FOLDER.iso
exec_and_log "vifs $VI_PARAMS -p $ISO_FILE [$DS_ID]$VM_ID/$DST_FOLDER.iso" \
"Error copying context ISO to [$DS_ID]$VM_ID/$DST_FOLDER.iso in $DST_HOST"
fi
rm -rf $ISO_DIR > /dev/null 2>&1
exit 0

86
src/tm_mad/vmfs/delete Executable file
View File

@ -0,0 +1,86 @@
#!/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. #
#--------------------------------------------------------------------------- #
# DELETE <host:remote_system_ds/disk.i|host:remote_system_ds/> vmid dsid
# - host is the target host to deploy the VM
# - remote_system_ds is the path for the system datastore in the host
# - vmid is the id of the VM
# - dsid is the target datastore (0 is the system datastore)
DST=$1
VMID=$2
DSID=$3
# Wait for the cancel action on the VM to complete
sleep 10
if [ -z "${ONE_LOCATION}" ]; then
TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
VMWARERC=/etc/one/vmwarerc
else
TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
VMWARERC=$ONE_LOCATION/etc/vmwarerc
fi
. $TMCOMMON
source $(dirname $0)/tm_vmfs.conf
#-------------------------------------------------------------------------------
# Retrieve needed information
#-------------------------------------------------------------------------------
USE_SSH=$(get_tm_use_ssh $DSID)
#-------------------------------------------------------------------------------
# Set up datastore
#-------------------------------------------------------------------------------
vmfs_set_up
#-------------------------------------------------------------------------------
# Return if deleting a disk, we will delete them when removing the
# remote_system_ds directory for the VM (remotely)
#-------------------------------------------------------------------------------
DST_PATH=`arg_path $DST`
DST_HOST=`arg_host $DST`
if [ `is_disk $DST_PATH` -eq 1 ]; then
exit 0
fi
log "Deleting $DST_PATH"
if [ "$USE_SSH" == "yes" ]; then
ssh_exec_and_log $DST_HOST "rm -rf $DST_PATH" "Error deleting $DST_PATH"
else
DIRS_TO_ERASE=`vifs $VI_PARAMS --dir [$DSID]$VMID|grep -v "Content Listing"|grep -v "\-\-\-\-\-\-\-\-"|egrep -v "^[[:space:]]*$"`
for dir in $DIRS_TO_ERASE; do
FILES_TO_ERASE=`vifs $VI_PARAMS --dir [$DSID]$VMID/$dir|grep -v "Content Listing"|grep -v "\-\-\-\-\-\-\-\-"|egrep -v "^[[:space:]]*$"`
for file in $FILES_TO_ERASE; do
exec_and_log "vifs $VI_PARAMS --force --rm [$DSID]$VMID/$dir/$file" \
"Cannot delete [$DSID]$VMID/$dir/$file in $DST_HOST"
done
exec_and_log "vifs $VI_PARAMS --force --rm [$DSID]$VMID/$dir" \
"Cannot delete [$DSID]$VMID in $DST_HOST"
done
exec_and_log "vifs $VI_PARAMS --force --rm [$DSID]$VMID" \
"Cannot delete [$DSID]$VMID in $DST_HOST"
fi
exit 0

View File

@ -16,7 +16,7 @@
# limitations under the License. #
#--------------------------------------------------------------------------- #
# clone fe:SOURCE host:remote_system_ds/disk.i vmid dsid
# ln fe:SOURCE host:remote_system_ds/disk.i vmid dsid
# - fe is the front-end hostname
# - SOURCE is the path of the disk image in the form DS_BASE_PATH/disk
# - host is the target host to deploy the VM
@ -37,9 +37,10 @@ else
fi
. $TMCOMMON
source $(dirname $0)/tm_vmfs.conf
#-------------------------------------------------------------------------------
# Set dst path and dir
# Retrieve needed information, set dst path and dir
#-------------------------------------------------------------------------------
SRC_PATH=`arg_path $SRC`
SRC_PATH="../../${SRC_PATH##"$DS_DIR/"}"
@ -48,28 +49,35 @@ DST_PATH=`arg_path $DST`
DST_HOST=`arg_host $DST`
DST_DIR=`dirname $DST_PATH`
ssh_make_path $DST_HOST $DST_PATH
USE_SSH=$(get_tm_use_ssh $DSID)
#-------------------------------------------------------------------------------
# Clone (cp) SRC into DST
# Link (ln) SRC into DST
#-------------------------------------------------------------------------------
log "Cloning $SRC_PATH in $DST"
CLONESCRIPT=$(cat <<EOF
cd $DST_DIR
if [ "$USE_SSH" == "yes" ]; then
ssh_make_path $DST_HOST $DST_PATH
export PATH=/usr/sbin:/sbin:\$PATH
# It's a folder, make links for all elements
SRC_FOLDER_NAME=`basename $SRC_PATH`
SRC_WITH_NO_FOLDER=`dirname $SRC_PATH`
SRC_DS_NAME=`basename $SRC_WITH_NO_FOLDER`
REL_SRC_PATH="../../../$SRC_DS_NAME/$SRC_FOLDER_NAME"
if which sudo > /dev/null; then
SUDO_CMD="sudo "
fi
log "Link all files in $SRC_PATH to $DST_PATH"
\$SUDO_CMD $VMKFSTOOLS -U $DST_PATH/disk.vmdk
\$SUDO_CMD $VMKFSTOOLS -i $SRC_PATH/disk.vmdk -d thin $DST_PATH/disk.vmdk
LINK_SCRIPT=$(cat <<EOF
for file in \$(cd $DST_DIR ; find $SRC_PATH -type f); do
FNAME=\$(basename \$file)
(cd $DST_PATH ; ln -sf $REL_SRC_PATH/\$FNAME $DST_PATH/$FNAME)
done
EOF
)
ssh_exec_and_log $DST_HOST "$CLONESCRIPT" "Error cloning $SRC to $DST"
ssh_exec_and_log $DST_HOST "$LINK_SCRIPT" \
"Could not link dir files from source DS to system DS"
else
log "Cannot link files without SSH enabled on the ESX hosts, calling clone"
exec $(dirname $0)/clone $*
fi
exit 0

96
src/tm_mad/vmfs/mkimage Executable file
View File

@ -0,0 +1,96 @@
#!/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. #
#--------------------------------------------------------------------------- #
# mkimage size format host:remote_system_ds/disk.i vmid dsid
# - size in MB of the image
# - format for the image
# - host is the target host to deploy the VM
# - remote_system_ds is the path for the system datastore in the host
# - vmid is the id of the VM
# - dsid is the target datastore (0 is the system datastore)
SIZE=$1
FSTYPE=$2
DST=$3
VMID=$4
DSID=$5
if [ -z "${ONE_LOCATION}" ]; then
TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
VMWARERC=/etc/one/vmwarerc
else
TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
VMWARERC=$ONE_LOCATION/etc/vmwarerc
fi
. $TMCOMMON
source $(dirname $0)/tm_vmfs.conf
#-------------------------------------------------------------------------------
# Retrieve needed information, set dst path and dir
#-------------------------------------------------------------------------------
DST_PATH=`arg_path $DST`
DST_HOST=`arg_host $DST`
DST_DIR=`dirname $DST_PATH`
DST_FOLDER=`basename $DST_PATH`
USE_SSH=$(get_tm_use_ssh $DSID)
SYSTEM_DS_NAME=`basename $(dirname $(dirname $DST_PATH))`
#-------------------------------------------------------------------------------
# Set up datastore
#-------------------------------------------------------------------------------
vmfs_set_up
#-------------------------------------------------------------------------------
# Make the new image (file-based)
#-------------------------------------------------------------------------------
log "Making filesystem of ${SIZE}M and type $FSTYPE at $DST"
if [ "$USE_SSH" == "yes" ]; then
ssh_make_path $DST_HOST $DST_PATH
MKFS_CMD=`mkfs_command $DST_PATH $FSTYPE $SIZE`
MKSCRIPT=$(cat <<EOF
rm $DST_PATH/*
export PATH=/usr/sbin:/sbin:\$PATH
$MKFS_CMD
EOF
)
ssh_exec_and_log $DST_HOST "$MKSCRIPT" "Could not create image $DST_PATH"
else
vmfs_create_double_path $SYSTEM_DS_NAME $VMID $DST_FOLDER
VMWARE_DISK_TYPE=`echo $FSTYPE|cut -d'_' -f 2`
$VMKFSTOOLS $VI_PARAMS -U [$SYSTEM_DS_NAME]$VMID/$DST_FOLDER/disk.vmdk &> /dev/null
# Erase in case that vmkfstool didn't recognize the disk
FILES_TO_ERASE=`vifs $VI_PARAMS --dir [$SYSTEM_DS_NAME]$VMID/$DST_FOLDER|grep -v "Content Listing"|grep -v "\-\-\-\-\-\-\-\-"|egrep -v "^[[:space:]]*$"`
for file in $FILES_TO_ERASE; do
vifs $VI_PARAMS --force --rm [$SYSTEM_DS_NAME]$VMID/$DST_FOLDER/$file
done
exec_and_log "$VMKFSTOOLS $VI_PARAMS -c ${SIZE}M -d ${VMWARE_DISK_TYPE} [$SYSTEM_DS_NAME]$VMID/$DST_FOLDER/disk.vmdk" \
"Cannot create [$SYSTEM_DS_NAME]$VMID/$DST_FOLDER/disk.vmdk on $DST_HOST"
fi
exit 0

View File

@ -32,27 +32,46 @@ DSID=$4
if [ -z "${ONE_LOCATION}" ]; then
TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
VMWARERC=/etc/one/vmwarerc
else
TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
VMWARERC=$ONE_LOCATION/etc/vmwarerc
fi
. $TMCOMMON
source $(dirname $0)/tm_vmfs.conf
set_ds_location
#-------------------------------------------------------------------------------
# Set dst path and dir
# Retrieve needed information, set dst path and dir
#-------------------------------------------------------------------------------
SRC_PATH=`arg_path $SRC`"/disk.vmdk"
DST_PATH=`arg_path $DST`
DST_PATH="$RMT_DS_DIR/${DST_PATH##"$DS_DIR/"}/disk.vmdk"
SRC_PATH=`arg_path $SRC`
SRC_HOST=`arg_host $SRC`
SRC_FOLDER=`basename $SRC_PATH`
DST_PATH=`arg_path $DST`
DST_FOLDER=`basename $DST_PATH`
USE_SSH=$(get_tm_use_ssh $DSID)
IMAGE_DS_NAME=`basename $(dirname $DST_PATH)`
SYSTEM_DS_NAME=`basename $(dirname $(dirname $SRC_PATH))`
#-------------------------------------------------------------------------------
# Set up datastore
#-------------------------------------------------------------------------------
vmfs_set_up
#-------------------------------------------------------------------------------
# Move the image back to the datastore
#-------------------------------------------------------------------------------
log "Moving [$SYSTEM_DS_NAME]$VMID/$SRC_FOLDER/disk.vmdk to [$IMAGE_DS_NAME]$DST_FOLDER/disk.vmdk"
if [ "$USE_SSH" == "yes" ]; then
MVSCRIPT=$(cat <<EOF
SRC_READLN=eval "$READLINK -f $SRC_PATH"
DST_READLN=eval "$READLINK -f $DST_PATH"
@ -66,7 +85,8 @@ else
SUDO="sudo "
fi
$SUDO $VMKFSTOOLS -i $SRC_PATH -d thin $DST_PATH
$SUDO $VMKFSTOOLS -U [$IMAGE_DS_NAME]$DST_FOLDER/disk.vmdk
$SUDO $VMKFSTOOLS -i [$SYSTEM_DS_NAME]$VMID/$SRC_FOLDER/disk.vmdk -d thin [$IMAGE_DS_NAME]$DST_FOLDER/disk.vmdk
fi
if [ -d $DST_PATH ]; then
@ -77,8 +97,12 @@ fi
EOF
)
log "Moving $SRC_PATH to datastore as $DST_PATH"
ssh_exec_and_log $SRC_HOST "$MVSCRIPT" "Could not move image $DST_PATH"
ssh_exec_and_log $SRC_HOST "$MVSCRIPT" \
"Could not move image [$SYSTEM_DS_NAME]$VMID/$SRC_FOLDER/disk.vmdk to [$IMAGE_DS_NAME]$DST_FOLDER/disk.vmdk in $SRC_HOST"
else
$VMKFSTOOLS $VI_PARAMS -U [$IMAGE_DS_NAME]$DST_FOLDER/disk.vmdk &> /dev/null
exec_and_log "$VMKFSTOOLS $VI_PARAMS -i [$SYSTEM_DS_NAME]$VMID/$SRC_FOLDER/disk.vmdk -d thin [$IMAGE_DS_NAME]$DST_FOLDER/disk.vmdk" \
"Could not move image [$SYSTEM_DS_NAME]$VMID/$SRC_FOLDER/disk.vmdk to [$IMAGE_DS_NAME]$DST_FOLDER/disk.vmdk in $SRC_HOST"
fi
exit 0

View File

@ -0,0 +1,20 @@
# -------------------------------------------------------------------------- #
# 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. #
#--------------------------------------------------------------------------- #
# Whether the TM VMware driver should use to invoke the VMFS native commands
# * remote API calls (value set to "no")
# * ssh connection (value set to "yes")
TM_USE_SSH=no

View File

@ -1 +0,0 @@
../common/context

View File

@ -1 +0,0 @@
../common/delete

View File

@ -1 +0,0 @@
../shared/ln

View File

@ -1 +0,0 @@
../shared/mkimage

View File

@ -24,7 +24,7 @@
#include <libgen.h>
/* ************************************************************************** */
/* Virtual Network :: Database Access Functions */
/* LibVirtDriver :: VMware deployment generator */
/* ************************************************************************** */
const char * LibVirtDriver::vmware_vnm_name = "vmware";

View File

@ -534,6 +534,12 @@ class ExecDriver < VirtualMachineDriver
action = VmmAction.new(self, id, :attach_disk, drv_message)
# Bug #1355, argument character limitation in ESX
# Message not used in vmware anyway
if @hypervisor == "vmware"
drv_message = "drv_message"
end
steps = [
# Perform a PROLOG on the disk
{

View File

@ -50,7 +50,11 @@ class VMwareDriver
@uri = conf[:libvirt_uri].gsub!('@HOST@', host)
@user = conf[:username]
@pass = conf[:password]
if conf[:password] and !conf[:password].empty?
@pass=conf[:password]
else
@pass="\"\""
end
@datacenter = conf[:datacenter]
@vcenter = conf[:vcenter]
@ -176,9 +180,11 @@ class VMwareDriver
# ------------------------------------------------------------------------ #
def restore(checkpoint)
begin
vm_folder=VAR_LOCATION + "/" + File.basename(File.dirname(checkpoint))
last_deployment_file=`ls -1 #{vm_folder}/deployment*|tail -1`
# Define the VM
dfile = VAR_LOCATION + "/" +
File.basename(File.dirname(checkpoint)) + "/deployment.0"
dfile = vm_folder + "/" + last_deployment_file
rescue => e
OpenNebula.log_error("Cannot open checkpoint #{e.message}")
exit -1