mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-10 01:17:40 +03:00
feature #1112: Work on the datastore drivers:
- Moved references to image_mad to datastore_mad. Adjusted installation dirs and source files - FS driver cp command uses DS_DRIVER_ACTION_DATA message - New libfs.sh to deal with datastore protocol - New xpath.rb to get XML elements in shell programs - Change oned.cong and OpenNebula core files to use DATASTORE instead of IMAGE - Change mkfs driver function to use the drv action data
This commit is contained in:
parent
621b8f1e76
commit
3a8525bdc1
@ -89,12 +89,9 @@ private:
|
||||
/**
|
||||
* Sends a make filesystem request to the MAD: "MKFS IMAGE_ID PATH SIZE_MB"
|
||||
* @param oid the image id.
|
||||
* @param fs type
|
||||
* @param size_mb of the image to be created
|
||||
* @param drv_msg xml data for the mad operation.
|
||||
*/
|
||||
void mkfs(int oid,
|
||||
const string& fs,
|
||||
int size_mb) const;
|
||||
void mkfs(int oid, const string& drv_msg) const;
|
||||
/**
|
||||
* Sends a delete request to the MAD: "DELETE IMAGE_ID PATH"
|
||||
* @param oid the image id.
|
||||
|
42
install.sh
42
install.sh
@ -99,7 +99,7 @@ if [ -z "$ROOT" ] ; then
|
||||
VAR_LOCATION="/var/lib/one"
|
||||
SUNSTONE_LOCATION="$LIB_LOCATION/sunstone"
|
||||
OZONES_LOCATION="$LIB_LOCATION/ozones"
|
||||
IMAGES_LOCATION="$VAR_LOCATION/images"
|
||||
SYSTEM_DS_LOCATION="$VAR_LOCATION/system_ds"
|
||||
RUN_LOCATION="/var/run/one"
|
||||
LOCK_LOCATION="/var/lock/one"
|
||||
INCLUDE_LOCATION="/usr/include"
|
||||
@ -130,7 +130,7 @@ if [ -z "$ROOT" ] ; then
|
||||
MAKE_DIRS="$BIN_LOCATION $LIB_LOCATION $ETC_LOCATION $VAR_LOCATION \
|
||||
$INCLUDE_LOCATION $SHARE_LOCATION \
|
||||
$LOG_LOCATION $RUN_LOCATION $LOCK_LOCATION \
|
||||
$IMAGES_LOCATION $MAN_LOCATION"
|
||||
$SYSTEM_DS_LOCATION $MAN_LOCATION"
|
||||
|
||||
DELETE_DIRS="$LIB_LOCATION $ETC_LOCATION $LOG_LOCATION $VAR_LOCATION \
|
||||
$RUN_LOCATION $SHARE_DIRS"
|
||||
@ -145,7 +145,7 @@ else
|
||||
VAR_LOCATION="$ROOT/var"
|
||||
SUNSTONE_LOCATION="$LIB_LOCATION/sunstone"
|
||||
OZONES_LOCATION="$LIB_LOCATION/ozones"
|
||||
IMAGES_LOCATION="$VAR_LOCATION/images"
|
||||
SYSTEM_DS_LOCATION="$VAR_LOCATION/system_ds"
|
||||
INCLUDE_LOCATION="$ROOT/include"
|
||||
SHARE_LOCATION="$ROOT/share"
|
||||
MAN_LOCATION="$ROOT/share/man/man1"
|
||||
@ -166,7 +166,7 @@ else
|
||||
DELETE_DIRS="$MAKE_DIRS"
|
||||
else
|
||||
MAKE_DIRS="$BIN_LOCATION $LIB_LOCATION $ETC_LOCATION $VAR_LOCATION \
|
||||
$INCLUDE_LOCATION $SHARE_LOCATION $IMAGES_LOCATION \
|
||||
$INCLUDE_LOCATION $SHARE_LOCATION $SYSTEM_DS_LOCATION \
|
||||
$MAN_LOCATION $OZONES_LOCATION"
|
||||
|
||||
DELETE_DIRS="$MAKE_DIRS"
|
||||
@ -180,7 +180,7 @@ fi
|
||||
SHARE_DIRS="$SHARE_LOCATION/examples \
|
||||
$SHARE_LOCATION/examples/tm"
|
||||
|
||||
ETC_DIRS="$ETC_LOCATION/image \
|
||||
ETC_DIRS="$ETC_LOCATION/datastore \
|
||||
$ETC_LOCATION/im_ec2 \
|
||||
$ETC_LOCATION/vmm_ec2 \
|
||||
$ETC_LOCATION/vmm_exec \
|
||||
@ -385,7 +385,8 @@ INSTALL_FILES=(
|
||||
VMWARE_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/vmware
|
||||
DUMMY_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/dummy
|
||||
LVM_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/lvm
|
||||
IMAGE_DRIVER_FS_SCRIPTS:$VAR_LOCATION/remotes/datastore/fs
|
||||
DATASTORE_DRIVER_COMMON_SCRIPTS:$VAR_LOCATION/remotes/datastore/
|
||||
DATASTORE_DRIVER_FS_SCRIPTS:$VAR_LOCATION/remotes/datastore/fs
|
||||
NETWORK_FILES:$VAR_LOCATION/remotes/vnm
|
||||
NETWORK_8021Q_FILES:$VAR_LOCATION/remotes/vnm/802.1Q
|
||||
NETWORK_DUMMY_FILES:$VAR_LOCATION/remotes/vnm/dummy
|
||||
@ -524,7 +525,7 @@ INSTALL_ETC_FILES=(
|
||||
VMWARE_ETC_FILES:$ETC_LOCATION
|
||||
VMM_EC2_ETC_FILES:$ETC_LOCATION/vmm_ec2
|
||||
VMM_EXEC_ETC_FILES:$ETC_LOCATION/vmm_exec
|
||||
IMAGE_DRIVER_FS_ETC_FILES:$ETC_LOCATION/image/
|
||||
DATASTORE_DRIVER_FS_ETC_FILES:$ETC_LOCATION/datastore/
|
||||
IM_EC2_ETC_FILES:$ETC_LOCATION/im_ec2
|
||||
TM_SHARED_ETC_FILES:$ETC_LOCATION/tm_shared
|
||||
TM_SSH_ETC_FILES:$ETC_LOCATION/tm_ssh
|
||||
@ -628,8 +629,8 @@ MADS_LIB_FILES="src/mad/sh/madcommon.sh \
|
||||
src/hm_mad/one_hm \
|
||||
src/authm_mad/one_auth_mad.rb \
|
||||
src/authm_mad/one_auth_mad \
|
||||
src/image_mad/one_image.rb \
|
||||
src/image_mad/one_image"
|
||||
src/datastore_mad/one_datastore.rb \
|
||||
src/datastore_mad/one_datastore"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# VMM SH Driver KVM scripts, to be installed under $REMOTES_LOCATION/vmm/kvm
|
||||
@ -795,18 +796,19 @@ VMWARE_TM_COMMANDS_LIB_FILES="src/tm_mad/vmware/tm_clone.sh \
|
||||
src/tm_mad/vmware/tm_context.sh"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Image Repository drivers, to be installed under $REMOTES_LOCATION/image
|
||||
# - FS based Image Repository, $REMOTES_LOCATION/image/fs
|
||||
# Datastore drivers, to be installed under $REMOTES_LOCATION/datastore
|
||||
# - FS based Image Repository, $REMOTES_LOCATION/datastore/fs
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
IMAGE_DRIVER_FS_ETC_FILES="src/image_mad/remotes/fs/fs.conf"
|
||||
DATASTORE_DRIVER_FS_ETC_FILES="src/datastore_mad/remotes/fs/fs.conf"
|
||||
|
||||
IMAGE_DRIVER_FS_SCRIPTS="src/image_mad/remotes/fs/cp \
|
||||
src/image_mad/remotes/fs/mkfs \
|
||||
src/image_mad/remotes/fs/mv \
|
||||
src/image_mad/remotes/fs/fsrc \
|
||||
src/image_mad/remotes/fs/rm"
|
||||
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"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Migration scripts for onedb command, to be installed under $LIB_LOCATION
|
||||
@ -1505,12 +1507,6 @@ if [ "$UNINSTALL" = "no" ] ; then
|
||||
for d in $CHOWN_DIRS; do
|
||||
chown -R $ONEADMIN_USER:$ONEADMIN_GROUP $DESTDIR$d
|
||||
done
|
||||
|
||||
# --- Set correct permissions for Image Repository ---
|
||||
|
||||
if [ -d "$DESTDIR$IMAGES_LOCATION" ]; then
|
||||
chmod 3770 $DESTDIR$IMAGES_LOCATION
|
||||
fi
|
||||
else
|
||||
for d in `echo $DELETE_DIRS | awk '{for (i=NF;i>=1;i--) printf $i" "}'`; do
|
||||
rmdir $d
|
||||
|
@ -107,7 +107,7 @@ MAC_PREFIX = "02:00"
|
||||
|
||||
SYSTEM_DS = [
|
||||
base_path = "/var/lib/one/system_ds",
|
||||
type = "shared"
|
||||
type = "fs"
|
||||
]
|
||||
|
||||
DEFAULT_IMAGE_TYPE = "OS"
|
||||
@ -336,23 +336,21 @@ TM_MAD = [
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
#*******************************************************************************
|
||||
# Image Manager Driver Configuration
|
||||
# Datastore Driver Configuration
|
||||
#*******************************************************************************
|
||||
# Drivers to manage the image repository, specialized for the storage backend
|
||||
# Drivers to manage the datastores, specialized for the storage backend
|
||||
# executable: path of the transfer driver executable, can be an
|
||||
# absolute path or relative to $ONE_LOCATION/lib/mads (or
|
||||
# /usr/lib/one/mads/ if OpenNebula was installed in /)
|
||||
#
|
||||
# arguments : for the driver executable
|
||||
# -t number of threads, i.e. number of repo operations at the same time
|
||||
# -d datastore types separated by commas
|
||||
#*******************************************************************************
|
||||
#-------------------------------------------------------------------------------
|
||||
# FS based Image Manager Driver Configuration
|
||||
# -t number of threads, i.e. number of repo operations at the same time
|
||||
#-------------------------------------------------------------------------------
|
||||
IMAGE_MAD = [
|
||||
executable = "one_image",
|
||||
|
||||
DATASTORE_MAD = [
|
||||
executable = "one_datastore",
|
||||
arguments = "-t 15 -d fs" ]
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
#*******************************************************************************
|
||||
# Hook Manager Configuration
|
||||
@ -389,7 +387,6 @@ IMAGE_MAD = [
|
||||
# allocated
|
||||
# - NO, The hook is executed in the OpenNebula server (default)
|
||||
#
|
||||
#
|
||||
# Host Hooks (HOST_HOOK) defined by:
|
||||
# name : for the hook, useful to track the hook (OPTIONAL)
|
||||
# on : when the hook should be executed,
|
||||
@ -408,10 +405,8 @@ IMAGE_MAD = [
|
||||
# - YES, The hook is executed in the host
|
||||
# - NO, The hook is executed in the OpenNebula server (default)
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
HM_MAD = [
|
||||
executable = "one_hm" ]
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
#*******************************************************************************
|
||||
|
@ -47,8 +47,8 @@ DatastorePool::DatastorePool(SqlDB * db,
|
||||
|
||||
// Build the default datastore
|
||||
|
||||
oss << "NAME = " << SYSTEM_DS_ID << endl
|
||||
<< "BASE_PATH = " << base_path << endl
|
||||
oss << "NAME = " << SYSTEM_DS_NAME << endl
|
||||
<< "BASE_PATH = " << base_path << endl
|
||||
<< "TYPE = " << type;
|
||||
|
||||
DatastoreTemplate * ds_tmpl = new DatastoreTemplate;
|
||||
|
@ -37,10 +37,10 @@ require 'base64'
|
||||
require 'rexml/document'
|
||||
|
||||
# This class provides basic messaging and logging functionality
|
||||
# to implement Image Repository Drivers. A image repository driver
|
||||
# to implement Datastore Drivers. A datastore driver
|
||||
# is a program (or a set of) that specialize the OpenNebula behavior
|
||||
# by interfacing with specific infrastructure storage solutions.
|
||||
class ImageDriver < OpenNebulaDriver
|
||||
class DatastoreDriver < OpenNebulaDriver
|
||||
|
||||
# Image Driver Protocol constants
|
||||
ACTION = {
|
||||
@ -77,39 +77,33 @@ class ImageDriver < OpenNebulaDriver
|
||||
@types = ds_type
|
||||
end
|
||||
|
||||
register_action(ACTION[:mv].to_sym, method("mv"))
|
||||
# register_action(ACTION[:mv].to_sym, method("mv"))
|
||||
register_action(ACTION[:cp].to_sym, method("cp"))
|
||||
register_action(ACTION[:rm].to_sym, method("rm"))
|
||||
register_action(ACTION[:mkfs].to_sym, method("mkfs"))
|
||||
end
|
||||
|
||||
# Image Manager Protocol Actions (generic implementation
|
||||
def mv(id, ds, src, dst)
|
||||
do_image_action(id, ds, :mv, "'#{src}' '#{dst}' '#{id}'")
|
||||
end
|
||||
############################################################################
|
||||
# Image Manager Protocol Actions (generic implementation)
|
||||
############################################################################
|
||||
# TODO: Integrate this with TM
|
||||
# def mv(id, ds, src, dst)
|
||||
# do_image_action(id, ds, :mv, "'#{src}' '#{dst}' '#{id}'")
|
||||
# end
|
||||
|
||||
def cp(id, drv_message)
|
||||
data = decode(drv_message)
|
||||
# TODO
|
||||
# ds = data.elements['DATASTORE/DRIVER'].text
|
||||
ds = "fs"
|
||||
src = data.elements['IMAGE/PATH'].text
|
||||
|
||||
do_image_action(id, ds, :cp, "'#{src}' '#{id}'")
|
||||
ds = get_ds_type(drv_message)
|
||||
do_image_action(id, ds, :cp, "#{drv_message} #{id}")
|
||||
end
|
||||
|
||||
def rm(id, drv_message)
|
||||
data = decode(drv_message)
|
||||
# TODO
|
||||
# ds = data.elements['DATASTORE/DRIVER'].text
|
||||
ds = "fs"
|
||||
dst = data.elements['IMAGE/SOURCE'].text
|
||||
|
||||
do_image_action(id, ds, :rm, "'#{dst}' '#{id}'")
|
||||
ds = get_ds_type(drv_message)
|
||||
do_image_action(id, ds, :rm, "#{drv_message} #{id}")
|
||||
end
|
||||
|
||||
def mkfs(id, ds, fs, size)
|
||||
do_image_action(id, ds, :mkfs, "'#{fs}' '#{size}' '#{id}'")
|
||||
def mkfs(id, drv_message)
|
||||
ds = get_ds_type(drv_message)
|
||||
do_image_action(id, ds, :mkfs, "#{drv_message} #{id}")
|
||||
end
|
||||
|
||||
private
|
||||
@ -139,23 +133,22 @@ class ImageDriver < OpenNebulaDriver
|
||||
send_message(ACTION[action], result, id, info)
|
||||
end
|
||||
|
||||
# TODO: Move decode to OpenNebulaDriver ?
|
||||
|
||||
# Decodes the encoded XML driver message received from the core
|
||||
#
|
||||
# @param [String] drv_message the driver message
|
||||
# @return [REXML::Element] the root element of the decoded XML message
|
||||
def decode(drv_message)
|
||||
def get_ds_type(drv_message)
|
||||
message = Base64.decode64(drv_message)
|
||||
|
||||
xml_doc = REXML::Document.new(message)
|
||||
|
||||
xml_doc.root
|
||||
dsxml = xml_doc.root.elements['/DS_DRIVER_ACTION_DATA/DATASTORE/TYPE']
|
||||
dstxt = dsxml.text if dsxml
|
||||
|
||||
return dstxt
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# ImageDriver Main program
|
||||
################################################################################
|
||||
################################################################################
|
||||
# DatastoreDriver Main program
|
||||
################################################################################
|
||||
################################################################################
|
||||
|
||||
opts = GetoptLong.new(
|
||||
[ '--threads', '-t', GetoptLong::OPTIONAL_ARGUMENT ],
|
||||
@ -178,5 +171,5 @@ rescue Exception => e
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
image_driver = ImageDriver.new(ds_type, :concurrency => threads)
|
||||
image_driver.start_driver
|
||||
ds_driver = DatastoreDriver.new(ds_type, :concurrency => threads)
|
||||
ds_driver.start_driver
|
@ -30,10 +30,20 @@ else
|
||||
fi
|
||||
|
||||
. $LIB_LOCATION/sh/scripts_common.sh
|
||||
source $(dirname $0)/fsrc
|
||||
|
||||
SRC=$1
|
||||
DRIVER_PATH=$(dirname $0)
|
||||
source ${DRIVER_PATH}/../libfs.sh
|
||||
|
||||
# -------- Get cp and datastore arguments from OpenNebula core ------------
|
||||
|
||||
DRV_ACTION=$1
|
||||
ID=$2
|
||||
|
||||
set_up_datastore $DRV_ACTION
|
||||
|
||||
XPATH="${DRIVER_PATH}/../xpath.rb -b $DRV_ACTION"
|
||||
eval "SRC=`$XPATH /DS_DRIVER_ACTION_DATA/IMAGE/PATH`"
|
||||
|
||||
DST=`generate_image_path`
|
||||
|
||||
# ------------ Copy the image to the repository -------------
|
||||
@ -42,8 +52,7 @@ case $SRC in
|
||||
http://*)
|
||||
log "Downloading $SRC to the image repository"
|
||||
|
||||
exec_and_log "$WGET -O $DST $SRC" \
|
||||
"Error downloading $SRC"
|
||||
exec_and_log "$WGET -O $DST $SRC" "Error downloading $SRC"
|
||||
|
||||
exec_and_log "chmod 0660 $DST"
|
||||
;;
|
||||
@ -59,8 +68,7 @@ vmware://*)
|
||||
|
||||
log "Copying local disk folder $SRC to the image repository"
|
||||
|
||||
exec_and_log "cp -rf $SRC $DST" \
|
||||
"Error copying $SRC to $DST"
|
||||
exec_and_log "cp -rf $SRC $DST" "Error copying $SRC to $DST"
|
||||
|
||||
if [ ! -f $DST/disk.vmdk ]; then
|
||||
BASE_DISK_FILE=`ls $DST | grep -v '.*-s[0-9]*\.vmdk'`
|
||||
@ -81,15 +89,13 @@ vmware://*)
|
||||
|
||||
log "Copying local image $SRC to the image repository"
|
||||
|
||||
exec_and_log "cp -f $SRC $DST" \
|
||||
"Error copying $SRC to $DST"
|
||||
exec_and_log "cp -f $SRC $DST" "Error copying $SRC to $DST"
|
||||
|
||||
exec_and_log "chmod 0660 $DST"
|
||||
;;
|
||||
esac
|
||||
|
||||
# ---------------- Get the size of the image & fix perms ------------
|
||||
|
||||
# ---------------- Get the size of the image ------------
|
||||
|
||||
SIZE=`fs_du $DST`
|
||||
|
@ -17,9 +17,9 @@
|
||||
# PRESERVE BASH SYNTAX
|
||||
|
||||
#*******************************************************************************
|
||||
# Configuration File for File-System based Image Repositories
|
||||
# DEFAULT Configuration File for File-System based Datastores
|
||||
#-------------------------------------------------------------------------------
|
||||
# IMAGE_REPOSITORY: Path where the images will be stored. If not defined
|
||||
# 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
|
||||
@ -31,7 +31,7 @@
|
||||
# of paths.This will allow you to open specific paths within RESTRICTED_DIRS
|
||||
#*******************************************************************************
|
||||
|
||||
#IMAGE_REPOSITORY_PATH=/var/lib/one/images
|
||||
#BASE_PATH=/var/lib/one/images
|
||||
|
||||
RESTRICTED_DIRS="/etc/"
|
||||
|
@ -17,52 +17,73 @@
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Configuration File for File-System based Image Repositories
|
||||
# - IMAGE_REPOSITORY: Path where the images will be stored
|
||||
# - RESTRICTED_DIRS: Paths that can not be used to register images
|
||||
# - SAFE_DIRS: Paths that are safe to specify image paths
|
||||
# Set up environment variables
|
||||
# @param $1 - template (base 64 encoded) with driver data
|
||||
# @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
|
||||
# - BASE_PATH: Path where the images will be stored
|
||||
#------------------------------------------------------------------------------
|
||||
if [ -z "${ONE_LOCATION}" ]; then
|
||||
VAR_LOCATION=/var/lib/one/
|
||||
ETC_LOCATION=/etc/one/
|
||||
else
|
||||
VAR_LOCATION=$ONE_LOCATION/var/
|
||||
ETC_LOCATION=$ONE_LOCATION/etc/
|
||||
fi
|
||||
|
||||
CONF_FILE=$ETC_LOCATION/image/fs.conf
|
||||
|
||||
source $CONF_FILE
|
||||
|
||||
if [ -z "${IMAGE_REPOSITORY_PATH}" ]; then
|
||||
function set_up_datastore {
|
||||
#
|
||||
# Load the default configuration for FS datastores
|
||||
#
|
||||
if [ -z "${ONE_LOCATION}" ]; then
|
||||
IMAGE_REPOSITORY_PATH=/var/lib/one/images
|
||||
VAR_LOCATION=/var/lib/one/
|
||||
ETC_LOCATION=/etc/one/
|
||||
else
|
||||
IMAGE_REPOSITORY_PATH=$ONE_LOCATION/var/images
|
||||
VAR_LOCATION=$ONE_LOCATION/var/
|
||||
ETC_LOCATION=$ONE_LOCATION/etc/
|
||||
fi
|
||||
fi
|
||||
|
||||
RESTRICTED_DIRS="$VAR_LOCATION $ETC_LOCATION $HOME/ $RESTRICTED_DIRS"
|
||||
CONF_FILE=$ETC_LOCATION/datastore/fs.conf
|
||||
|
||||
export IMAGE_REPOSITORY_PATH
|
||||
export RESTRICTED_DIRS
|
||||
export SAFE_DIRS
|
||||
source $CONF_FILE
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Function used to generate Image names, you should not need to override this
|
||||
#------------------------------------------------------------------------------
|
||||
#
|
||||
# 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)
|
||||
#
|
||||
RESTRICTED_DIRS="$VAR_LOCATION $ETC_LOCATION $HOME/ $RESTRICTED_DIRS"
|
||||
|
||||
export BASE_PATH
|
||||
export RESTRICTED_DIRS
|
||||
export SAFE_DIRS
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Generates an unique image path. Requires BASE_PATH to be set
|
||||
# @return path for the image (empty if error)
|
||||
#-------------------------------------------------------------------------------
|
||||
function generate_image_path {
|
||||
|
||||
CANONICAL_STR="`$DATE +%s`:$ID"
|
||||
CANONICAL_STR="`$DATE +%s`:$ID"
|
||||
|
||||
CANONICAL_MD5=$($MD5SUM - << EOF
|
||||
CANONICAL_MD5=$($MD5SUM - << EOF
|
||||
$CANONICAL_STR
|
||||
EOF
|
||||
)
|
||||
|
||||
echo "$IMAGE_REPOSITORY_PATH/`echo $CANONICAL_MD5 | cut -d ' ' -f1`"
|
||||
echo "${BASE_PATH}/`echo $CANONICAL_MD5 | cut -d ' ' -f1`"
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Computes the size of an image
|
||||
# @param $1 - Path to the image
|
||||
# @return size of the image in Mb
|
||||
#-------------------------------------------------------------------------------
|
||||
function fs_du {
|
||||
if [ -d "$1" ]; then
|
||||
SIZE=`du -s "$1" | cut -f1`
|
||||
@ -81,6 +102,11 @@ function fs_du {
|
||||
echo "$SIZE"
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Checks if a path is safe for copying the image from
|
||||
# @param $1 - Path to the image
|
||||
# @return 0 if the path is safe, 1 otherwise
|
||||
#-------------------------------------------------------------------------------
|
||||
function check_restricted {
|
||||
for path in $SAFE_DIRS ; do
|
||||
if [ -n "`readlink -f $1 | grep -E "^$path"`" ] ; then
|
@ -411,8 +411,7 @@ int ImageManager::register_image(int iid, const string& ds_data)
|
||||
}
|
||||
|
||||
drv_msg = format_message(img->to_xml(img_tmpl), ds_data);
|
||||
|
||||
path = img->get_path();
|
||||
path = img->get_path();
|
||||
|
||||
if ( path.empty() == true ) //NO PATH -> USE SOURCE OR MKFS FOR DATABLOCK
|
||||
{
|
||||
@ -421,7 +420,7 @@ int ImageManager::register_image(int iid, const string& ds_data)
|
||||
string fs = img->get_fstype();
|
||||
int size = img->get_size();
|
||||
|
||||
imd->mkfs(img->get_oid(), fs, size);
|
||||
imd->mkfs(img->get_oid(), *drv_msg);
|
||||
|
||||
oss << "Creating disk at " << img->get_source() << " of "
|
||||
<< size << "Mb with format " << fs;
|
||||
|
@ -52,12 +52,12 @@ void ImageManagerDriver::mv(int oid,
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void ImageManagerDriver::mkfs(int oid,
|
||||
const string& fs,
|
||||
int size_mb) const
|
||||
const string& drv_msg) const
|
||||
{
|
||||
ostringstream os;
|
||||
|
||||
os << "MKFS " << oid << " " << fs << " " << size_mb << endl;
|
||||
os << "MKFS " << oid << " " << drv_msg << endl;
|
||||
|
||||
write(os);
|
||||
}
|
||||
|
||||
|
@ -561,7 +561,7 @@ void Nebula::start()
|
||||
{
|
||||
vector<const Attribute *> image_mads;
|
||||
|
||||
nebula_configuration->get("IMAGE_MAD", image_mads);
|
||||
nebula_configuration->get("DATASTORE_MAD", image_mads);
|
||||
|
||||
imagem = new ImageManager(ipool,image_mads);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user