Skip to content

Commit

Permalink
F OpenNebula#3244: Better mixed modes ceph/clone.ssh
Browse files Browse the repository at this point in the history
  • Loading branch information
xorel committed Jul 23, 2019
1 parent ed9d64c commit 27e7bee
Show file tree
Hide file tree
Showing 15 changed files with 523 additions and 204 deletions.
4 changes: 2 additions & 2 deletions include/VirtualMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -2035,11 +2035,11 @@ class VirtualMachine : public PoolObjectSQL
* netowrking updates.
* @param context attribute of the VM
* @param error string if any
* @param only_auto boolean to generate context only for vnets
* @param only_auto boolean to generate context only for vnets
* with NETWORK_MODE = auto
* @return 0 on success
*/
int generate_network_context(VectorAttribute * context, string& error,
int generate_network_context(VectorAttribute * context, string& error,
bool only_auto);

/**
Expand Down
2 changes: 1 addition & 1 deletion include/VirtualMachineDisk.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class VirtualMachineDisk : public VirtualMachineAttribute
/**
* Return the TM_MAD_SYSTEM attribute
*/
std::string get_tm_mad_system();
std::string get_tm_mad_system() const;

/* ---------------------------------------------------------------------- */
/* Image Manager Interface */
Expand Down
39 changes: 34 additions & 5 deletions src/tm/TransferManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -423,14 +423,18 @@ int TransferManager::prolog_transfer_command(
// <CLONE|LN> tm_mad fe:SOURCE host:remote_system_ds/disk.i vmid dsid
if (clon == "YES")
{
xfr << "CLONE ";
xfr << "CLONE";
}
else
{
xfr << "LN ";
xfr << "LN";
}

xfr << tm_mad << " ";
std::string tsys = disk->get_tm_mad_system();

xfr << "." << tsys;

xfr << " " << tm_mad << " ";

if ( source.find(":") == string::npos ) //Regular file
{
Expand Down Expand Up @@ -1121,7 +1125,14 @@ void TransferManager::epilog_transfer_command(
return;
}

//MVDS tm_mad hostname:remote_system_dir/disk.0 <fe:SOURCE|SOURCE> vmid dsid

string tsys = disk->vector_value("TM_MAD_SYSTEM");
if (!tsys.empty())
{
tm_mad = tm_mad + "." + tsys;
}

//MVDS tm_mad.(tm_mad_system) hostname:remote_system_dir/disk.0 <fe:SOURCE|SOURCE> vmid dsid
xfr << "MVDS "
<< tm_mad << " "
<< host << ":" << vm->get_system_dir() << "/disk." << disk_id << " "
Expand All @@ -1148,6 +1159,12 @@ void TransferManager::epilog_transfer_command(
vv_rc = disk->vector_value("DATASTORE_ID", ds_id_i);
}

string tsys = disk->vector_value("TM_MAD_SYSTEM");
if (!tsys.empty())
{
tm_mad = tm_mad + "." + tsys;
}

if ( !tm_mad.empty() && vv_rc == 0)
{
//DELETE tm_mad hostname:remote_system_dir/disk.i vmid ds_id
Expand Down Expand Up @@ -1487,7 +1504,13 @@ int TransferManager::epilog_delete_commands(VirtualMachine *vm,
}
}

//DELETE tm_mad host:remote_system_dir/disk.i vmid dsid(image)
string tsys = (*disk)->vector_value("TM_MAD_SYSTEM");
if (!tsys.empty())
{
tm_mad = tm_mad + "." + tsys;
}

//DELETE tm_mad(.tm_mad_system) host:remote_system_dir/disk.i vmid dsid(image)
// *local* DELETE tm_mad fe:system_dir/disk.i vmid dsid(image)
// *prev* DELETE tm_mad prev_host:remote_system_dir/disk.i vmid ds_id(image)
xfr << "DELETE "
Expand Down Expand Up @@ -2154,6 +2177,12 @@ void TransferManager::resize_command(VirtualMachine * vm,
ds_id = disk->vector_value("DATASTORE_ID");
}

string tsys = disk->vector_value("TM_MAD_SYSTEM");
if (!tsys.empty())
{
tm_mad = tm_mad + "." + tsys;
}

//RESIZE tm_mad host:remote_system_dir/disk.i size vmid dsid
xfr << "RESIZE "
<< tm_mad << " "
Expand Down
53 changes: 14 additions & 39 deletions src/tm_mad/ceph/clone
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,13 @@ done < <(onevm show -x $VM_ID| $XPATH \
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/CEPH_KEY \
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/CEPH_CONF \
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/SIZE \
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/ORIGINAL_SIZE \
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/TYPE )
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/ORIGINAL_SIZE )
CEPH_USER="${XPATH_ELEMENTS[j++]}"
CEPH_KEY="${XPATH_ELEMENTS[j++]}"
CEPH_CONF="${XPATH_ELEMENTS[j++]}"
SIZE="${XPATH_ELEMENTS[j++]}"
ORIGINAL_SIZE="${XPATH_ELEMENTS[j++]}"
TYPE="${XPATH_ELEMENTS[j++]}"
#-------------------------------------------------------------------------------
# Get Datastore information
Expand Down Expand Up @@ -117,49 +115,26 @@ if [ -n "$EC_POOL_NAME" ]; then
EC_POOL_OPT="--data-pool ${EC_POOL_NAME}"
fi
if [ "${TYPE}" = 'FILE' ]; then
ssh_make_path $DST_HOST $DST_DIR 'ssh'
CLONE_CMD=$(cat <<EOF
RBD="${RBD}"
CLONE_CMD=$(cat <<EOF
RBD="${RBD}"
$RBD info $RBD_DST >/dev/null 2>&1 && exit 0
rbd_make_snap $SRC_PATH
rbd_make_snap $SRC_PATH
set -e -o pipefail
set -e -o pipefail
if [ "\$(rbd_format $SRC_PATH)" = "2" ]; then
$RBD export "$SRC_PATH@snap" $DST_PATH
else
$RBD export $SRC_PATH $DST_PATH
fi
if [ "\$(rbd_format $SRC_PATH)" = "2" ]; then
$RBD ${EC_POOL_OPT} clone "$SRC_PATH@snap" $RBD_DST
else
$RBD copy $SRC_PATH $RBD_DST
fi
if [ -n "$ORIGINAL_SIZE" -a "$SIZE" -gt "$ORIGINAL_SIZE" ]; then
qemu-img resize ${DST_PATH} ${SIZE}M
fi
if [ -n "$ORIGINAL_SIZE" -a "$SIZE" -gt "$ORIGINAL_SIZE" ]; then
$RBD resize $RBD_DST --size $SIZE
fi
EOF
)
else
CLONE_CMD=$(cat <<EOF
RBD="${RBD}"
$RBD info $RBD_DST >/dev/null 2>&1 && exit 0
rbd_make_snap $SRC_PATH
set -e -o pipefail
if [ "\$(rbd_format $SRC_PATH)" = "2" ]; then
$RBD ${EC_POOL_OPT} clone "$SRC_PATH@snap" $RBD_DST
else
$RBD copy $SRC_PATH $RBD_DST
fi
if [ -n "$ORIGINAL_SIZE" -a "$SIZE" -gt "$ORIGINAL_SIZE" ]; then
$RBD resize $RBD_DST --size $SIZE
fi
EOF
)
fi
ssh_exec_and_log_stdin "$DST_HOST" "$CLONE_CMD" "$CEPH_UTILS" \
"Error cloning $SRC_PATH to $RBD_DST in $DST_HOST"
Expand Down
124 changes: 124 additions & 0 deletions src/tm_mad/ceph/clone.ssh
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#!/bin/bash

# -------------------------------------------------------------------------- #
# Copyright 2002-2019, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #

# clone.ssh 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
VM_ID=$3
DS_ID=$4

#--------------------------------------------------------------------------------

if [ -z "${ONE_LOCATION}" ]; then
TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
LIB_LOCATION=/usr/lib/one
else
TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
LIB_LOCATION=$ONE_LOCATION/lib
fi

DRIVER_PATH=$(dirname $0)

source $TMCOMMON
source ${DRIVER_PATH}/../../etc/datastore/ceph/ceph.conf

CEPH_UTILS=${DRIVER_PATH}/../../datastore/ceph/ceph_utils.sh

#-------------------------------------------------------------------------------
# Compute the destination image name
#-------------------------------------------------------------------------------

DST_HOST=`arg_host $DST`

SRC_PATH=`arg_path $SRC`
DST_PATH=`arg_path $DST`

DST_DIR=`dirname $DST_PATH`

DISK_ID=$(echo $DST|awk -F. '{print $NF}')
RBD_DST="${SRC_PATH}-${VM_ID}-${DISK_ID}"

#-------------------------------------------------------------------------------
# Get Image information
#-------------------------------------------------------------------------------

XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin"

unset i j XPATH_ELEMENTS

while IFS= read -r -d '' element; do
XPATH_ELEMENTS[i++]="$element"
done < <(onevm show -x $VM_ID| $XPATH \
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/CEPH_USER \
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/CEPH_KEY \
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/CEPH_CONF \
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/SIZE \
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/ORIGINAL_SIZE)

CEPH_USER="${XPATH_ELEMENTS[j++]}"
CEPH_KEY="${XPATH_ELEMENTS[j++]}"
CEPH_CONF="${XPATH_ELEMENTS[j++]}"
SIZE="${XPATH_ELEMENTS[j++]}"
ORIGINAL_SIZE="${XPATH_ELEMENTS[j++]}"

#-------------------------------------------------------------------------------
# Create @snap and export it
#-------------------------------------------------------------------------------

if [ -n "$CEPH_USER" ]; then
RBD="$RBD --id ${CEPH_USER}"
fi

if [ -n "$CEPH_KEY" ]; then
RBD="$RBD --keyfile ${CEPH_KEY}"
fi

if [ -n "$CEPH_CONF" ]; then
RBD="$RBD --conf ${CEPH_CONF}"
fi


ssh_make_path $DST_HOST $DST_DIR 'ssh'

CLONE_CMD=$(cat <<EOF
RBD="${RBD}"
rbd_make_snap $SRC_PATH
set -e -o pipefail
if [ "\$(rbd_format $SRC_PATH)" = "2" ]; then
$RBD export "$SRC_PATH@snap" $DST_PATH
else
$RBD export $SRC_PATH $DST_PATH
fi
if [ -n "$ORIGINAL_SIZE" -a "$SIZE" -gt "$ORIGINAL_SIZE" ]; then
qemu-img resize ${DST_PATH} ${SIZE}M
fi
EOF
)

ssh_exec_and_log_stdin "$DST_HOST" "$CLONE_CMD" "$CEPH_UTILS" \
"Error cloning $SRC_PATH to $RBD_DST in $DST_HOST"
exit 0
26 changes: 10 additions & 16 deletions src/tm_mad/ceph/delete
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,14 @@ done < <(onevm show -x $VM_ID | $XPATH \
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/CEPH_USER \
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/CEPH_KEY \
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/CEPH_CONF \
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/POOL_NAME \
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/TYPE )
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/POOL_NAME)

SRC="${XPATH_ELEMENTS[j++]}"
CLONE="${XPATH_ELEMENTS[j++]}"
CEPH_USER="${XPATH_ELEMENTS[j++]}"
CEPH_KEY="${XPATH_ELEMENTS[j++]}"
CEPH_CONF="${XPATH_ELEMENTS[j++]}"
POOL_NAME="${XPATH_ELEMENTS[j++]:-$POOL_NAME}"
TYPE="${XPATH_ELEMENTS[j++]}"

# No need to delete no cloned images
if [ "$CLONE" = "NO" ]; then
Expand Down Expand Up @@ -159,24 +157,20 @@ fi

log "Deleting $DST_PATH"

if [ "${TYPE}" = 'FILE' ]; then
exit 0
else
DELETE_CMD=$(cat <<EOF
RBD="${RBD}"
DELETE_CMD=$(cat <<EOF
RBD="${RBD}"
if [ "\$(rbd_format $RBD_SRC)" = "2" ]; then
rbd_rm_r \$(rbd_top_parent $RBD_SRC)
if [ "\$(rbd_format $RBD_SRC)" = "2" ]; then
rbd_rm_r \$(rbd_top_parent $RBD_SRC)
if [ -n "$RBD_SNAP" ]; then
rbd_rm_snap $SRC $RBD_SNAP
fi
else
$RBD rm $RBD_SRC
if [ -n "$RBD_SNAP" ]; then
rbd_rm_snap $SRC $RBD_SNAP
fi
else
$RBD rm $RBD_SRC
fi
EOF
)
fi

ssh_exec_and_log_stdin "$DST_HOST" "$DELETE_CMD" "$CEPH_UTILS" \
"Error deleting $RBD_SRC in $DST_HOST"
20 changes: 20 additions & 0 deletions src/tm_mad/ceph/delete.ssh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

# -------------------------------------------------------------------------- #
# Copyright 2002-2019, OpenNebula Project, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #

# Nothing to do
exit 0
Loading

0 comments on commit 27e7bee

Please sign in to comment.