From c1b74347747973c9666f0f0a049b026a26151cb4 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 2 Mar 2012 18:24:03 +0100 Subject: [PATCH 01/10] feature 1112: Context fot tm_shared --- src/tm_mad/shared/context | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/src/tm_mad/shared/context b/src/tm_mad/shared/context index 09d0a7552a..2806793ba1 100755 --- a/src/tm_mad/shared/context +++ b/src/tm_mad/shared/context @@ -16,6 +16,11 @@ # 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 @@ -26,39 +31,48 @@ while (( "$#" )); do done 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 -get_vmdir - +#------------------------------------------------------------------------------- +# Set dst path and dirs +#------------------------------------------------------------------------------- DST_PATH=`arg_path $DST` -fix_dst_path +set_ds_location -DST_DIR=`dirname $DST_PATH` +REL_DST_PATH=${DST_PATH##"$DS_LOCATION/"} +DST_PATH="$ONE_LOCAL_VAR/datastores/$REL_DST_PATH" + +DST_DIR=`dirname $DST_PATH` ISO_DIR=$DST_DIR/isofiles +if [ ! -d $DST_DIR ]; then + log "Creating directory $DST_DIR" + exec_and_log "mkdir -p $DST_DIR" +fi + exec_and_log "mkdir -p $ISO_DIR" +#------------------------------------------------------------------------------- +# Build the Context Block device +#------------------------------------------------------------------------------- for f in $SRC; do case $f in http://*) - exec_and_log "$WGET -P $ISO_DIR $f" \ - "Error downloading $f" + 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" + exec_and_log "cp -R $f $ISO_DIR" "Error copying $f to $ISO_DIR" ;; esac done -exec_and_log "$MKISOFS -o $DST_PATH -J -R $ISO_DIR" \ - "Error creating iso fs" +exec_and_log "$MKISOFS -o $DST_PATH -J -R $ISO_DIR" "Error creating iso fs" exec_and_log "rm -rf $ISO_DIR" From d376c6fa4b6a711d6f1c21b9ec24be9e4892c6bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 2 Mar 2012 18:51:17 +0100 Subject: [PATCH 02/10] Feature #1112: Work on CLI commands, cluster and DS related methods --- src/cli/one_helper.rb | 5 +++++ src/cli/one_helper/onedatastore_helper.rb | 1 + src/cli/one_helper/onehost_helper.rb | 1 + src/cli/one_helper/oneimage_helper.rb | 1 + src/cli/one_helper/onevnet_helper.rb | 1 + src/cli/onecluster | 22 +++++++++++++++++----- src/cli/onedatastore | 12 ++++++++++++ 7 files changed, 38 insertions(+), 5 deletions(-) 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 ######################################################################## From 1bb6d434645dc3e0639f00760c46ab49e86fa269 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 2 Mar 2012 19:10:41 +0100 Subject: [PATCH 03/10] Feature #1112: Create system and default datastores in cluster 'none' --- src/datastore/DatastorePool.cc | 44 +++++++--------------------------- 1 file changed, 9 insertions(+), 35 deletions(-) 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); } From e71c78c18742de020c6d52a18e2fbc97e88f6cd0 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sat, 3 Mar 2012 03:37:06 +0100 Subject: [PATCH 04/10] feature #1112: Do not make system_datastore directory for a VM. --- src/vm/VirtualMachine.cc | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 1700dff31e..759c4b89ce 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -164,12 +164,7 @@ int VirtualMachine::select(SqlDB * db) mkdir(oss.str().c_str(), 0700); chmod(oss.str().c_str(), 0700); - - system_dir = get_system_dir(); - - mkdir(system_dir.c_str(), 0700); - chmod(system_dir.c_str(), 0700); - + //-------------------------------------------------------------------------- //Create Log support for this VM //-------------------------------------------------------------------------- From eb33fab49f833b3f54e8e6d536db9d97cb1caf2e Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sat, 3 Mar 2012 03:37:38 +0100 Subject: [PATCH 05/10] feature #1112: Fix bug when one of the actions of a TM script fails --- src/tm_mad/one_tm.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tm_mad/one_tm.rb b/src/tm_mad/one_tm.rb index 4f3e56a992..d8fc620987 100755 --- a/src/tm_mad/one_tm.rb +++ b/src/tm_mad/one_tm.rb @@ -84,7 +84,7 @@ class TransferManagerDriver < OpenNebulaDriver if result == RESULT[:failure] send_message("TRANSFER", result, id, info) - break + return end } From 193c3d2c94996aa879b1a1121db352fbd5347d8b Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sat, 3 Mar 2012 03:38:18 +0100 Subject: [PATCH 06/10] feature #1112: Do not set DATASTORE_LOCATION value, use the default --- share/etc/oned.conf | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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" From 4dc9a34b790e6f9ec8d48479a072b6cfdd301da8 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sat, 3 Mar 2012 03:39:21 +0100 Subject: [PATCH 07/10] feature #1112: TM shared and ssh. It should allow any combination of system datastore and images datastore types (shared-shared, ssh-shared, shared-ssh, ssh-ssh) --- src/mad/sh/scripts_common.sh | 19 ++++--- src/tm_mad/common/context | 78 ++++++++++++++++++++++++++ src/tm_mad/common/delete | 47 ++++++++++++++++ src/tm_mad/{dummy => common}/dummy.sh | 0 src/tm_mad/common/mkimage | 61 +++++++++++++++++++++ src/tm_mad/common/mkswap | 30 ++++++++++ src/tm_mad/dummy/clone | 2 +- src/tm_mad/dummy/context | 2 +- src/tm_mad/dummy/delete | 2 +- src/tm_mad/dummy/ln | 2 +- src/tm_mad/dummy/mkimage | 2 +- src/tm_mad/dummy/mkswap | 2 +- src/tm_mad/dummy/mv | 2 +- src/tm_mad/dummy/mvds | 1 + src/tm_mad/shared/clone | 26 ++++----- src/tm_mad/shared/context | 79 +-------------------------- src/tm_mad/shared/delete | 52 +----------------- src/tm_mad/shared/ln | 26 +++------ src/tm_mad/shared/mkimage | 66 +--------------------- src/tm_mad/shared/mkswap | 29 +--------- src/tm_mad/shared/mv | 2 +- src/tm_mad/ssh/clone | 37 +++++++------ src/tm_mad/ssh/context | 73 +------------------------ src/tm_mad/ssh/delete | 36 +----------- src/tm_mad/ssh/ln | 35 +----------- src/tm_mad/ssh/mkimage | 44 +-------------- src/tm_mad/ssh/mkswap | 46 +--------------- src/tm_mad/ssh/mv | 38 +++++++++---- src/tm_mad/tm_common.sh | 64 +++++++++++++++++++++- 29 files changed, 374 insertions(+), 529 deletions(-) create mode 100755 src/tm_mad/common/context create mode 100755 src/tm_mad/common/delete rename src/tm_mad/{dummy => common}/dummy.sh (100%) create mode 100755 src/tm_mad/common/mkimage create mode 100755 src/tm_mad/common/mkswap create mode 120000 src/tm_mad/dummy/mvds mode change 100755 => 120000 src/tm_mad/shared/context mode change 100755 => 120000 src/tm_mad/shared/delete mode change 100755 => 120000 src/tm_mad/shared/mkimage mode change 100755 => 120000 src/tm_mad/shared/mkswap mode change 100755 => 120000 src/tm_mad/ssh/context mode change 100755 => 120000 src/tm_mad/ssh/delete mode change 100755 => 120000 src/tm_mad/ssh/ln mode change 100755 => 120000 src/tm_mad/ssh/mkimage mode change 100755 => 120000 src/tm_mad/ssh/mkswap 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/tm_mad/common/delete b/src/tm_mad/common/delete new file mode 100755 index 0000000000..f0c68244a6 --- /dev/null +++ b/src/tm_mad/common/delete @@ -0,0 +1,47 @@ +#!/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 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 + +#------------------------------------------------------------------------------- +# 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" +ssh_exec_and_log $DST_HOST "rm -rf $DST_PATH" "Error deleting $DST_PATH" + +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/ssh/clone b/src/tm_mad/ssh/clone index 10e1c28a96..ef7a0b6db0 100755 --- a/src/tm_mad/ssh/clone +++ b/src/tm_mad/ssh/clone @@ -16,46 +16,49 @@ # limitations under the License. # #--------------------------------------------------------------------------- # +# clone fe:SOURCE host:remote_system_ds/disk.i size +# - 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=/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 +#------------------------------------------------------------------------------- +# Set dst path and dir +#------------------------------------------------------------------------------- + SRC_PATH=`arg_path $SRC` DST_PATH=`arg_path $DST` SRC_HOST=`arg_host $SRC` DST_HOST=`arg_host $DST` - -log_debug "$1 $2" -log_debug "DST: $DST_PATH" - DST_DIR=`dirname $DST_PATH` -log "Creating directory $DST_DIR" -exec_and_log "$SSH $DST_HOST mkdir -p $DST_DIR" \ - "Error creating directory $DST_DIR" +ssh_make_path $DST_HOST $DST_DIR +#------------------------------------------------------------------------------- +# Copy files to the remote host +#------------------------------------------------------------------------------- case $SRC in http://*) log "Downloading $SRC" - exec_and_log "$SSH $DST_HOST $WGET -O $DST_PATH $SRC" \ - "Error downloading $SRC" + RMT_CMD="$WGET -O $DST_PATH $SRC" + ssh_exec_and_log "$DST_HOST" "$RMT_CMD" "Error downloading $SRC" ;; *) - log "Cloning $SRC" - exec_and_log "$SCP $SRC $DST" \ - "Error copying $SRC to $DST" + log "Cloning $SRC in $DST_PATH" + exec_and_log "$SCP $SRC $DST" "Error copying $SRC to $DST" ;; esac - -exec_and_log "$SSH $DST_HOST chmod a+rw $DST_PATH" - diff --git a/src/tm_mad/ssh/context b/src/tm_mad/ssh/context deleted file mode 100755 index 0827fdef9f..0000000000 --- a/src/tm_mad/ssh/context +++ /dev/null @@ -1,72 +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. # -#--------------------------------------------------------------------------- # - -while (( "$#" )); do - if [ "$#" == "1" ]; then - DST=$1 - else - SRC="$SRC $1" - fi - shift -done - - -if [ -z "${ONE_LOCATION}" ]; then - TMCOMMON=/usr/lib/one/mads/tm_common.sh -else - TMCOMMON=$ONE_LOCATION/lib/mads/tm_common.sh -fi - -. $TMCOMMON - - -DST_PATH=`arg_path $DST` -DST_DIR=`dirname $DST_PATH` -DST_FILE=`basename $DST_PATH` -DST_HASH=`echo -n $DST | $MD5SUM | $AWK '{print $1}'` -if [ -z "$ONE_LOCATION" ]; then - TMP_DIR="/var/lib/one/$DST_HASH" -else - TMP_DIR="$ONE_LOCATION/var/$DST_HASH" -fi -ISO_DIR="$TMP_DIR/isofiles" - - -exec_and_log "mkdir -p $ISO_DIR" \ - "Error creating directory $ISO_DIR" - -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 $TMP_DIR/$DST_FILE -J -R $ISO_DIR" \ - "Error creating iso fs" -exec_and_log "$SCP $TMP_DIR/$DST_FILE $DST" \ - "Error copying $TMP_DIR/$DST_FILE to $DST" -exec_and_log "rm -rf $TMP_DIR" \ - "Error deleting $TMP_DIR" diff --git a/src/tm_mad/ssh/context b/src/tm_mad/ssh/context new file mode 120000 index 0000000000..921312e950 --- /dev/null +++ b/src/tm_mad/ssh/context @@ -0,0 +1 @@ +../common/context \ No newline at end of file diff --git a/src/tm_mad/ssh/delete b/src/tm_mad/ssh/delete deleted file mode 100755 index 9046c19414..0000000000 --- a/src/tm_mad/ssh/delete +++ /dev/null @@ -1,35 +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. # -#--------------------------------------------------------------------------- # - -SRC=$1 -DST=$2 - -if [ -z "${ONE_LOCATION}" ]; then - TMCOMMON=/usr/lib/one/mads/tm_common.sh -else - TMCOMMON=$ONE_LOCATION/lib/mads/tm_common.sh -fi - -. $TMCOMMON - -SRC_PATH=`arg_path $SRC` -SRC_HOST=`arg_host $SRC` - -log "Deleting $SRC_PATH" -exec_and_log "$SSH $SRC_HOST rm -rf $SRC_PATH" \ - "Error deleting $SRC_PATH" diff --git a/src/tm_mad/ssh/delete b/src/tm_mad/ssh/delete new file mode 120000 index 0000000000..230e56774f --- /dev/null +++ b/src/tm_mad/ssh/delete @@ -0,0 +1 @@ +../common/delete \ No newline at end of file diff --git a/src/tm_mad/ssh/ln b/src/tm_mad/ssh/ln deleted file mode 100755 index 40d8e6f2e5..0000000000 --- a/src/tm_mad/ssh/ln +++ /dev/null @@ -1,34 +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. # -#--------------------------------------------------------------------------- # - -SRC=$1 -DST=$2 - -if [ -z "${ONE_LOCATION}" ]; then - TMCOMMON=/usr/lib/one/mads/tm_common.sh - TM_COMMANDS_LOCATION=/usr/lib/one/tm_commands/ -else - TMCOMMON=$ONE_LOCATION/lib/mads/tm_common.sh - TM_COMMANDS_LOCATION=$ONE_LOCATION/lib/tm_commands/ -fi - -. $TMCOMMON - -log "Link $SRC_PATH (non shared dir, will clone)" -#exec_and_log "ln -s $SRC_PATH $DST_PATH" -exec $TM_COMMANDS_LOCATION/ssh/tm_clone.sh $SRC $DST diff --git a/src/tm_mad/ssh/ln b/src/tm_mad/ssh/ln new file mode 120000 index 0000000000..4197517ec0 --- /dev/null +++ b/src/tm_mad/ssh/ln @@ -0,0 +1 @@ +./clone \ No newline at end of file diff --git a/src/tm_mad/ssh/mkimage b/src/tm_mad/ssh/mkimage deleted file mode 100755 index ace8017ca8..0000000000 --- a/src/tm_mad/ssh/mkimage +++ /dev/null @@ -1,43 +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. # -#--------------------------------------------------------------------------- # - -if [ -z "${ONE_LOCATION}" ]; then - TMCOMMON=/usr/lib/one/mads/tm_common.sh -else - TMCOMMON=$ONE_LOCATION/lib/mads/tm_common.sh -fi - -. $TMCOMMON - -SIZE=$1 -FSTYPE=$2 -DST=$3 - -DST_PATH=`arg_path $DST` -DST_HOST=`arg_host $DST` -DST_DIR=`dirname $DST_PATH` - -MKFS_CMD=`mkfs_command $DST_PATH $FSTYPE` - -exec_and_log "$SSH $DST_HOST mkdir -p $DST_DIR" \ - "Error creating directory $DST_DIR" -exec_and_log "$SSH $DST_HOST $DD if=/dev/zero of=$DST_PATH bs=1 count=1 seek=${SIZE}M" \ - "Could not create image $DST_PATH" -exec_and_log "$SSH $DST_HOST $MKFS_CMD" \ - "Unable to create filesystem $FSTYPE in $DST_PATH" -exec_and_log "$SSH $DST_HOST chmod a+rw $DST_PATH" diff --git a/src/tm_mad/ssh/mkimage b/src/tm_mad/ssh/mkimage new file mode 120000 index 0000000000..ad1bdd354d --- /dev/null +++ b/src/tm_mad/ssh/mkimage @@ -0,0 +1 @@ +../common/mkimage \ No newline at end of file diff --git a/src/tm_mad/ssh/mkswap b/src/tm_mad/ssh/mkswap deleted file mode 100755 index b2c9b80665..0000000000 --- a/src/tm_mad/ssh/mkswap +++ /dev/null @@ -1,45 +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. # -#--------------------------------------------------------------------------- # - -SIZE=$1 -DST=$2 - -if [ -z "${ONE_LOCATION}" ]; then - TMCOMMON=/usr/lib/one/mads/tm_common.sh -else - TMCOMMON=$ONE_LOCATION/lib/mads/tm_common.sh -fi - -. $TMCOMMON - -DST_PATH=`arg_path $DST` -DST_HOST=`arg_host $DST` - -DST_DIR=`dirname $DST_PATH` - -log "Creating ${SIZE}Mb image in $DST_PATH" -exec_and_log "$SSH $DST_HOST mkdir -p $DST_DIR" -exec_and_log "$SSH $DST_HOST $DD if=/dev/zero of=$DST_PATH bs=1 count=1 seek=${SIZE}M" \ - "Could not create image file $DST_PATH" - -log "Initializing swap space" -exec_and_log "$SSH $DST_HOST $MKSWAP $DST_PATH" \ - "Could not create swap on $DST_PATH" - -exec_and_log "$SSH $DST_HOST chmod a+w $DST_PATH" - diff --git a/src/tm_mad/ssh/mkswap b/src/tm_mad/ssh/mkswap new file mode 120000 index 0000000000..3e0699b0f3 --- /dev/null +++ b/src/tm_mad/ssh/mkswap @@ -0,0 +1 @@ +../common/mkswap \ No newline at end of file diff --git a/src/tm_mad/ssh/mv b/src/tm_mad/ssh/mv index e7c7e2d668..61319e6612 100755 --- a/src/tm_mad/ssh/mv +++ b/src/tm_mad/ssh/mv @@ -16,17 +16,26 @@ # limitations under the License. # #--------------------------------------------------------------------------- # +# MV +# +# - 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/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 < Date: Sun, 4 Mar 2012 22:23:01 +0100 Subject: [PATCH 08/10] feature #1112: Move to Datastore action for the shared and ssh transfer drivers --- src/tm_mad/shared/mvds | 73 ++++++++++++++++++++++++++++++++++++++++++ src/tm_mad/ssh/clone | 1 - src/tm_mad/ssh/mvds | 54 +++++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+), 1 deletion(-) create mode 100755 src/tm_mad/shared/mvds create mode 100755 src/tm_mad/ssh/mvds 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 < Date: Mon, 5 Mar 2012 11:53:59 +0100 Subject: [PATCH 09/10] feature #1112: Remove unnecessary files from install.sh and the 'mv' datastore scripts --- install.sh | 8 --- src/datastore_mad/remotes/fs/fs.conf | 38 ---------- src/datastore_mad/remotes/fs/mv | 75 -------------------- src/datastore_mad/remotes/vmware/mv | 75 -------------------- src/datastore_mad/remotes/vmware/vmware.conf | 38 ---------- 5 files changed, 234 deletions(-) delete mode 100644 src/datastore_mad/remotes/fs/fs.conf delete mode 100755 src/datastore_mad/remotes/fs/mv delete mode 100755 src/datastore_mad/remotes/vmware/mv delete mode 100644 src/datastore_mad/remotes/vmware/vmware.conf 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/src/datastore_mad/remotes/fs/fs.conf b/src/datastore_mad/remotes/fs/fs.conf deleted file mode 100644 index ec29989e22..0000000000 --- a/src/datastore_mad/remotes/fs/fs.conf +++ /dev/null @@ -1,38 +0,0 @@ -# -------------------------------------------------------------------------- # -# 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. # -#--------------------------------------------------------------------------- # - -# PRESERVE BASH SYNTAX - -#******************************************************************************* -# 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 -#******************************************************************************* - -#BASE_PATH=/var/lib/one/images - -RESTRICTED_DIRS="/etc/" - -SAFE_DIRS="$HOME/public/" 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/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/vmware/vmware.conf b/src/datastore_mad/remotes/vmware/vmware.conf deleted file mode 100644 index ec29989e22..0000000000 --- a/src/datastore_mad/remotes/vmware/vmware.conf +++ /dev/null @@ -1,38 +0,0 @@ -# -------------------------------------------------------------------------- # -# 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. # -#--------------------------------------------------------------------------- # - -# PRESERVE BASH SYNTAX - -#******************************************************************************* -# 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 -#******************************************************************************* - -#BASE_PATH=/var/lib/one/images - -RESTRICTED_DIRS="/etc/" - -SAFE_DIRS="$HOME/public/" From f4e20d81ce56062af24644945debd0116adbc794 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Mon, 5 Mar 2012 11:56:18 +0100 Subject: [PATCH 10/10] feature #1112: Improvements in datastora_mad drivers: * Remove unnecessary chowns. * Improve xpath access from datastore shell scripts. * Read UNAME, RESTRICTED_DIRS and SAFE_DIRS from datastore template. * New size function using qemu-img --- src/datastore_mad/remotes/fs/cp | 25 +++++++++---- src/datastore_mad/remotes/fs/mkfs | 23 +++++++++--- src/datastore_mad/remotes/libfs.sh | 54 +++++++++++++++++---------- src/datastore_mad/remotes/vmware/cp | 23 +++++++++--- src/datastore_mad/remotes/vmware/mkfs | 27 ++++++++------ src/datastore_mad/remotes/xpath.rb | 2 +- 6 files changed, 104 insertions(+), 50 deletions(-) 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/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/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