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

Merge branch 'feature-1112' of git.opennebula.org:one into feature-1112

This commit is contained in:
Tino Vazquez 2012-03-05 14:39:08 +01:00
commit c2069ea215
51 changed files with 615 additions and 807 deletions

View File

@ -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"
#-------------------------------------------------------------------------------

View File

@ -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"

View File

@ -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

View File

@ -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']]

View File

@ -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']]

View File

@ -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'])]

View File

@ -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'])]

View File

@ -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

View File

@ -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
########################################################################

View File

@ -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);
}

View File

@ -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

View File

@ -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`

View File

@ -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"

View File

@ -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

View File

@ -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

View File

@ -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"

View File

@ -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"

View File

@ -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

View File

@ -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

78
src/tm_mad/common/context Executable file
View File

@ -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

View File

@ -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:remote_system_ds/disk.i|host:remote_system_ds/>
# - 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

61
src/tm_mad/common/mkimage Executable file
View File

@ -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 <<EOF
$DD if=/dev/zero of=$DST_PATH bs=1 count=1 seek=${SIZE}M
$MKFS_CMD
EOF
)
log "Making filesystem of ${SIZE}M and type $FSTYPE at $DST"
ssh_exec_and_log $DST_HOST "$MKSCRIPT" "Could not create image $DST_PATH"
exit 0

30
src/tm_mad/common/mkswap Executable file
View File

@ -0,0 +1,30 @@
#!/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`
exit 0

View File

@ -1 +1 @@
dummy.sh
../common/dummy.sh

View File

@ -1 +1 @@
dummy.sh
../common/dummy.sh

View File

@ -1 +1 @@
dummy.sh
../common/dummy.sh

View File

@ -1 +1 @@
dummy.sh
../common/dummy.sh

View File

@ -1 +1 @@
dummy.sh
../common/dummy.sh

View File

@ -1 +1 @@
dummy.sh
../common/dummy.sh

View File

@ -1 +1 @@
dummy.sh
../common/dummy.sh

1
src/tm_mad/dummy/mvds Symbolic link
View File

@ -0,0 +1 @@
../common/dummy.sh

View File

@ -84,7 +84,7 @@ class TransferManagerDriver < OpenNebulaDriver
if result == RESULT[:failure]
send_message("TRANSFER", result, id, info)
break
return
end
}

View File

@ -37,19 +37,13 @@ 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/"}
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
ssh_make_path $DST_HOST $DST_DIR
#-------------------------------------------------------------------------------
# Clone (cp) SRC into DST
@ -57,11 +51,17 @@ fi
case $SRC in
http://*)
log "Downloading $SRC into $DST_PATH"
exec_and_log "$WGET -O $DST_PATH $SRC" "Error downloading $SRC"
ssh_exec_and_log $DST_HOST \
"$WGET -O $DST_PATH $SRC" \
"Error downloading $SRC"
;;
*)
log "Cloning $SRC_PATH in $DST_PATH"
exec_and_log "cp -r $SRC_PATH $DST_PATH" "Error copying $SRC to $DST"
log "Cloning $SRC_PATH in $DST"
ssh_exec_and_log $DST_HOST \
"cd $DST_DIR; cp -r $SRC_PATH $DST_PATH" \
"Error copying $SRC to $DST"
;;
esac
exit 0

View File

@ -1,64 +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
get_vmdir
DST_PATH=`arg_path $DST`
fix_dst_path
DST_DIR=`dirname $DST_PATH`
ISO_DIR=$DST_DIR/isofiles
exec_and_log "mkdir -p $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 $DST_PATH -J -R $ISO_DIR" \
"Error creating iso fs"
exec_and_log "rm -rf $ISO_DIR"

1
src/tm_mad/shared/context Symbolic link
View File

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

View File

@ -1,51 +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. #
#--------------------------------------------------------------------------- #
# DELETE <host:remote_system_ds/disk.i|host:remote_system_ds/>
# - 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"

1
src/tm_mad/shared/delete Symbolic link
View File

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

View File

@ -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

View File

@ -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

1
src/tm_mad/shared/mkimage Symbolic link
View File

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

View File

@ -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`

1
src/tm_mad/shared/mkswap Symbolic link
View File

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

View File

@ -1 +1 @@
../dummy/dummy.sh
../common/dummy.sh

73
src/tm_mad/shared/mvds Executable file
View File

@ -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 <<EOF
if [ \( -L $SRC \) -a \
\( "`$READLINK -f $SRC_PATH`" = "`$READLINK -f $DST_PATH`" \) ] ; then
echo "Not moving files to image repo, they are the same"
else
mv -f $SRC_PATH $DST_PATH
fi
;;
esac
if [ -d $DST_PATH ]; then
chmod 0770 $DST_PATH
else
chmod 0660 $DST_PATH
fi
EOF
)
log "Moving $SRC_PATH to datastore as $DST_PATH"
ssh_exec_and_log $SRC_HOST "$MVSCRIPT" "Could not move image $DST_PATH"
exit 0

View File

@ -16,46 +16,48 @@
# 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"

View File

@ -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"

1
src/tm_mad/ssh/context Symbolic link
View File

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

View File

@ -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"

1
src/tm_mad/ssh/delete Symbolic link
View File

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

View File

@ -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

1
src/tm_mad/ssh/ln Symbolic link
View File

@ -0,0 +1 @@
./clone

View File

@ -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"

1
src/tm_mad/ssh/mkimage Symbolic link
View File

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

View File

@ -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"

1
src/tm_mad/ssh/mkswap Symbolic link
View File

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

View File

@ -16,17 +16,26 @@
# limitations under the License. #
#--------------------------------------------------------------------------- #
# MV <hostA:system_ds/disk.i|hostB:system_ds/disk.i>
# <hostA:system_ds/|hostB:system_ds/>
# - 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

View File

@ -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

View File

@ -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
}
}
# ------------------------------------------------------------------------------
# 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 <<EOF
$2
EOF`
SSH_EXEC_RC=$?
if [ $? -ne 0 ]; then
log_error "Command $2 failed"
log_error "$SSH_EXEC_ERR"
if [ -n "$3" ]; then
error_message "$3"
else
error_message "Error executing $2: $SSH_EXEC_ERR"
fi
exit $SSH_EXEC_RC
fi
}
#Creates path ($2) at $1
function ssh_make_path
{
SSH_EXEC_ERR=`$SSH $1 bash -s 2>&1 1>/dev/null <<EOF
if [ ! -d $2 ]; then
mkdir -p $2
fi
EOF`
SSH_EXEC_RC=$?
if [ $? -ne 0 ]; then
error_message "Error creating directory $2 at $1: $SSH_EXEC_ERR"
exit $SSH_EXEC_RC
fi
}
#Transform a system data store path from its remote location to the local one
#$1 remote path
function remote2local_path
{
if [ -z "$RMT_DS_DIR" ]; then
set_ds_location
fi
echo "$ONE_LOCAL_VAR/datastores/${1##"$RMT_DS_DIR/"}"
}

View File

@ -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
//--------------------------------------------------------------------------