diff --git a/install.sh b/install.sh index 0c2304050e..e8403dd398 100755 --- a/install.sh +++ b/install.sh @@ -529,8 +529,6 @@ INSTALL_ETC_FILES=( VMWARE_ETC_FILES:$ETC_LOCATION VMM_EC2_ETC_FILES:$ETC_LOCATION/vmm_ec2 VMM_EXEC_ETC_FILES:$ETC_LOCATION/vmm_exec - DATASTORE_DRIVER_FS_ETC_FILES:$ETC_LOCATION/datastore/ - DATASTORE_DRIVER_VMWARE_ETC_FILES:$ETC_LOCATION/datastore/ IM_EC2_ETC_FILES:$ETC_LOCATION/im_ec2 TM_LVM_ETC_FILES:$ETC_LOCATION/tm/ HM_ETC_FILES:$ETC_LOCATION/hm @@ -808,21 +806,15 @@ TM_VMWARE_FILES="src/tm_mad/vmware/clone \ # - VMware based Image Repository, $REMOTES_LOCATION/datastore/vmware #------------------------------------------------------------------------------- -DATASTORE_DRIVER_FS_ETC_FILES="src/datastore_mad/remotes/fs/fs.conf" - -DATASTORE_DRIVER_VMWARE_ETC_FILES="src/datastore_mad/remotes/vmware/vmware.conf" - DATASTORE_DRIVER_COMMON_SCRIPTS="src/datastore_mad/remotes/xpath.rb \ src/datastore_mad/remotes/libfs.sh" DATASTORE_DRIVER_FS_SCRIPTS="src/datastore_mad/remotes/fs/cp \ src/datastore_mad/remotes/fs/mkfs \ - src/datastore_mad/remotes/fs/mv \ src/datastore_mad/remotes/fs/rm" DATASTORE_DRIVER_VMWARE_SCRIPTS="src/datastore_mad/remotes/vmware/cp \ src/datastore_mad/remotes/vmware/mkfs \ - src/datastore_mad/remotes/vmware/mv \ src/datastore_mad/remotes/vmware/rm" #------------------------------------------------------------------------------- diff --git a/share/etc/oned.conf b/share/etc/oned.conf index 1e51799aaa..4f99071a3c 100644 --- a/share/etc/oned.conf +++ b/share/etc/oned.conf @@ -82,7 +82,8 @@ MAC_PREFIX = "02:00" #******************************************************************************* # DATASTORE_LOCATION: Path for Datastores in the hosts. It IS the same all the # hosts in the cluster. DATASTORE_LOCATION IS ONLY FOR THE HOSTS AND *NOT* THE -# FRONT-END +# FRONT-END. It defaults to /var/lib/one/datastores (or +# $ONE_LOCATION/var/datastores in self-contained mode) # # DEFAULT_IMAGE_TYPE: This can take values # OS Image file holding an operating system @@ -96,7 +97,7 @@ MAC_PREFIX = "02:00" # vd KVM virtual disk #******************************************************************************* -DATASTORE_LOCATION = /var/lib/one/datastores +#DATASTORE_LOCATION = /var/lib/one/datastores DEFAULT_IMAGE_TYPE = "OS" DEFAULT_DEVICE_PREFIX = "hd" diff --git a/src/cli/one_helper.rb b/src/cli/one_helper.rb index c78c6e9ed6..019d80845e 100644 --- a/src/cli/one_helper.rb +++ b/src/cli/one_helper.rb @@ -333,6 +333,11 @@ EOT when "GROUP" then OpenNebula::GroupPool.new(client) when "USER" then OpenNebula::UserPool.new(client) when "DATASTORE" then OpenNebula::DatastorePool.new(client) + when "CLUSTER" then OpenNebula::ClusterPool.new(client) + when "VNET" then OpenNebula::VirtualNetworkPool.new(client) + when "IMAGE" then OpenNebula::ImagePool.new(client) + when "VMTEMPLATE" then OpenNebula::TemplatePool.new(client) + when "VM" then OpenNebula::VirtualMachinePool.new(client) end rc = pool.info diff --git a/src/cli/one_helper/onedatastore_helper.rb b/src/cli/one_helper/onedatastore_helper.rb index b88a5f6b4d..d263fd4316 100644 --- a/src/cli/one_helper/onedatastore_helper.rb +++ b/src/cli/one_helper/onedatastore_helper.rb @@ -68,6 +68,7 @@ class OneDatastoreHelper < OpenNebulaHelper::OneHelper puts str % ["NAME", datastore.name] puts str % ["USER", datastore['UNAME']] puts str % ["GROUP", datastore['GNAME']] + puts str % ["CLUSTER", datastore['CLUSTER']] puts str % ["TYPE", datastore['TYPE']] puts str % ["BASE PATH",datastore['BASE_PATH']] diff --git a/src/cli/one_helper/onehost_helper.rb b/src/cli/one_helper/onehost_helper.rb index 306b1fcf75..74628bb18f 100644 --- a/src/cli/one_helper/onehost_helper.rb +++ b/src/cli/one_helper/onehost_helper.rb @@ -118,6 +118,7 @@ class OneHostHelper < OpenNebulaHelper::OneHelper puts str % ["ID", host.id.to_s] puts str % ["NAME", host.name] + puts str % ["CLUSTER", host['CLUSTER']] puts str % ["STATE", host.state_str] puts str % ["IM_MAD", host['IM_MAD']] puts str % ["VM_MAD", host['VM_MAD']] diff --git a/src/cli/one_helper/oneimage_helper.rb b/src/cli/one_helper/oneimage_helper.rb index 27a4910ec1..4d13ae95dc 100644 --- a/src/cli/one_helper/oneimage_helper.rb +++ b/src/cli/one_helper/oneimage_helper.rb @@ -118,6 +118,7 @@ class OneImageHelper < OpenNebulaHelper::OneHelper puts str % ["NAME", image.name] puts str % ["USER", image['UNAME']] puts str % ["GROUP",image['GNAME']] + puts str % ["DATASTORE",image['DATASTORE']] puts str % ["TYPE", image.type_str] puts str % ["REGISTER TIME", OpenNebulaHelper.time_to_str(image['REGTIME'])] diff --git a/src/cli/one_helper/onevnet_helper.rb b/src/cli/one_helper/onevnet_helper.rb index 72fb32346c..6b2b439c5a 100644 --- a/src/cli/one_helper/onevnet_helper.rb +++ b/src/cli/one_helper/onevnet_helper.rb @@ -103,6 +103,7 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper puts str % ["NAME", vn['NAME']] puts str % ["USER", vn['UNAME']] puts str % ["GROUP", vn['GNAME']] + puts str % ["CLUSTER", vn['CLUSTER']] puts str % ["TYPE", vn.type_str] puts str % ["BRIDGE", vn["BRIDGE"]] puts str % ["VLAN", OpenNebulaHelper.boolean_to_str(vn['VLAN'])] diff --git a/src/cli/onecluster b/src/cli/onecluster index 07b0fc1ae8..352e4811e0 100755 --- a/src/cli/onecluster +++ b/src/cli/onecluster @@ -56,6 +56,18 @@ cmd=CommandParser::CmdParser.new(ARGV) do helper.list_to_id(arg) end + set :format, :vnetid, OpenNebulaHelper.rname_to_id_desc("VNET") do |arg| + OpenNebulaHelper.rname_to_id(arg, "VNET") + end + + set :format, :hostid, OpenNebulaHelper.rname_to_id_desc("HOST") do |arg| + OpenNebulaHelper.rname_to_id(arg, "HOST") + end + + set :format, :datastoreid, OpenNebulaHelper.rname_to_id_desc("DATASTORE") do |arg| + OpenNebulaHelper.rname_to_id(arg, "DATASTORE") + end + ######################################################################## # Commands ######################################################################## @@ -102,7 +114,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do # TODO: allow the second param to be [:range, :hostid_list] command :addhost, addhost_desc,:clusterid, :hostid do - helper.perform_actions(args[0],options,"updated") do |cluster| + helper.perform_action(args[0],options,"updated") do |cluster| cluster.addhost(args[1].to_i) end end @@ -113,7 +125,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do # TODO: allow the second param to be [:range, :hostid_list] command :delhost, delhost_desc, :clusterid, :hostid do - helper.perform_actions(args[0],options,"updated") do |cluster| + helper.perform_action(args[0],options,"updated") do |cluster| cluster.delhost(args[1].to_i) end end @@ -124,7 +136,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do # TODO: allow the second param to be [:range, :datastoreid_list] command :adddatastore, adddatastore_desc,:clusterid, :datastoreid do - helper.perform_actions(args[0],options,"updated") do |cluster| + helper.perform_action(args[0],options,"updated") do |cluster| cluster.adddatastore(args[1].to_i) end end @@ -135,7 +147,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do # TODO: allow the second param to be [:range, :datastoreid_list] command :deldatastore, deldatastore_desc, :clusterid, :datastoreid do - helper.perform_actions(args[0],options,"updated") do |cluster| + helper.perform_action(args[0],options,"updated") do |cluster| cluster.deldatastore(args[1].to_i) end end @@ -146,7 +158,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do # TODO: allow the second param to be [:range, :vnetid_list] command :addvnet, addvnet_desc,:clusterid, :vnetid do - helper.perform_actions(args[0],options,"updated") do |cluster| + helper.perform_action(args[0],options,"updated") do |cluster| cluster.addvnet(args[1].to_i) end end diff --git a/src/cli/onedatastore b/src/cli/onedatastore index 58edffcdd0..514b5c2249 100755 --- a/src/cli/onedatastore +++ b/src/cli/onedatastore @@ -56,6 +56,18 @@ cmd=CommandParser::CmdParser.new(ARGV) do helper.list_to_id(arg) end + set :format, :clusterid, OpenNebulaHelper.rname_to_id_desc("CLUSTER") do |arg| + OpenNebulaHelper.rname_to_id(arg, "CLUSTER") + end + + set :format, :groupid, OpenNebulaHelper.rname_to_id_desc("GROUP") do |arg| + OpenNebulaHelper.rname_to_id(arg, "GROUP") + end + + set :format, :userid, OpenNebulaHelper.rname_to_id_desc("USER") do |arg| + OpenNebulaHelper.rname_to_id(arg, "USER") + end + ######################################################################## # Commands ######################################################################## diff --git a/src/datastore/DatastorePool.cc b/src/datastore/DatastorePool.cc index 9897f80790..d45f1eb0d3 100644 --- a/src/datastore/DatastorePool.cc +++ b/src/datastore/DatastorePool.cc @@ -45,11 +45,7 @@ DatastorePool::DatastorePool(SqlDB * db): { DatastoreTemplate * ds_tmpl; - int rc, system_id, default_id; - Nebula& nd = Nebula::instance(); - - ClusterPool * clpool = nd.get_clpool(); - Cluster * cluster; + int rc; // --------------------------------------------------------------------- // Create the system datastore @@ -72,12 +68,12 @@ DatastorePool::DatastorePool(SqlDB * db): UserPool::oneadmin_name, GroupPool::ONEADMIN_NAME, ds_tmpl, - &system_id, - ClusterPool::DEFAULT_CLUSTER_ID, - ClusterPool::DEFAULT_CLUSTER_NAME, + &rc, + ClusterPool::NONE_CLUSTER_ID, + ClusterPool::NONE_CLUSTER_NAME, error_str); - if( system_id < 0 ) + if( rc < 0 ) { goto error_bootstrap; } @@ -104,38 +100,16 @@ DatastorePool::DatastorePool(SqlDB * db): UserPool::oneadmin_name, GroupPool::ONEADMIN_NAME, ds_tmpl, - &default_id, - ClusterPool::DEFAULT_CLUSTER_ID, - ClusterPool::DEFAULT_CLUSTER_NAME, + &rc, + ClusterPool::NONE_CLUSTER_ID, + ClusterPool::NONE_CLUSTER_NAME, error_str); - if( default_id < 0 ) + if( rc < 0 ) { goto error_bootstrap; } - // Add to Cluster - cluster = clpool->get(ClusterPool::DEFAULT_CLUSTER_ID, true); - - if( cluster == 0 ) - { - error_str = "Could not get default cluster"; - goto error_bootstrap; - } - - rc = cluster->add_datastore(system_id, error_str); - rc += cluster->add_datastore(default_id, error_str); - - if ( rc != 0 ) - { - cluster->unlock(); - goto error_bootstrap; - } - - clpool->update(cluster); - - cluster->unlock(); - // User created datastores will start from ID 100 set_update_lastOID(99); } diff --git a/src/datastore_mad/remotes/fs/cp b/src/datastore_mad/remotes/fs/cp index 3f99bc4324..b7fe2249f7 100755 --- a/src/datastore_mad/remotes/fs/cp +++ b/src/datastore_mad/remotes/fs/cp @@ -39,10 +39,25 @@ source ${DRIVER_PATH}/../libfs.sh DRV_ACTION=$1 ID=$2 -set_up_datastore $DRV_ACTION - XPATH="${DRIVER_PATH}/../xpath.rb -b $DRV_ACTION" -SRC=`$XPATH /DS_DRIVER_ACTION_DATA/IMAGE/PATH` + +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/IMAGE/PATH) + +BASE_PATH="${XPATH_ELEMENTS[0]}" +RESTRICTED_DIRS="${XPATH_ELEMENTS[1]}" +SAFE_DIRS="${XPATH_ELEMENTS[2]}" +UMASK="${XPATH_ELEMENTS[3]}" +SRC="${XPATH_ELEMENTS[4]}" + +set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS" "$UMASK" DST=`generate_image_path` @@ -53,8 +68,6 @@ http://*) log "Downloading $SRC to the image repository" exec_and_log "$WGET -O $DST $SRC" "Error downloading $SRC" - - exec_and_log "chmod 0660 $DST" ;; *) @@ -67,8 +80,6 @@ http://*) log "Copying local image $SRC to the image repository" exec_and_log "cp -f $SRC $DST" "Error copying $SRC to $DST" - - exec_and_log "chmod 0660 $DST" ;; esac diff --git a/src/datastore_mad/remotes/fs/mkfs b/src/datastore_mad/remotes/fs/mkfs index 5ec61bdb36..7f27552ad6 100755 --- a/src/datastore_mad/remotes/fs/mkfs +++ b/src/datastore_mad/remotes/fs/mkfs @@ -39,20 +39,32 @@ source ${DRIVER_PATH}/../libfs.sh DRV_ACTION=$1 ID=$2 -set_up_datastore $DRV_ACTION +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/FSTYPE \ +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) -FSTYPE="${XPATH_ELEMENTS[0]}" -SIZE="${XPATH_ELEMENTS[1]}" + +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]}" + +set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS" "$UMASK" DST=`generate_image_path` - # ------------ Create the image to the repository ------------ MKFS_CMD=`mkfs_command $DST $FSTYPE` @@ -61,7 +73,6 @@ exec_and_log "$DD if=/dev/zero of=$DST bs=1 count=1 seek=${SIZE}M" \ "Could not create image $DST" exec_and_log "$MKFS_CMD" \ "Unable to create filesystem $FSTYPE in $DST" -exec_and_log "chmod 0660 $DST" # ---------------- Get the size of the image ------------ SIZE=`fs_du $DST` diff --git a/src/datastore_mad/remotes/fs/mv b/src/datastore_mad/remotes/fs/mv deleted file mode 100755 index 8ea2259a28..0000000000 --- a/src/datastore_mad/remotes/fs/mv +++ /dev/null @@ -1,75 +0,0 @@ -#!/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 move a VM image (SRC) to the image repository as DST -# Several SRC types are supported -############################################################################### - -# ------------ Set up the environment to source common tools ------------ - -if [ -z "${ONE_LOCATION}" ]; then - LIB_LOCATION=/usr/lib/one -else - LIB_LOCATION=$ONE_LOCATION/lib -fi - -. $LIB_LOCATION/sh/scripts_common.sh -source $(dirname $0)/fsrc - -SRC=$1 -DST=$2 -ID=$3 - -# ------------ Generate a filename for the image ------------ - -if [ "$DST" = "-" ] ; then - DST=`generate_image_path` -fi - -# ------------ Move the image to the repository ------------ - -case $SRC in -http://*) - log "Downloading $SRC to the image repository" - exec_and_log "$WGET -O $DST $SRC" \ - "Error downloading $SRC" - ;; - -*) - log "Moving local image $SRC to the image repository" - - if [ \( -L $SRC \) -a \ - \( "`$READLINK -f $SRC`" = "`$READLINK -f $DST`" \) ] ; then - log "Not moving files to image repo, they are the same" - else - exec_and_log "mv -f $SRC $DST" "Could not move $SRC to $DST" - fi - ;; -esac - -if [ -d $DST ]; then - exec_and_log "chmod 0770 $DST" -else - exec_and_log "chmod 0660 $DST" -fi - -# ---------------- 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 4f61c99354..e1b5f67717 100644 --- a/src/datastore_mad/remotes/libfs.sh +++ b/src/datastore_mad/remotes/libfs.sh @@ -17,8 +17,11 @@ #--------------------------------------------------------------------------- # #------------------------------------------------------------------------------ -# Set up environment variables -# @param $1 - template (base 64 encoded) with driver data +# Set up environment variables +# @param $1 - Datastore base_path +# @param $2 - Restricted directories +# @param $3 - Safe dirs +# @param $4 - Umask for new file creation (default: 0007) # @return sets the following environment variables # - RESTRICTED_DIRS: Paths that can not be used to register images # - SAFE_DIRS: Paths that are safe to specify image paths @@ -28,6 +31,11 @@ function set_up_datastore { # # Load the default configuration for FS datastores # + BASE_PATH="$1" + RESTRICTED_DIRS="$2" + SAFE_DIRS="$3" + UMASK="$4" + if [ -z "${ONE_LOCATION}" ]; then VAR_LOCATION=/var/lib/one/ ETC_LOCATION=/etc/one/ @@ -36,24 +44,6 @@ function set_up_datastore { ETC_LOCATION=$ONE_LOCATION/etc/ fi - CONF_FILE=$ETC_LOCATION/datastore/fs.conf - - source $CONF_FILE - - # - # Load attributes from the Datastore - # - XPATH="$VAR_LOCATION/remotes/datastore/xpath.rb -b $1" - eval "DS_BASE_PATH=`$XPATH /DS_DRIVER_ACTION_DATA/DATASTORE/BASE_PATH`" - - if [ -z "${DS_BASE_PATH}" ]; then - if [ -z "${BASE_PATH}" ]; then - BASE_PATH="${VAR_LOCATION}/images" - fi - else - BASE_PATH=${DS_BASE_PATH} - fi - # # RESTRICTED AND SAFE DIRS (from default configuration) # @@ -62,6 +52,14 @@ function set_up_datastore { export BASE_PATH export RESTRICTED_DIRS export SAFE_DIRS + + mkdir -p $BASE_PATH + + if [ -n "$UMASK" ]; then + umask $UMASK + else + umask 0007 + fi } #------------------------------------------------------------------------------- @@ -102,6 +100,22 @@ function fs_du { echo "$SIZE" } +#------------------------------------------------------------------------------- +# Computes the size of an image +# @param $1 - Path to the image +# @return size of the image in Mb +#------------------------------------------------------------------------------- +function qemu_size { + DISK="$1" + + SIZE=`$QEMU_IMG info $DISK|grep "^virtual size:"|\ + sed 's/^.*(\([0-9]\+\) bytes.*$/\1/g'` + + SIZE=$(($SIZE/1048576)) + + echo "$SIZE" +} + #------------------------------------------------------------------------------- # Checks if a path is safe for copying the image from # @param $1 - Path to the image diff --git a/src/datastore_mad/remotes/vmware/cp b/src/datastore_mad/remotes/vmware/cp index 069bd89b72..f216d95892 100755 --- a/src/datastore_mad/remotes/vmware/cp +++ b/src/datastore_mad/remotes/vmware/cp @@ -39,10 +39,25 @@ source ${DRIVER_PATH}/../libfs.sh DRV_ACTION=$1 ID=$2 -set_up_datastore $DRV_ACTION - XPATH="${DRIVER_PATH}/../xpath.rb -b $DRV_ACTION" -SRC=`$XPATH /DS_DRIVER_ACTION_DATA/IMAGE/PATH` + +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/IMAGE/PATH) + +BASE_PATH="${XPATH_ELEMENTS[0]}" +RESTRICTED_DIRS="${XPATH_ELEMENTS[1]}" +SAFE_DIRS="${XPATH_ELEMENTS[2]}" +UMASK="${XPATH_ELEMENTS[3]}" +SRC="${XPATH_ELEMENTS[4]}" + +set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS" "$UMASK" DST=`generate_image_path` @@ -66,8 +81,6 @@ case $SRC in exec_and_log "mv -f $DST/$BASE_DISK_FILE $DST/disk.vmdk" \ "Error renaming disk file $BASE_DISK_FILE to disk.vmdk" fi - - exec_and_log "chmod 0770 $DST" ;; esac diff --git a/src/datastore_mad/remotes/vmware/mkfs b/src/datastore_mad/remotes/vmware/mkfs index e7e623c713..f48f2535d8 100755 --- a/src/datastore_mad/remotes/vmware/mkfs +++ b/src/datastore_mad/remotes/vmware/mkfs @@ -39,19 +39,29 @@ source ${DRIVER_PATH}/../libfs.sh DRV_ACTION=$1 ID=$2 -set_up_datastore $DRV_ACTION - 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/FSTYPE \ +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) -FSTYPE="${XPATH_ELEMENTS[0]}" -SIZE="${XPATH_ELEMENTS[1]}" +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]}" + +set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS" "$UMASK" DST=`generate_image_path` @@ -60,7 +70,6 @@ DISK_TMP=$DISK.tmp IMAGE_FORMAT=vmdk -umask 0007 # ------------ Create the image to the repository ------------ MKFS_CMD=`mkfs_command $DISK_TMP $FSTYPE` @@ -75,13 +84,9 @@ exec_and_log "$QEMU_IMG convert -O $IMAGE_FORMAT $DISK_TMP $DISK" \ "Unable to convert to $IMAGE_FORMAT in $DISK_TMP" exec_and_log "rm -f $DISK_TMP" \ "Unable to remove temporary disk $DISK_TMP" -exec_and_log "chmod 0660 $DISK" # ---------------- Get the size of the image ------------ -SIZE=`$QEMU_IMG info $DISK|grep "^virtual size:"|\ - sed 's/^.*(\([0-9]\+\) bytes.*$/\1/g'` - -SIZE=$(($SIZE/1048576)) +SIZE=`qemu_size $DISK` echo "$DST $SIZE" diff --git a/src/datastore_mad/remotes/vmware/mv b/src/datastore_mad/remotes/vmware/mv deleted file mode 100755 index 8ea2259a28..0000000000 --- a/src/datastore_mad/remotes/vmware/mv +++ /dev/null @@ -1,75 +0,0 @@ -#!/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 move a VM image (SRC) to the image repository as DST -# Several SRC types are supported -############################################################################### - -# ------------ Set up the environment to source common tools ------------ - -if [ -z "${ONE_LOCATION}" ]; then - LIB_LOCATION=/usr/lib/one -else - LIB_LOCATION=$ONE_LOCATION/lib -fi - -. $LIB_LOCATION/sh/scripts_common.sh -source $(dirname $0)/fsrc - -SRC=$1 -DST=$2 -ID=$3 - -# ------------ Generate a filename for the image ------------ - -if [ "$DST" = "-" ] ; then - DST=`generate_image_path` -fi - -# ------------ Move the image to the repository ------------ - -case $SRC in -http://*) - log "Downloading $SRC to the image repository" - exec_and_log "$WGET -O $DST $SRC" \ - "Error downloading $SRC" - ;; - -*) - log "Moving local image $SRC to the image repository" - - if [ \( -L $SRC \) -a \ - \( "`$READLINK -f $SRC`" = "`$READLINK -f $DST`" \) ] ; then - log "Not moving files to image repo, they are the same" - else - exec_and_log "mv -f $SRC $DST" "Could not move $SRC to $DST" - fi - ;; -esac - -if [ -d $DST ]; then - exec_and_log "chmod 0770 $DST" -else - exec_and_log "chmod 0660 $DST" -fi - -# ---------------- Get the size of the image ------------ -SIZE=`fs_du $DST` - -echo "$DST $SIZE" diff --git a/src/datastore_mad/remotes/xpath.rb b/src/datastore_mad/remotes/xpath.rb index 3cf8af12b5..9a330d7247 100755 --- a/src/datastore_mad/remotes/xpath.rb +++ b/src/datastore_mad/remotes/xpath.rb @@ -47,7 +47,7 @@ xml = REXML::Document.new(tmp).root ARGV.each do |xpath| element = xml.elements[xpath] - values << element.text if !element.nil? + values << element.text.to_s if !element.nil? values << "\0" end diff --git a/src/mad/sh/scripts_common.sh b/src/mad/sh/scripts_common.sh index 9201d919a9..b60c15d8a7 100755 --- a/src/mad/sh/scripts_common.sh +++ b/src/mad/sh/scripts_common.sh @@ -109,19 +109,20 @@ function error_message function exec_and_log { message=$2 - output=`$1 2>&1 1>/dev/null` - code=$? - if [ "x$code" != "x0" ]; then - log_error "Command \"$1\" failed." - log_error "$output" - if [ -z "$message" ]; then - error_message "$output" + + EXEC_LOG_ERR=`$1 2>&1 1>/dev/null` + EXEC_LOG_RC=$? + + if [ $EXEC_LOG_RC -ne 0 ]; then + log_error "Command \"$1\" failed: $EXEC_LOG_ERR" + + if [ -n "$2" ]; then + error_message "$2" else - error_message "$message" + error_message "Error executing $1: $EXEC_LOG_ERR" fi exit $code fi - log "Executed \"$1\"." } # Like exec_and_log but the first argument is the number of seconds diff --git a/src/tm_mad/common/context b/src/tm_mad/common/context new file mode 100755 index 0000000000..a36c2e5699 --- /dev/null +++ b/src/tm_mad/common/context @@ -0,0 +1,78 @@ +#!/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 +# - 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 + +while (( "$#" )); do + if [ "$#" == "1" ]; then + DST=$1 + else + SRC="$SRC $1" + fi + shift +done + +if [ -z "${ONE_LOCATION}" ]; then + TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh +else + TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh +fi + +. $TMCOMMON + +#------------------------------------------------------------------------------- +# Set dst path and dirs +#------------------------------------------------------------------------------- +DST_PATH=`arg_path $DST` +DST_HOST=`arg_host $DST` +DST_DIR=`dirname $DST_PATH` + +ssh_make_path $DST_HOST $DST_DIR + +#------------------------------------------------------------------------------- +# Build the Context Block device (locally) and copy it remotely +#------------------------------------------------------------------------------- +log "Generating context block device at $DST" + +VM_ID=`basename $DST_DIR` +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" + +exec_and_log "$SCP $ISO_FILE $DST" "Error copying context ISO to $DST" + +rm -rf $ISO_DIR > /dev/null 2>&1 + +exit 0 diff --git a/src/datastore_mad/remotes/fs/fs.conf b/src/tm_mad/common/delete old mode 100644 new mode 100755 similarity index 57% rename from src/datastore_mad/remotes/fs/fs.conf rename to src/tm_mad/common/delete index ec29989e22..f0c68244a6 --- a/src/datastore_mad/remotes/fs/fs.conf +++ b/src/tm_mad/common/delete @@ -1,3 +1,5 @@ +#!/bin/bash + # -------------------------------------------------------------------------- # # Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) # # # @@ -14,25 +16,32 @@ # limitations under the License. # #--------------------------------------------------------------------------- # -# PRESERVE BASH SYNTAX +# DELETE +# - host is the target host to deploy the VM +# - remote_system_ds is the path for the system datastore in the host + +DST=$1 + +if [ -z "${ONE_LOCATION}" ]; then + TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh +else + TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh +fi + +. $TMCOMMON -#******************************************************************************* -# DEFAULT Configuration File for File-System based Datastores #------------------------------------------------------------------------------- -# BASE_PATH: Path where the images will be stored. If not defined -# defaults to /var/lib/one/images or $ONE_LOCATION/var/images -# -# RESTRICTED_DIRS: Paths that can not be used to register images. A space -# separated list of paths. This prevents users to access important files like -# oned.db or /etc/shadow. OpenNebula will automatically add its configuration -# dirs:/var/lib/one, /etc/one and oneadmin's home ($HOME). -# -# SAFE_DIRS: Paths that are safe to specify image paths. A space separated list -# of paths.This will allow you to open specific paths within RESTRICTED_DIRS -#******************************************************************************* +# 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` -#BASE_PATH=/var/lib/one/images +if [ `is_disk $DST_PATH` -eq 1 ]; then + exit 0 +fi -RESTRICTED_DIRS="/etc/" +log "Deleting $DST_PATH" +ssh_exec_and_log $DST_HOST "rm -rf $DST_PATH" "Error deleting $DST_PATH" -SAFE_DIRS="$HOME/public/" +exit 0 diff --git a/src/tm_mad/dummy/dummy.sh b/src/tm_mad/common/dummy.sh similarity index 100% rename from src/tm_mad/dummy/dummy.sh rename to src/tm_mad/common/dummy.sh diff --git a/src/tm_mad/common/mkimage b/src/tm_mad/common/mkimage new file mode 100755 index 0000000000..3471e81410 --- /dev/null +++ b/src/tm_mad/common/mkimage @@ -0,0 +1,61 @@ +#!/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 size +# - 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 + +SIZE=$1 +FSTYPE=$2 +DST=$3 + +if [ -z "${ONE_LOCATION}" ]; then + TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh +else + TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh +fi + +. $TMCOMMON + +#------------------------------------------------------------------------------- +# Set dst path and dir +#------------------------------------------------------------------------------- +DST_PATH=`arg_path $DST` +DST_HOST=`arg_host $DST` +DST_DIR=`dirname $DST_PATH` + +ssh_make_path $DST_HOST $DST_DIR + +#------------------------------------------------------------------------------- +# Make the new image (file-based) +#------------------------------------------------------------------------------- +MKFS_CMD=`mkfs_command $DST_PATH $FSTYPE` + +MKSCRIPT=$(cat < -# - host is the target host to deploy the VM -# - remote_system_ds is the path for the system datastore in the host - -DST=$1 - -if [ -z "${ONE_LOCATION}" ]; then - TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh -else - TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh -fi - -. $TMCOMMON - -#------------------------------------------------------------------------------- -# Set dst path and dir -# Return if deleting a disk, we will delete them when removing the -# remote_system_ds directory for the VM -#------------------------------------------------------------------------------- - -DST_PATH=`arg_path $DST` - -if [ `is_disk $DST_PATH` -eq 1 ]; then - exit 0 -fi - -set_ds_location - -REL_DST_PATH=${DST_PATH##"$DS_LOCATION/"} -DST_PATH="$ONE_LOCAL_VAR/datastores/$REL_DST_PATH" - -log "Deleting $DST_PATH" -exec_and_log "rm -rf $DST_PATH" "Error deleting $DST_PATH" diff --git a/src/tm_mad/shared/delete b/src/tm_mad/shared/delete new file mode 120000 index 0000000000..230e56774f --- /dev/null +++ b/src/tm_mad/shared/delete @@ -0,0 +1 @@ +../common/delete \ No newline at end of file diff --git a/src/tm_mad/shared/ln b/src/tm_mad/shared/ln index 480ea50def..4ecb76e42b 100755 --- a/src/tm_mad/shared/ln +++ b/src/tm_mad/shared/ln @@ -37,30 +37,22 @@ fi # Set dst path and dir #------------------------------------------------------------------------------- SRC_PATH=`arg_path $SRC` +SRC_PATH="../../${SRC_PATH##"$DS_DIR/"}" + DST_PATH=`arg_path $DST` - -set_ds_location - -REL_DST_PATH=${DST_PATH##"$DS_LOCATION/"} -REL_SRC_PATH=${SRC_PATH##"$ONE_LOCAL_VAR/datastores/"} - -DST_PATH="$ONE_LOCAL_VAR/datastores/$REL_DST_PATH" +DST_HOST=`arg_host $DST` DST_DIR=`dirname $DST_PATH` -if [ ! -d $DST_DIR ]; then - log "Creating directory $DST_DIR" - exec_and_log "mkdir -p $DST_DIR" -fi - -DST_FILE=`basename $DST_PATH` +ssh_make_path $DST_HOST $DST_DIR #------------------------------------------------------------------------------- # Link (ln) SRC into DST #------------------------------------------------------------------------------- -log "Linking $SRC_PATH in $DST_PATH" +log "Linking $SRC_PATH in $DST" -cd $DST_DIR +ssh_exec_and_log $DST_HOST \ + "cd $DST_DIR; ln -s $SRC_PATH $DST_PATH" \ + "Error linking $SRC to $DST" -exec_and_log "ln -s ../../$REL_SRC_PATH ./$DST_FILE" \ - "Error linking $SRC to $DST" +exit 0 diff --git a/src/tm_mad/shared/mkimage b/src/tm_mad/shared/mkimage deleted file mode 100755 index d651075dcc..0000000000 --- a/src/tm_mad/shared/mkimage +++ /dev/null @@ -1,65 +0,0 @@ -#!/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 size -# - 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 - -SIZE=$1 -FSTYPE=$2 -DST=$3 - -if [ -z "${ONE_LOCATION}" ]; then - TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh -else - TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh -fi - -. $TMCOMMON - -#------------------------------------------------------------------------------- -# Set dst path and dir -#------------------------------------------------------------------------------- -DST_PATH=`arg_path $DST` - -set_ds_location - -REL_DST_PATH=${DST_PATH##"$DS_LOCATION/"} -DST_PATH="$ONE_LOCAL_VAR/datastores/$REL_DST_PATH" - -DST_DIR=`dirname $DST_PATH` - -if [ ! -d $DST_DIR ]; then - log "Creating directory $DST_DIR" - exec_and_log "mkdir -p $DST_DIR" -fi - -#------------------------------------------------------------------------------- -# Make the new image (file-based) -#------------------------------------------------------------------------------- - -MKFS_CMD=`mkfs_command $DST_PATH $FSTYPE` - -exec_and_log "$DD if=/dev/zero of=$DST_PATH bs=1 count=1 seek=${SIZE}M" \ - "Could not create image $DST_PATH" - -if [ -n "$MKFS_CMD" ]; then - exec_and_log "$MKFS_CMD" "Unable to create filesystem $FSTYPE in $DST_PATH" -fi \ No newline at end of file diff --git a/src/tm_mad/shared/mkimage b/src/tm_mad/shared/mkimage new file mode 120000 index 0000000000..ad1bdd354d --- /dev/null +++ b/src/tm_mad/shared/mkimage @@ -0,0 +1 @@ +../common/mkimage \ No newline at end of file diff --git a/src/tm_mad/shared/mkswap b/src/tm_mad/shared/mkswap deleted file mode 100755 index 51ac4d96a1..0000000000 --- a/src/tm_mad/shared/mkswap +++ /dev/null @@ -1,28 +0,0 @@ -#!/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. # -#--------------------------------------------------------------------------- # - -# mkswap size host:remote_system_ds/disk.i size -# - size in MB of the image -# - host is the target host to deploy the VM -# - remote_system_ds is the path for the system datastore in the host - -SIZE=$1 -DST=$2 - -CMD="`dirname $0`/mkimage $SIZE swap $DST" -`$CMD` diff --git a/src/tm_mad/shared/mkswap b/src/tm_mad/shared/mkswap new file mode 120000 index 0000000000..3e0699b0f3 --- /dev/null +++ b/src/tm_mad/shared/mkswap @@ -0,0 +1 @@ +../common/mkswap \ No newline at end of file diff --git a/src/tm_mad/shared/mv b/src/tm_mad/shared/mv index 2507dfb82d..300563f2ad 120000 --- a/src/tm_mad/shared/mv +++ b/src/tm_mad/shared/mv @@ -1 +1 @@ -../dummy/dummy.sh \ No newline at end of file +../common/dummy.sh \ No newline at end of file diff --git a/src/tm_mad/shared/mvds b/src/tm_mad/shared/mvds new file mode 100755 index 0000000000..94116583cd --- /dev/null +++ b/src/tm_mad/shared/mvds @@ -0,0 +1,73 @@ +#!/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. # +#--------------------------------------------------------------------------- # + +# mvds host:remote_system_ds/disk.i fe:SOURCE +# - 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 + +SRC=$1 +DST=$2 + +if [ -z "${ONE_LOCATION}" ]; then + TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh +else + TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh +fi + +. $TMCOMMON + +set_ds_location + +#------------------------------------------------------------------------------- +# Set dst path and dir +#------------------------------------------------------------------------------- +SRC_PATH=`arg_path $SRC` +DST_PATH=`arg_path $DST` + +DST_PATH="$RMT_DS_DIR/${DST_PATH##"$DS_DIR/"}" + +SRC_HOST=`arg_host $DST` + +#------------------------------------------------------------------------------- +# Move the image back to the datastore +#------------------------------------------------------------------------------- +MVSCRIPT=$(cat < +# +# - hostX is the target host to deploy the VM +# - system_ds is the path for the system datastore in the host + SRC=$1 DST=$2 if [ -z "${ONE_LOCATION}" ]; then - TMCOMMON=/usr/lib/one/mads/tm_common.sh + TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh else - TMCOMMON=$ONE_LOCATION/lib/mads/tm_common.sh + TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh fi . $TMCOMMON +#------------------------------------------------------------------------------- +# Return if moving a disk, we will move them when moving the whole system_ds +# directory for the VM +#------------------------------------------------------------------------------- SRC_PATH=`arg_path $SRC` DST_PATH=`arg_path $DST` @@ -35,14 +44,21 @@ DST_HOST=`arg_host $DST` DST_DIR=`dirname $DST_PATH` -if full_src_and_dst_equal; then - log "Not moving $SRC to $DST, they are the same path" -else - log "Moving $SRC_PATH" - exec_and_log "$SSH $DST_HOST mkdir -p $DST_DIR" \ - "Unable to create directory $DST_DIR" - exec_and_log "$SCP -r $SRC $DST" \ - "Could not copy $SRC to $DST" - exec_and_log "$SSH $SRC_HOST rm -rf $SRC_PATH" +if [ `is_disk $DST_PATH` -eq 1 ]; then + exit 0 fi +if [ "$SRC" == "$DST" ]; then + log "Not moving $SRC to $DST, they are the same path" + exit 0 +fi + +ssh_make_path $DST_HOST $DST_DIR + +log "Moving $SRC to $DST" + +exec_and_log "$SCP -r $SRC $DST" "Could not copy $SRC to $DST" + +exec_and_log "$SSH $SRC_HOST rm -rf $SRC_PATH" + +exit 0 diff --git a/src/datastore_mad/remotes/vmware/vmware.conf b/src/tm_mad/ssh/mvds old mode 100644 new mode 100755 similarity index 55% rename from src/datastore_mad/remotes/vmware/vmware.conf rename to src/tm_mad/ssh/mvds index ec29989e22..87621225a9 --- a/src/datastore_mad/remotes/vmware/vmware.conf +++ b/src/tm_mad/ssh/mvds @@ -1,3 +1,5 @@ +#!/bin/bash + # -------------------------------------------------------------------------- # # Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) # # # @@ -14,25 +16,39 @@ # limitations under the License. # #--------------------------------------------------------------------------- # -# PRESERVE BASH SYNTAX +# mvds host:remote_system_ds/disk.i fe:SOURCE +# - 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 + +SRC=$1 +DST=$2 + +if [ -z "${ONE_LOCATION}" ]; then + TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh +else + TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh +fi + +. $TMCOMMON + +set_ds_location -#******************************************************************************* -# DEFAULT Configuration File for File-System based Datastores #------------------------------------------------------------------------------- -# BASE_PATH: Path where the images will be stored. If not defined -# defaults to /var/lib/one/images or $ONE_LOCATION/var/images -# -# RESTRICTED_DIRS: Paths that can not be used to register images. A space -# separated list of paths. This prevents users to access important files like -# oned.db or /etc/shadow. OpenNebula will automatically add its configuration -# dirs:/var/lib/one, /etc/one and oneadmin's home ($HOME). -# -# SAFE_DIRS: Paths that are safe to specify image paths. A space separated list -# of paths.This will allow you to open specific paths within RESTRICTED_DIRS -#******************************************************************************* +# Set dst path and dir +#------------------------------------------------------------------------------- +SRC_PATH=`arg_path $SRC` +DST_PATH=`arg_path $DST` -#BASE_PATH=/var/lib/one/images +DST_PATH="$RMT_DS_DIR/${DST_PATH##"$DS_DIR/"}" -RESTRICTED_DIRS="/etc/" +SRC_HOST=`arg_host $DST` -SAFE_DIRS="$HOME/public/" +#------------------------------------------------------------------------------- +# Move the image back to the datastore +#------------------------------------------------------------------------------- +log "Moving $SRC_PATH to datastore as $DST_PATH" +exec_and_log "$SCP $SRC $DST" "Error copying $SRC to $DST" + +exit 0 diff --git a/src/tm_mad/tm_common.sh b/src/tm_mad/tm_common.sh index 07578a18b8..6626ef591f 100644 --- a/src/tm_mad/tm_common.sh +++ b/src/tm_mad/tm_common.sh @@ -22,9 +22,11 @@ export LANG=C if [ -z "$ONE_LOCATION" ]; then ONE_LOCAL_VAR=/var/lib/one ONE_LIB=/usr/lib/one + DS_DIR=/var/lib/one/datastores else ONE_LOCAL_VAR=$ONE_LOCATION/var ONE_LIB=$ONE_LOCATION/lib + DS_DIR=$ONE_LOCATION/var/datastores fi ONE_SH=$ONE_LIB/sh @@ -56,8 +58,10 @@ function arg_path #Return the DATASTORE_LOCATION from OpenNebula configuration function set_ds_location { - DS_LOCATION=`$GREP '^DATASTORE_LOCATION=' $ONE_LOCAL_VAR/config | cut -d= -f2` - DS_LOCATION=`fix_dir_slashes $DS_LOCATION` + RMT_DS_DIR=`$GREP '^DATASTORE_LOCATION=' $ONE_LOCAL_VAR/config | cut -d= -f2` + RMT_DS_DIR=`fix_dir_slashes $DS_LOCATION` + + export RMT_DS_DIR } #Return 1 if the first argument is a disk @@ -70,4 +74,58 @@ function is_disk else echo "0" fi -} \ No newline at end of file +} + +# ------------------------------------------------------------------------------ +# 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 <