Implement OpenNebula driver
This commit is contained in:
Vendored
+6
@@ -53,3 +53,9 @@ Architecture: amd64
|
||||
Depends: ${shlibs:Depends}, ${misc:Depends}, vitastor-client (= ${binary:Version})
|
||||
Description: Vitastor Proxmox Virtual Environment storage plugin
|
||||
Vitastor storage plugin for Proxmox Virtual Environment.
|
||||
|
||||
Package: opennebula-vitastor
|
||||
Architecture: amd64
|
||||
Depends: ${shlibs:Depends}, ${misc:Depends}, vitastor-client, patch, python3, jq
|
||||
Description: Vitastor OpenNebula storage plugin
|
||||
Vitastor storage plugin for OpenNebula.
|
||||
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
opennebula/remotes var/lib/one/
|
||||
opennebula/sudoers.d etc/
|
||||
opennebula/install.sh var/lib/one/remotes/datastore/vitastor/
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
if [ "$1" = "configure" ]; then
|
||||
/var/lib/one/remotes/datastore/vitastor/install.sh
|
||||
fi
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
interest /var/lib/one/remotes/datastore/downloader.sh
|
||||
interest /etc/one/oned.conf
|
||||
interest /etc/one/vmm_exec/vmm_execrc
|
||||
interest /etc/apparmor.d/local/abstractions/libvirt-qemu
|
||||
Executable
+20
@@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
reapply_patch() {
|
||||
if ! patch -f --dry-run -l -R $1 < $2 >/dev/null; then
|
||||
if ! patch -l -f $1 < $2; then
|
||||
echo "ERROR: Failed to patch file $1, please apply the patch $2 manually"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
echo "Reapplying Vitastor patches to OpenNebula's oned.conf, vmm_execrc and downloader.sh"
|
||||
reapply_patch /var/lib/one/remotes/datastore/downloader.sh /var/lib/one/remotes/datastore/vitastor/downloader-vitastor.sh.diff
|
||||
reapply_patch /etc/one/oned.conf /var/lib/one/remotes/datastore/vitastor/oned.conf.diff
|
||||
reapply_patch /etc/one/vmm_exec/vmm_execrc /var/lib/one/remotes/datastore/vitastor/vmm_execrc.diff
|
||||
if [ -f /etc/apparmor.d/local/abstractions/libvirt-qemu ]; then
|
||||
if ! grep -q /etc/vitastor/vitastor.conf /etc/apparmor.d/local/abstractions/libvirt-qemu; then
|
||||
echo ' "/etc/vitastor/vitastor.conf" r,' >> /etc/apparmor.d/local/abstractions/libvirt-qemu
|
||||
fi
|
||||
fi
|
||||
Executable
+77
@@ -0,0 +1,77 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Vitastor OpenNebula driver
|
||||
# Copyright (c) Vitaliy Filippov, 2024+
|
||||
# License: Apache-2.0 http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
# This script is used to copy a VM image (SRC) to the image repository as DST
|
||||
|
||||
# -------- Set up the environment to source common tools & conf ------------
|
||||
if [ -z "${ONE_LOCATION}" ]; then
|
||||
LIB_LOCATION=/usr/lib/one
|
||||
else
|
||||
LIB_LOCATION=$ONE_LOCATION/lib
|
||||
fi
|
||||
|
||||
. $LIB_LOCATION/sh/scripts_common.sh
|
||||
|
||||
DRIVER_PATH=$(dirname $0)
|
||||
source ${DRIVER_PATH}/../libfs.sh
|
||||
|
||||
# -------- Get cp and datastore arguments from OpenNebula core ------------
|
||||
|
||||
DRV_ACTION=`cat -`
|
||||
ID=$1
|
||||
|
||||
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/DATASTORE/BASE_PATH \
|
||||
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/BRIDGE_LIST \
|
||||
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/POOL_NAME \
|
||||
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/IMAGE_PREFIX \
|
||||
/DS_DRIVER_ACTION_DATA/IMAGE/PATH \
|
||||
/DS_DRIVER_ACTION_DATA/IMAGE/SIZE \
|
||||
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/VITASTOR_CONF)
|
||||
|
||||
unset i
|
||||
|
||||
BASE_PATH="${XPATH_ELEMENTS[i++]}"
|
||||
BRIDGE_LIST="${XPATH_ELEMENTS[i++]}"
|
||||
POOL_NAME="${XPATH_ELEMENTS[i++]}"
|
||||
IMAGE_PREFIX="${XPATH_ELEMENTS[i++]}"
|
||||
SRC="${XPATH_ELEMENTS[i++]}"
|
||||
SIZE="${XPATH_ELEMENTS[i++]}"
|
||||
VITASTOR_CONF="${XPATH_ELEMENTS[i++]}"
|
||||
|
||||
DST_HOST=`get_destination_host $ID`
|
||||
|
||||
if [ -z "$DST_HOST" ]; then
|
||||
error_message "Datastore template missing 'BRIDGE_LIST' attribute."
|
||||
exit -1
|
||||
fi
|
||||
|
||||
CLI=vitastor-cli
|
||||
if [ -n "$VITASTOR_CONF" ]; then
|
||||
CLI="$CLI --config_path ${VITASTOR_CONF}"
|
||||
fi
|
||||
if [ -n "$POOL_NAME" ]; then
|
||||
CLI="$CLI --pool ${POOL_NAME}"
|
||||
fi
|
||||
|
||||
SAFE_DIRS=""
|
||||
|
||||
DST="${IMAGE_PREFIX}one-${ID}"
|
||||
|
||||
ssh_exec_and_log "$DST_HOST" "$CLI create --parent $SRC $DST" \
|
||||
"Error during $CLI create --parent $SRC $DST in $DST_HOST"
|
||||
|
||||
# FIXME: Is it really required?
|
||||
ssh_exec_and_log "$DST_HOST" "$CLI flatten $DST" \
|
||||
"Error during $CLI create flatten $DST in $DST_HOST"
|
||||
|
||||
echo "$DST raw"
|
||||
Executable
+135
@@ -0,0 +1,135 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Vitastor OpenNebula driver
|
||||
# Copyright (c) Vitaliy Filippov, 2024+
|
||||
# License: Apache-2.0 http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
# This script is used to copy a local image SRC to the image repository as DST
|
||||
|
||||
# -------- Set up the environment to source common tools & conf ------------
|
||||
|
||||
if [ -z "${ONE_LOCATION}" ]; then
|
||||
LIB_LOCATION=/usr/lib/one
|
||||
else
|
||||
LIB_LOCATION=$ONE_LOCATION/lib
|
||||
fi
|
||||
|
||||
. $LIB_LOCATION/sh/scripts_common.sh
|
||||
|
||||
DRIVER_PATH=$(dirname $0)
|
||||
source ${DRIVER_PATH}/../libfs.sh
|
||||
|
||||
# -------- Get cp and datastore arguments from OpenNebula core ------------
|
||||
|
||||
DRV_ACTION=`cat -`
|
||||
ID=$1
|
||||
|
||||
export DRV_ACTION
|
||||
|
||||
UTILS_PATH="${DRIVER_PATH}/.."
|
||||
|
||||
XPATH="$UTILS_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/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/BRIDGE_LIST \
|
||||
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/POOL_NAME \
|
||||
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/IMAGE_PREFIX \
|
||||
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/STAGING_DIR \
|
||||
/DS_DRIVER_ACTION_DATA/IMAGE/PATH \
|
||||
/DS_DRIVER_ACTION_DATA/IMAGE/SIZE \
|
||||
/DS_DRIVER_ACTION_DATA/IMAGE/TEMPLATE/MD5 \
|
||||
/DS_DRIVER_ACTION_DATA/IMAGE/TEMPLATE/SHA1 \
|
||||
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/NO_DECOMPRESS \
|
||||
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/LIMIT_TRANSFER_BW \
|
||||
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/VITASTOR_CONF)
|
||||
|
||||
unset i
|
||||
|
||||
BASE_PATH="${XPATH_ELEMENTS[i++]}"
|
||||
RESTRICTED_DIRS="${XPATH_ELEMENTS[i++]}"
|
||||
SAFE_DIRS="${XPATH_ELEMENTS[i++]}"
|
||||
BRIDGE_LIST="${XPATH_ELEMENTS[i++]}"
|
||||
POOL_NAME="${XPATH_ELEMENTS[i++]}"
|
||||
IMAGE_PREFIX="${XPATH_ELEMENTS[i++]}"
|
||||
STAGING_DIR="${XPATH_ELEMENTS[i++]:-$STAGING_DIR}"
|
||||
SRC="${XPATH_ELEMENTS[i++]}"
|
||||
SIZE="${XPATH_ELEMENTS[i++]}"
|
||||
MD5="${XPATH_ELEMENTS[i++]}"
|
||||
SHA1="${XPATH_ELEMENTS[i++]}"
|
||||
NO_DECOMPRESS="${XPATH_ELEMENTS[i++]}"
|
||||
LIMIT_TRANSFER_BW="${XPATH_ELEMENTS[i++]}"
|
||||
VITASTOR_CONF="${XPATH_ELEMENTS[i++]}"
|
||||
|
||||
DST_HOST=`get_destination_host $ID`
|
||||
|
||||
if [ -z "$DST_HOST" ]; then
|
||||
error_message "Datastore template missing 'BRIDGE_LIST' attribute."
|
||||
exit -1
|
||||
fi
|
||||
|
||||
CLI=vitastor-cli
|
||||
QEMU_ARG=""
|
||||
if [ -n "$VITASTOR_CONF" ]; then
|
||||
CLI="$CLI --config_path ${VITASTOR_CONF}"
|
||||
QEMU_ARG=":config_path=${VITASTOR_CONF}"
|
||||
fi
|
||||
if [ -n "$POOL_NAME" ]; then
|
||||
CLI="$CLI --pool ${POOL_NAME}"
|
||||
fi
|
||||
|
||||
set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS"
|
||||
|
||||
IMAGE_HASH=`generate_image_hash`
|
||||
TMP_DST="$STAGING_DIR/$IMAGE_HASH"
|
||||
|
||||
DST="${IMAGE_PREFIX}one-${ID}"
|
||||
|
||||
DOWNLOADER_ARGS=`set_downloader_args "$MD5" "$SHA1" "$NO_DECOMPRESS" "$LIMIT_TRANSFER_BW" "$SRC" -`
|
||||
|
||||
COPY_COMMAND="$UTILS_PATH/downloader.sh $DOWNLOADER_ARGS"
|
||||
|
||||
case $SRC in
|
||||
http://*|https://*)
|
||||
log "Downloading $SRC to the image repository"
|
||||
|
||||
DUMP="$COPY_COMMAND"
|
||||
;;
|
||||
|
||||
*)
|
||||
if [ `check_restricted $SRC` -eq 1 ]; then
|
||||
log_error "Not allowed to copy images from $RESTRICTED_DIRS"
|
||||
error_message "Not allowed to copy image file $SRC"
|
||||
exit -1
|
||||
fi
|
||||
|
||||
log "Copying local image $SRC to the image repository"
|
||||
|
||||
DUMP="$COPY_COMMAND"
|
||||
;;
|
||||
esac
|
||||
|
||||
multiline_exec_and_log "set -e -o pipefail; $DUMP | $SSH $DST_HOST $DD of=$TMP_DST bs=1M" \
|
||||
"Error copying $SRC to $DST_HOST:$TMP_DST"
|
||||
|
||||
REGISTER_CMD=$(cat <<EOF
|
||||
set -e -o pipefail
|
||||
|
||||
SIZE=\$($QEMU_IMG info --output json "$TMP_DST" | jq -r '.["virtual-size"]')
|
||||
$CLI create -s \$SIZE "$DST"
|
||||
$QEMU_IMG convert -O raw "$TMP_DST" "vitastor:image=$DST$QEMU_ARG"
|
||||
|
||||
# remove original
|
||||
$RM -f $TMP_DST
|
||||
EOF
|
||||
)
|
||||
|
||||
ssh_exec_and_log "$DST_HOST" "$REGISTER_CMD" "Error registering $DST in $DST_HOST"
|
||||
|
||||
echo "$DST raw"
|
||||
+555
@@ -0,0 +1,555 @@
|
||||
#!/bin/bash
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2023, 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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
if [ -z "${ONE_LOCATION}" ]; then
|
||||
LIB_LOCATION=/usr/lib/one
|
||||
VAR_LOCATION=/var/lib/one
|
||||
else
|
||||
LIB_LOCATION=$ONE_LOCATION/lib
|
||||
VAR_LOCATION=$ONE_LOCATION/var
|
||||
fi
|
||||
|
||||
. $LIB_LOCATION/sh/scripts_common.sh
|
||||
|
||||
DRIVER_PATH=$(dirname $0)
|
||||
|
||||
# Escape single quotes
|
||||
function esc_sq
|
||||
{
|
||||
echo "$1" | sed -e "s/'/'\\\''/g"
|
||||
}
|
||||
|
||||
# Execute a command (first parameter) and use the first kb of stdout
|
||||
# to determine the file type
|
||||
function get_type
|
||||
{
|
||||
if [ "$NO_DECOMPRESS" = "yes" ]; then
|
||||
echo "application/octet-stream"
|
||||
else
|
||||
command=$1
|
||||
|
||||
( eval "$command" | head -n 1024 | file -b --mime-type - ) 2>/dev/null
|
||||
fi
|
||||
}
|
||||
|
||||
# Gets the command needed to decompress an stream.
|
||||
function get_decompressor
|
||||
{
|
||||
type=$1
|
||||
|
||||
case "$type" in
|
||||
"application/x-gzip"|"application/gzip")
|
||||
echo "gunzip -c -"
|
||||
;;
|
||||
"application/x-bzip2")
|
||||
echo "bunzip2 -qc -"
|
||||
;;
|
||||
"application/x-xz")
|
||||
echo "unxz -c -"
|
||||
;;
|
||||
*)
|
||||
echo "cat"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Function called to decompress a stream. The first parameter is the command
|
||||
# used to decompress the stream. Second parameter is the output file or
|
||||
# - for stdout.
|
||||
function decompress
|
||||
{
|
||||
command="$1"
|
||||
to="$2"
|
||||
|
||||
if [ "$to" = "-" ]; then
|
||||
$command
|
||||
else
|
||||
$command > "$to"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function called to hash a stream. First parameter is the algorithm name.
|
||||
function hasher
|
||||
{
|
||||
if [ -n "$1" ]; then
|
||||
openssl dgst -$1 | awk '{print $NF}' > $HASH_FILE
|
||||
else
|
||||
# Needs something consuming stdin or the pipe will break
|
||||
cat >/dev/null
|
||||
fi
|
||||
}
|
||||
|
||||
# Unarchives a tar or a zip a file to a directory with the same name.
|
||||
function unarchive
|
||||
{
|
||||
TO="$1"
|
||||
|
||||
file_type=$(get_type "cat $TO")
|
||||
|
||||
tmp="$TO"
|
||||
|
||||
# Add full path if it is relative
|
||||
if [ ${tmp:0:1} != "/" ]; then
|
||||
tmp="$PWD/$tmp"
|
||||
fi
|
||||
|
||||
IN="$tmp.tmp"
|
||||
OUT="$tmp"
|
||||
|
||||
case "$file_type" in
|
||||
"application/x-tar")
|
||||
command="tar -xf $IN -C $OUT"
|
||||
;;
|
||||
"application/zip")
|
||||
command="unzip -d $OUT $IN"
|
||||
;;
|
||||
*)
|
||||
command=""
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -n "$command" ]; then
|
||||
mv "$OUT" "$IN"
|
||||
mkdir "$OUT"
|
||||
|
||||
$command
|
||||
|
||||
if [ "$?" != "0" ]; then
|
||||
echo "Error uncompressing archive" >&2
|
||||
exit -1
|
||||
fi
|
||||
|
||||
rm "$IN"
|
||||
fi
|
||||
}
|
||||
|
||||
function s3_env
|
||||
{
|
||||
XPATH="$DRIVER_PATH/xpath.rb -b $DRV_ACTION"
|
||||
|
||||
unset i j XPATH_ELEMENTS
|
||||
|
||||
while IFS= read -r -d '' element; do
|
||||
XPATH_ELEMENTS[i++]="$element"
|
||||
done < <($XPATH /DS_DRIVER_ACTION_DATA/MARKETPLACE/TEMPLATE/ACCESS_KEY_ID \
|
||||
/DS_DRIVER_ACTION_DATA/MARKETPLACE/TEMPLATE/SECRET_ACCESS_KEY \
|
||||
/DS_DRIVER_ACTION_DATA/MARKETPLACE/TEMPLATE/REGION \
|
||||
/DS_DRIVER_ACTION_DATA/MARKETPLACE/TEMPLATE/AWS \
|
||||
/DS_DRIVER_ACTION_DATA/MARKETPLACE/TEMPLATE/ENDPOINT)
|
||||
|
||||
S3_ACCESS_KEY_ID="${XPATH_ELEMENTS[j++]}"
|
||||
S3_SECRET_ACCESS_KEY="${XPATH_ELEMENTS[j++]}"
|
||||
S3_REGION="${XPATH_ELEMENTS[j++]}"
|
||||
S3_AWS="${XPATH_ELEMENTS[j++]}"
|
||||
S3_ENDPOINT="${XPATH_ELEMENTS[j++]}"
|
||||
|
||||
CURRENT_DATE_DAY="$(date -u '+%Y%m%d')"
|
||||
CURRENT_DATE_ISO8601="${CURRENT_DATE_DAY}T$(date -u '+%H%M%S')Z"
|
||||
}
|
||||
|
||||
# Create an SHA-256 hash in hexadecimal.
|
||||
# Usage:
|
||||
# hash_sha256 <string>
|
||||
function hash_sha256 {
|
||||
printf "${1}" | openssl dgst -sha256 | sed 's/^.* //'
|
||||
}
|
||||
|
||||
# Create an SHA-256 hmac in hexadecimal.
|
||||
# Usage:
|
||||
# hmac_sha256 <key> <data>
|
||||
function hmac_sha256 {
|
||||
printf "${2}" | openssl dgst -sha256 -mac HMAC -macopt "${1}" | sed 's/^.* //'
|
||||
}
|
||||
|
||||
# Create the signature.
|
||||
# Usage:
|
||||
# create_signature
|
||||
function create_signature {
|
||||
stringToSign="AWS4-HMAC-SHA256\n${CURRENT_DATE_ISO8601}\n${CURRENT_DATE_DAY}/${S3_REGION}/s3/aws4_request\n$(hash_sha256 "${HTTP_CANONICAL_REQUEST}")"
|
||||
dateKey=$(hmac_sha256 key:"AWS4${S3_SECRET_ACCESS_KEY}" "${CURRENT_DATE_DAY}")
|
||||
regionKey=$(hmac_sha256 hexkey:"${dateKey}" "${S3_REGION}")
|
||||
serviceKey=$(hmac_sha256 hexkey:"${regionKey}" "s3")
|
||||
signingKey=$(hmac_sha256 hexkey:"${serviceKey}" "aws4_request")
|
||||
|
||||
printf "${stringToSign}" | openssl dgst -sha256 -mac HMAC -macopt hexkey:"${signingKey}" | sed 's/.*(stdin)= //'
|
||||
}
|
||||
|
||||
function s3_curl_args
|
||||
{
|
||||
FROM="$1"
|
||||
|
||||
ENDPOINT="$S3_ENDPOINT"
|
||||
OBJECT=$(basename "$FROM")
|
||||
BUCKET=$(basename $(dirname "$FROM"))
|
||||
|
||||
DATE="`date -u +'%a, %d %b %Y %H:%M:%S GMT'`"
|
||||
AUTH_STRING="GET\n\n\n${DATE}\n/${BUCKET}/${OBJECT}"
|
||||
|
||||
SIGNED_AUTH_STRING=`echo -en "$AUTH_STRING" | \
|
||||
openssl sha1 -hmac ${S3_SECRET_ACCESS_KEY} -binary | \
|
||||
base64`
|
||||
|
||||
echo " -H \"Date: ${DATE}\"" \
|
||||
" -H \"Authorization: AWS ${S3_ACCESS_KEY_ID}:${SIGNED_AUTH_STRING}\"" \
|
||||
" '$(esc_sq "${ENDPOINT}/${BUCKET}/${OBJECT}")'"
|
||||
}
|
||||
|
||||
function s3_curl_args_aws
|
||||
{
|
||||
FROM="$1"
|
||||
|
||||
OBJECT=$(basename "$FROM")
|
||||
BUCKET=$(basename "$(dirname "$FROM")")
|
||||
|
||||
ENDPOINT="$BUCKET.s3.amazonaws.com"
|
||||
|
||||
AWS_S3_PATH="$(echo $OBJECT | sed 's;^\([^/]\);/\1;')"
|
||||
|
||||
HTTP_REQUEST_PAYLOAD_HASH="$(echo "" | openssl dgst -sha256 | sed 's/^.* //')"
|
||||
HTTP_CANONICAL_REQUEST_URI="${AWS_S3_PATH}"
|
||||
HTTP_REQUEST_CONTENT_TYPE='application/octet-stream'
|
||||
|
||||
HTTP_CANONICAL_REQUEST_HEADERS="content-type:${HTTP_REQUEST_CONTENT_TYPE}
|
||||
host:${ENDPOINT}
|
||||
x-amz-content-sha256:${HTTP_REQUEST_PAYLOAD_HASH}
|
||||
x-amz-date:${CURRENT_DATE_ISO8601}"
|
||||
|
||||
HTTP_REQUEST_SIGNED_HEADERS="content-type;host;x-amz-content-sha256;x-amz-date"
|
||||
HTTP_CANONICAL_REQUEST="GET
|
||||
${HTTP_CANONICAL_REQUEST_URI}\n
|
||||
${HTTP_CANONICAL_REQUEST_HEADERS}\n
|
||||
${HTTP_REQUEST_SIGNED_HEADERS}
|
||||
${HTTP_REQUEST_PAYLOAD_HASH}"
|
||||
|
||||
SIGNATURE="$(create_signature)"
|
||||
HTTP_REQUEST_AUTHORIZATION_HEADER="AWS4-HMAC-SHA256 Credential=${S3_ACCESS_KEY_ID}/${CURRENT_DATE_DAY}/${S3_REGION}/s3/aws4_request, SignedHeaders=${HTTP_REQUEST_SIGNED_HEADERS}, Signature=${SIGNATURE}"
|
||||
|
||||
echo " -H \"Authorization: ${HTTP_REQUEST_AUTHORIZATION_HEADER}\"" \
|
||||
" -H \"content-type: ${HTTP_REQUEST_CONTENT_TYPE}\"" \
|
||||
" -H \"x-amz-content-sha256: ${HTTP_REQUEST_PAYLOAD_HASH}\"" \
|
||||
" -H \"x-amz-date: ${CURRENT_DATE_ISO8601}\"" \
|
||||
" \"https://${ENDPOINT}${HTTP_CANONICAL_REQUEST_URI}\""
|
||||
}
|
||||
|
||||
function get_rbd_cmd
|
||||
{
|
||||
local i j URL_ELEMENTS
|
||||
|
||||
FROM="$1"
|
||||
|
||||
URL_RB="$DRIVER_PATH/url.rb"
|
||||
|
||||
while IFS= read -r -d '' element; do
|
||||
URL_ELEMENTS[i++]="$element"
|
||||
done < <($URL_RB "$FROM" \
|
||||
USER \
|
||||
HOST \
|
||||
SOURCE \
|
||||
PARAM_DS \
|
||||
PARAM_CEPH_USER \
|
||||
PARAM_CEPH_KEY \
|
||||
PARAM_CEPH_CONF)
|
||||
|
||||
USER="${URL_ELEMENTS[j++]}"
|
||||
DST_HOST="${URL_ELEMENTS[j++]}"
|
||||
SOURCE="${URL_ELEMENTS[j++]}"
|
||||
DS="${URL_ELEMENTS[j++]}"
|
||||
CEPH_USER="${URL_ELEMENTS[j++]}"
|
||||
CEPH_KEY="${URL_ELEMENTS[j++]}"
|
||||
CEPH_CONF="${URL_ELEMENTS[j++]}"
|
||||
|
||||
# Remove leading '/'
|
||||
SOURCE="${SOURCE#/}"
|
||||
|
||||
if [ -n "$USER" ]; then
|
||||
DST_HOST="$USER@$DST_HOST"
|
||||
fi
|
||||
|
||||
if [ -n "$CEPH_USER" ]; then
|
||||
RBD="$RBD --id '$(esc_sq "${CEPH_USER}")'"
|
||||
fi
|
||||
|
||||
if [ -n "$CEPH_KEY" ]; then
|
||||
RBD="$RBD --keyfile '$(esc_sq "${CEPH_KEY}")'"
|
||||
fi
|
||||
|
||||
if [ -n "$CEPH_CONF" ]; then
|
||||
RBD="$RBD --conf '$(esc_sq "${CEPH_CONF}")'"
|
||||
fi
|
||||
|
||||
echo "ssh '$(esc_sq "$DST_HOST")' \"$RBD export '$(esc_sq "$SOURCE")' -\""
|
||||
}
|
||||
|
||||
function get_vitastor_cmd
|
||||
{
|
||||
local i j URL_ELEMENTS
|
||||
|
||||
FROM="$1"
|
||||
|
||||
URL_RB="$DRIVER_PATH/url.rb"
|
||||
|
||||
while IFS= read -r -d '' element; do
|
||||
URL_ELEMENTS[i++]="$element"
|
||||
done < <($URL_RB "$FROM" \
|
||||
USER \
|
||||
HOST \
|
||||
SOURCE \
|
||||
PARAM_DS \
|
||||
PARAM_VITASTOR_CONF)
|
||||
|
||||
USER="${URL_ELEMENTS[j++]}"
|
||||
DST_HOST="${URL_ELEMENTS[j++]}"
|
||||
SOURCE="${URL_ELEMENTS[j++]}"
|
||||
DS="${URL_ELEMENTS[j++]}"
|
||||
VITASTOR_CONF="${URL_ELEMENTS[j++]}"
|
||||
|
||||
# Remove leading '/'
|
||||
SOURCE="${SOURCE#/}"
|
||||
|
||||
if [ -n "$USER" ]; then
|
||||
DST_HOST="$USER@$DST_HOST"
|
||||
fi
|
||||
|
||||
local CLI
|
||||
CLI="vitastor-cli"
|
||||
if [ -n "$VITASTOR_CONF" ]; then
|
||||
CLI="$CLI --config_path '$(esc_sq "${VITASTOR_CONF}")'"
|
||||
fi
|
||||
|
||||
echo "ssh '$(esc_sq "$DST_HOST")' \"$CLI dd iimg='$(esc_sq "$SOURCE")'\""
|
||||
}
|
||||
|
||||
# Compare 2 version strings using sort -V
|
||||
# Usage:
|
||||
# verlte "3.2.9" "3.4.0"
|
||||
function verlte() {
|
||||
[ "$1" = "`echo -e "$1\n$2" | sort -V | head -n1`" ]
|
||||
}
|
||||
|
||||
# Returns curl retry options based on its version
|
||||
function curl_retry_args {
|
||||
[ "$NO_RETRY" = "yes" ] && return
|
||||
|
||||
RETRY_ARGS="--retry 3 --retry-delay 3"
|
||||
|
||||
CURL_VER=`curl --version | grep -o 'curl [0-9\.]*' | awk '{print $2}'`
|
||||
|
||||
# To retry also on conn-reset-by-peer fresh curl is needed
|
||||
if verlte "7.71.0" "$CURL_VER" && [ -z ${MAX_SIZE} ] ; then
|
||||
RETRY_ARGS+=" --retry-all-errors"
|
||||
fi
|
||||
|
||||
echo $RETRY_ARGS
|
||||
}
|
||||
|
||||
TEMP=`getopt -o m:s:l:c:no -l md5:,sha1:,limit:,max-size:,nodecomp,noretry -- "$@"`
|
||||
|
||||
if [ $? != 0 ] ; then
|
||||
echo "Arguments error" >&2
|
||||
exit -1
|
||||
fi
|
||||
|
||||
eval set -- "$TEMP"
|
||||
|
||||
while true; do
|
||||
case "$1" in
|
||||
-m|--md5)
|
||||
HASH_TYPE=md5
|
||||
HASH=$2
|
||||
shift 2
|
||||
;;
|
||||
-s|--sha1)
|
||||
HASH_TYPE=sha1
|
||||
HASH=$2
|
||||
shift 2
|
||||
;;
|
||||
-n|--nodecomp)
|
||||
export NO_DECOMPRESS="yes"
|
||||
shift
|
||||
;;
|
||||
-l|--limit)
|
||||
export LIMIT_RATE="$2"
|
||||
shift 2
|
||||
;;
|
||||
-c|--max-size)
|
||||
export MAX_SIZE="$2"
|
||||
shift 2
|
||||
;;
|
||||
-o|--noretry)
|
||||
export NO_RETRY="yes"
|
||||
shift
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
break
|
||||
;;
|
||||
*)
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
FROM="$1"
|
||||
TO="$2"
|
||||
|
||||
if [ -n "${HASH_TYPE}" -a -n "${MAX_SIZE}" ]; then
|
||||
echo "Hash check not supported for partial downloads" >&2
|
||||
exit -1
|
||||
else
|
||||
# File used by the hasher function to store the resulting hash
|
||||
export HASH_FILE="/tmp/downloader.hash.$$"
|
||||
fi
|
||||
|
||||
GLOBAL_CURL_ARGS="--fail -sS -k -L $(curl_retry_args)"
|
||||
|
||||
case "$FROM" in
|
||||
http://*|https://*)
|
||||
# -k so it does not check the certificate
|
||||
# -L to follow redirects
|
||||
# -sS to hide output except on failure
|
||||
# --limit_rate to limit the bw
|
||||
curl_args="$GLOBAL_CURL_ARGS '$(esc_sq "${FROM}")'"
|
||||
|
||||
if [ -n "$LIMIT_RATE" ]; then
|
||||
curl_args="--limit-rate $LIMIT_RATE $curl_args"
|
||||
fi
|
||||
|
||||
command="curl $curl_args"
|
||||
;;
|
||||
ssh://*)
|
||||
# pseudo-url for ssh transfers ssh://user@host:path
|
||||
# -l to limit the bw
|
||||
ssh_src=${FROM#ssh://}
|
||||
ssh_arg=(${ssh_src/:/ })
|
||||
|
||||
rmt_cmd="\"cat '$(esc_sq "${ssh_arg[1]}")'\""
|
||||
|
||||
command="ssh ${ssh_arg[0]} $rmt_cmd"
|
||||
;;
|
||||
s3://*)
|
||||
# Read s3 environment
|
||||
s3_env
|
||||
|
||||
if [ -z "$S3_ACCESS_KEY_ID" -o -z "$S3_SECRET_ACCESS_KEY" ]; then
|
||||
echo "S3_ACCESS_KEY_ID and S3_SECRET_ACCESS_KEY are required" >&2
|
||||
exit -1
|
||||
fi
|
||||
|
||||
curl_args=""
|
||||
|
||||
if [[ "$S3_AWS" =~ (no|NO) ]]; then
|
||||
curl_args="$(s3_curl_args "$FROM")"
|
||||
else
|
||||
curl_args="$(s3_curl_args_aws "$FROM")"
|
||||
fi
|
||||
|
||||
command="curl $GLOBAL_CURL_ARGS $curl_args"
|
||||
;;
|
||||
rbd://*)
|
||||
command="$(get_rbd_cmd "$FROM")"
|
||||
;;
|
||||
vitastor://*)
|
||||
command="$(get_vitastor_cmd "$FROM")"
|
||||
;;
|
||||
vcenter://*)
|
||||
command="$VAR_LOCATION/remotes/datastore/vcenter_downloader.rb '$(esc_sq "$FROM")'"
|
||||
;;
|
||||
lxd://*)
|
||||
file_type="application/octet-stream"
|
||||
command="$VAR_LOCATION/remotes/datastore/lxd_downloader.sh \"$FROM\""
|
||||
;;
|
||||
restic://*)
|
||||
eval `$VAR_LOCATION/remotes/datastore/restic_downloader.rb "$FROM" | grep -e '^command=' -e '^clean_command='`
|
||||
;;
|
||||
rsync://*)
|
||||
eval `$VAR_LOCATION/remotes/datastore/rsync_downloader.rb "$FROM" | grep -e '^command=' -e '^clean_command='`
|
||||
;;
|
||||
*)
|
||||
if [ ! -r $FROM ]; then
|
||||
echo "Cannot read from $FROM" >&2
|
||||
exit -1
|
||||
fi
|
||||
command="cat '$(esc_sq "$FROM")'"
|
||||
;;
|
||||
esac
|
||||
|
||||
[ -z "$file_type" ] && file_type=$(get_type "$command")
|
||||
decompressor=$(get_decompressor "$file_type")
|
||||
|
||||
if [ -z "${MAX_SIZE}" ]; then
|
||||
eval "$command" | \
|
||||
tee >( hasher $HASH_TYPE) | \
|
||||
decompress "$decompressor" "$TO"
|
||||
|
||||
if [ "$?" != "0" -o "$PIPESTATUS" != "0" ]; then
|
||||
echo "Error copying" >&2
|
||||
exit -1
|
||||
fi
|
||||
else
|
||||
# Order of the 'head' command is here on purpose:
|
||||
# 1. We want to download more bytes than needed to get a requested
|
||||
# number of bytes on the output. Decompressor may need more
|
||||
# data to decompress the stream.
|
||||
# 2. Decompressor command is also misused to detect SIGPIPE error.
|
||||
eval "$command" | \
|
||||
decompress "$decompressor" "$TO" 2>/dev/null | \
|
||||
head -c "${MAX_SIZE}"
|
||||
|
||||
# Following table shows exit codes of each command
|
||||
# in the pipe for various scenarios:
|
||||
#
|
||||
# ----------------------------------------------------
|
||||
# | $COMMAND | TYPE | PIPESTATUS | BEHAVIOUR
|
||||
# ----------------------------------------------------
|
||||
# | cat | partial | 141 141 0 | OK
|
||||
# | cat | full | 0 0 0 | OK
|
||||
# | cat | error | 1 0 0 | fail
|
||||
# | curl | partial | 23 141 0 | OK
|
||||
# | curl | full | 0 0 0 | OK
|
||||
# | curl | error | 22 0 0 | fail
|
||||
# | ssh | partial | 255 141 0 | OK
|
||||
# | ssh | full | 0 0 0 | OK
|
||||
# | ssh | error ssh | 255 0 0 | fail
|
||||
# | ssh | error ssh cat | 1 0 0 | fail
|
||||
if [ \( "${PIPESTATUS[0]}" != '0' -a "${PIPESTATUS[1]}" = '0' \) \
|
||||
-o \( "${PIPESTATUS[1]}" != '0' -a "${PIPESTATUS[1]}" != '141' \) \
|
||||
-o \( "${PIPESTATUS[2]}" != "0" \) ];
|
||||
then
|
||||
echo "Error copying" >&2
|
||||
exit -1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -n "$HASH_TYPE" ]; then
|
||||
HASH_RESULT=$( cat $HASH_FILE)
|
||||
rm $HASH_FILE
|
||||
if [ "$HASH_RESULT" != "$HASH" ]; then
|
||||
echo "Hash does not match" >&2
|
||||
exit -1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Unarchive only if the destination is filesystem
|
||||
if [ "$TO" != "-" ]; then
|
||||
unarchive "$TO"
|
||||
fi
|
||||
|
||||
# Perform any clean operation
|
||||
if [ -n "${clean_command}" ]; then
|
||||
eval "$clean_command"
|
||||
fi
|
||||
@@ -0,0 +1,60 @@
|
||||
diff --git /var/lib/one/remotes/datastore/downloader.sh /var/lib/one/remotes/datastore/downloader.sh
|
||||
index 9b75d8ee4b..09d2a5d41d 100755
|
||||
--- /var/lib/one/remotes/datastore/downloader.sh
|
||||
+++ /var/lib/one/remotes/datastore/downloader.sh
|
||||
@@ -295,6 +295,45 @@ function get_rbd_cmd
|
||||
echo "ssh '$(esc_sq "$DST_HOST")' \"$RBD export '$(esc_sq "$SOURCE")' -\""
|
||||
}
|
||||
|
||||
+function get_vitastor_cmd
|
||||
+{
|
||||
+ local i j URL_ELEMENTS
|
||||
+
|
||||
+ FROM="$1"
|
||||
+
|
||||
+ URL_RB="$DRIVER_PATH/url.rb"
|
||||
+
|
||||
+ while IFS= read -r -d '' element; do
|
||||
+ URL_ELEMENTS[i++]="$element"
|
||||
+ done < <($URL_RB "$FROM" \
|
||||
+ USER \
|
||||
+ HOST \
|
||||
+ SOURCE \
|
||||
+ PARAM_DS \
|
||||
+ PARAM_VITASTOR_CONF)
|
||||
+
|
||||
+ USER="${URL_ELEMENTS[j++]}"
|
||||
+ DST_HOST="${URL_ELEMENTS[j++]}"
|
||||
+ SOURCE="${URL_ELEMENTS[j++]}"
|
||||
+ DS="${URL_ELEMENTS[j++]}"
|
||||
+ VITASTOR_CONF="${URL_ELEMENTS[j++]}"
|
||||
+
|
||||
+ # Remove leading '/'
|
||||
+ SOURCE="${SOURCE#/}"
|
||||
+
|
||||
+ if [ -n "$USER" ]; then
|
||||
+ DST_HOST="$USER@$DST_HOST"
|
||||
+ fi
|
||||
+
|
||||
+ local CLI
|
||||
+ CLI="vitastor-cli"
|
||||
+ if [ -n "$VITASTOR_CONF" ]; then
|
||||
+ CLI="$CLI --config_path '$(esc_sq "${VITASTOR_CONF}")'"
|
||||
+ fi
|
||||
+
|
||||
+ echo "ssh '$(esc_sq "$DST_HOST")' \"$CLI dd iimg='$(esc_sq "$SOURCE")'\""
|
||||
+}
|
||||
+
|
||||
# Compare 2 version strings using sort -V
|
||||
# Usage:
|
||||
# verlte "3.2.9" "3.4.0"
|
||||
@@ -424,6 +463,9 @@ s3://*)
|
||||
rbd://*)
|
||||
command="$(get_rbd_cmd "$FROM")"
|
||||
;;
|
||||
+vitastor://*)
|
||||
+ command="$(get_vitastor_cmd "$FROM")"
|
||||
+ ;;
|
||||
vcenter://*)
|
||||
command="$VAR_LOCATION/remotes/datastore/vcenter_downloader.rb '$(esc_sq "$FROM")'"
|
||||
;;
|
||||
Executable
+114
@@ -0,0 +1,114 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Vitastor OpenNebula driver
|
||||
# Copyright (c) Vitaliy Filippov, 2024+
|
||||
# License: Apache-2.0 http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
# This script is used to export an image to qcow2 file
|
||||
|
||||
# ------------ 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
|
||||
|
||||
DRIVER_PATH=$(dirname $0)
|
||||
source ${DRIVER_PATH}/../libfs.sh
|
||||
|
||||
# -------- Get rm and datastore arguments from OpenNebula core ------------
|
||||
|
||||
DRV_ACTION=`cat -`
|
||||
ID=$1
|
||||
|
||||
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/SOURCE \
|
||||
/DS_DRIVER_ACTION_DATA/IMAGE/SIZE \
|
||||
/DS_DRIVER_ACTION_DATA/IMAGE/TEMPLATE/MD5 \
|
||||
/DS_DRIVER_ACTION_DATA/IMAGE/TEMPLATE/SHA1 \
|
||||
/DS_DRIVER_ACTION_DATA/IMAGE/TEMPLATE/FORMAT \
|
||||
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/BRIDGE_LIST \
|
||||
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/VITASTOR_CONF)
|
||||
|
||||
unset i
|
||||
|
||||
SRC="${XPATH_ELEMENTS[i++]}"
|
||||
SIZE="${XPATH_ELEMENTS[i++]}"
|
||||
MD5="${XPATH_ELEMENTS[i++]}"
|
||||
SHA1="${XPATH_ELEMENTS[i++]}"
|
||||
FORMAT="${XPATH_ELEMENTS[i++]:-raw}"
|
||||
BRIDGE_LIST="${XPATH_ELEMENTS[i++]}"
|
||||
VITASTOR_CONF="${XPATH_ELEMENTS[i++]}"
|
||||
|
||||
DST_HOST=`get_destination_host $ID`
|
||||
|
||||
if [ -z "$DST_HOST" ]; then
|
||||
error_message "Datastore template missing 'BRIDGE_LIST' attribute."
|
||||
exit -1
|
||||
fi
|
||||
|
||||
IMPORT_SOURCE="vitastor://$DST_HOST/$SRC"
|
||||
IS_JOIN="?"
|
||||
|
||||
CLI=vitastor-cli
|
||||
if [ -n "$VITASTOR_CONF" ]; then
|
||||
CLI="$CLI --config_path $VITASTOR_CONF"
|
||||
IMPORT_SOURCE="${IMPORT_SOURCE}${IS_JOIN}VITASTOR_CONF=${VITASTOR_CONF}"
|
||||
fi
|
||||
|
||||
# FIXME: this is inefficient - it pipes the image twice...
|
||||
|
||||
INFO_SCRIPT=$(cat <<EOF
|
||||
if [ -z "$MD5" ]; then
|
||||
CHECKSUM=\$(
|
||||
$CLI dd iimg=${SRC} | ${MD5SUM} | cut -f1 -d' '
|
||||
ps=\$PIPESTATUS
|
||||
|
||||
if [ "\$ps" != "0" ]; then
|
||||
exit \$ps
|
||||
fi
|
||||
)
|
||||
|
||||
status=\$?
|
||||
|
||||
[ "\$status" != "0" ] && exit \$status
|
||||
else
|
||||
CHECKSUM="$MD5"
|
||||
fi
|
||||
|
||||
if [ -z "\$CHECKSUM" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cat <<EOT
|
||||
<MD5><![CDATA[\$CHECKSUM]]></MD5>
|
||||
<SIZE><![CDATA[$SIZE]]></SIZE>
|
||||
<FORMAT><![CDATA[${FORMAT}]]></FORMAT>
|
||||
EOT
|
||||
EOF
|
||||
)
|
||||
|
||||
INFO=$(ssh_monitor_and_log "$DST_HOST" "$INFO_SCRIPT" "Image info script" 2>&1)
|
||||
INFO_STATUS=$?
|
||||
|
||||
if [ "$INFO_STATUS" != "0" ]; then
|
||||
echo "$INFO"
|
||||
exit $INFO_STATUS
|
||||
fi
|
||||
|
||||
cat <<EOF
|
||||
<IMPORT_INFO>
|
||||
<IMPORT_SOURCE><![CDATA[$IMPORT_SOURCE]]></IMPORT_SOURCE>
|
||||
$INFO
|
||||
<DISPOSE>NO</DISPOSE>
|
||||
</IMPORT_INFO>"
|
||||
EOF
|
||||
Executable
+127
@@ -0,0 +1,127 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Vitastor OpenNebula driver
|
||||
# Copyright (c) Vitaliy Filippov, 2024+
|
||||
# License: Apache-2.0 http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
# This script is used to create a VM image (SRC) of size (SIZE) and formatted as (FS)
|
||||
|
||||
# -------- Set up the environment to source common tools & conf ------------
|
||||
|
||||
if [ -z "${ONE_LOCATION}" ]; then
|
||||
LIB_LOCATION=/usr/lib/one
|
||||
else
|
||||
LIB_LOCATION=$ONE_LOCATION/lib
|
||||
fi
|
||||
|
||||
. $LIB_LOCATION/sh/scripts_common.sh
|
||||
|
||||
DRIVER_PATH=$(dirname $0)
|
||||
source ${DRIVER_PATH}/../libfs.sh
|
||||
source ${DRIVER_PATH}/../../etc/datastore/datastore.conf
|
||||
|
||||
# -------- Get mkfs and datastore arguments from OpenNebula core ------------
|
||||
|
||||
DRV_ACTION=`cat -`
|
||||
ID=$1
|
||||
|
||||
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/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/BRIDGE_LIST \
|
||||
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/POOL_NAME \
|
||||
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/IMAGE_PREFIX \
|
||||
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/STAGING_DIR \
|
||||
/DS_DRIVER_ACTION_DATA/IMAGE/FORMAT \
|
||||
/DS_DRIVER_ACTION_DATA/IMAGE/SIZE \
|
||||
/DS_DRIVER_ACTION_DATA/IMAGE/FS \
|
||||
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/VITASTOR_CONF)
|
||||
|
||||
unset i
|
||||
|
||||
BASE_PATH="${XPATH_ELEMENTS[i++]}"
|
||||
RESTRICTED_DIRS="${XPATH_ELEMENTS[i++]}"
|
||||
SAFE_DIRS="${XPATH_ELEMENTS[i++]}"
|
||||
BRIDGE_LIST="${XPATH_ELEMENTS[i++]}"
|
||||
POOL_NAME="${XPATH_ELEMENTS[i++]}"
|
||||
IMAGE_PREFIX="${XPATH_ELEMENTS[i++]}"
|
||||
STAGING_DIR="${XPATH_ELEMENTS[i++]:-$STAGING_DIR}"
|
||||
FORMAT="${XPATH_ELEMENTS[i++]}"
|
||||
SIZE="${XPATH_ELEMENTS[i++]}"
|
||||
FS="${XPATH_ELEMENTS[i++]}"
|
||||
VITASTOR_CONF="${XPATH_ELEMENTS[i++]}"
|
||||
|
||||
DST_HOST=`get_destination_host $ID`
|
||||
|
||||
if [ -z "$DST_HOST" ]; then
|
||||
error_message "Datastore template missing 'BRIDGE_LIST' attribute."
|
||||
exit -1
|
||||
fi
|
||||
|
||||
CLI=
|
||||
if [ -n "$VITASTOR_CONF" ]; then
|
||||
CLI="$CLI --config_path ${VITASTOR_CONF}"
|
||||
fi
|
||||
if [ -n "$POOL_NAME" ]; then
|
||||
CLI="$CLI --pool ${POOL_NAME}"
|
||||
fi
|
||||
|
||||
set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS"
|
||||
|
||||
IMAGE_NAME="${IMAGE_PREFIX}one-${ID}"
|
||||
|
||||
# ------------ Image to save_as disk, no need to create a new image ------------
|
||||
|
||||
if [ "$FORMAT" = "save_as" ]; then
|
||||
echo "$IMAGE_NAME"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# ------------ Create the image in the repository ------------
|
||||
|
||||
# FIXME: Duplicate code with tm/vitastor/mkimage
|
||||
|
||||
MKIMAGE_CMD=$(cat <<EOF
|
||||
set -e -o pipefail
|
||||
export PATH=/usr/sbin:/sbin:\$PATH
|
||||
vitastor-cli $CLI create --pool "${POOL_NAME}" "$IMAGE_NAME" --size "${SIZE}M"
|
||||
EOF
|
||||
)
|
||||
|
||||
if [ -n "$FS" -o "$FORMAT" = "swap" ]; then
|
||||
MKFS_CMD=`mkfs_command '$NBD' raw "$SIZE" "$SUPPORTED_FS" "$FS" "$FS_OPTS" | grep -v $QEMU_IMG`
|
||||
fi
|
||||
|
||||
MKIMAGE_CMD=$(cat <<EOF
|
||||
set -e -o pipefail
|
||||
export PATH=/usr/sbin:/sbin:\$PATH
|
||||
vitastor-cli $CLI create --pool "${POOL_NAME}" "$IMAGE_NAME" --size "${SIZE}M"
|
||||
EOF
|
||||
)
|
||||
if [ ! -z $FS ]; then
|
||||
set -e -o pipefail
|
||||
|
||||
IMAGE_HASH=`generate_image_hash`
|
||||
TMP_DST="$STAGING_DIR/$IMAGE_HASH"
|
||||
FS_OPTS=$(eval $(echo "echo \$FS_OPTS_$FS"))
|
||||
|
||||
MKFS_CMD=`mkfs_command '$NBD' raw "$SIZE" "$SUPPORTED_FS" "$FS" "$FS_OPTS" | grep -v $QEMU_IMG`
|
||||
MKIMAGE_CMD=$(cat <<EOF
|
||||
$MKIMAGE_CMD
|
||||
NBD=\$(sudo vitastor-nbd $CLI map --image "$IMAGE_NAME")
|
||||
trap "sudo vitastor-nbd $CLI unmap \$NBD" EXIT
|
||||
$MKFS_CMD
|
||||
EOF
|
||||
)
|
||||
fi
|
||||
|
||||
ssh_exec_and_log "$DST_HOST" "$MKIMAGE_CMD" "Error registering $IMAGE_NAME in $DST_HOST"
|
||||
|
||||
echo "$IMAGE_NAME"
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Vitastor OpenNebula driver
|
||||
# Copyright (c) Vitaliy Filippov, 2024+
|
||||
# License: Apache-2.0 http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
# This script is used to monitor the free and used space of a datastore
|
||||
|
||||
# -------- Set up the environment to source common tools & conf ------------
|
||||
|
||||
if [ -z "${ONE_LOCATION}" ]; then
|
||||
LIB_LOCATION=/usr/lib/one
|
||||
else
|
||||
LIB_LOCATION=$ONE_LOCATION/lib
|
||||
fi
|
||||
|
||||
. $LIB_LOCATION/sh/scripts_common.sh
|
||||
|
||||
DRIVER_PATH=$(dirname $0)
|
||||
source ${DRIVER_PATH}/../../datastore/libfs.sh
|
||||
|
||||
# -------- Get datastore arguments from OpenNebula core ------------
|
||||
|
||||
DRV_ACTION=`cat -`
|
||||
ID=$1
|
||||
|
||||
XPATH="${DRIVER_PATH}/../../datastore/xpath.rb -b $DRV_ACTION"
|
||||
|
||||
unset i j XPATH_ELEMENTS
|
||||
|
||||
while IFS= read -r -d '' element; do
|
||||
XPATH_ELEMENTS[i++]="$element"
|
||||
done < <($XPATH \
|
||||
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/BRIDGE_LIST \
|
||||
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/POOL_NAME \
|
||||
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/VITASTOR_CONF)
|
||||
|
||||
BRIDGE_LIST="${XPATH_ELEMENTS[j++]}"
|
||||
POOL_NAME="${XPATH_ELEMENTS[j++]}"
|
||||
VITASTOR_CONF="${XPATH_ELEMENTS[j++]}"
|
||||
|
||||
HOST=`get_destination_host`
|
||||
|
||||
if [ -z "$HOST" ]; then
|
||||
error_message "Datastore template missing 'BRIDGE_LIST' attribute."
|
||||
exit -1
|
||||
fi
|
||||
|
||||
CLI=vitastor-cli
|
||||
if [ -n "$VITASTOR_CONF" ]; then
|
||||
CLI="$CLI --config_path ${VITASTOR_CONF}"
|
||||
fi
|
||||
|
||||
# ------------ Compute datastore usage -------------
|
||||
|
||||
MONITOR_SCRIPT=$(cat <<EOF
|
||||
vitastor-cli df --json | jq -r '.[] | select(.name == "${POOL_NAME}") |
|
||||
"TOTAL_MB="+(.total_raw/.raw_to_usable/1024/1024 | tostring)+
|
||||
"\nUSED_MB="+(.used_raw/.raw_to_usable/1024/1024 | tostring)+
|
||||
"\nFREE_MB="+(.max_available/1024/1024 | tostring)'
|
||||
EOF
|
||||
)
|
||||
|
||||
ssh_monitor_and_log $HOST "$MONITOR_SCRIPT 2>&1" "Error monitoring ${POOL_NAME} in $HOST"
|
||||
@@ -0,0 +1,70 @@
|
||||
diff --git /etc/one/oned.conf /etc/one/oned.conf
|
||||
index be02d646a8..27f876ec36 100644
|
||||
--- /etc/one/oned.conf
|
||||
+++ /etc/one/oned.conf
|
||||
@@ -481,7 +481,7 @@ VM_MAD = [
|
||||
NAME = "kvm",
|
||||
SUNSTONE_NAME = "KVM",
|
||||
EXECUTABLE = "one_vmm_exec",
|
||||
- ARGUMENTS = "-t 15 -r 0 kvm -p",
|
||||
+ ARGUMENTS = "-t 15 -r 0 kvm -p -l deploy=deploy.vitastor",
|
||||
DEFAULT = "vmm_exec/vmm_exec_kvm.conf",
|
||||
TYPE = "kvm",
|
||||
KEEP_SNAPSHOTS = "yes",
|
||||
@@ -592,7 +592,7 @@ VM_MAD = [
|
||||
|
||||
TM_MAD = [
|
||||
EXECUTABLE = "one_tm",
|
||||
- ARGUMENTS = "-t 15 -d dummy,lvm,shared,fs_lvm,fs_lvm_ssh,qcow2,ssh,ceph,dev,vcenter,iscsi_libvirt"
|
||||
+ ARGUMENTS = "-t 15 -d dummy,lvm,shared,fs_lvm,fs_lvm_ssh,qcow2,ssh,ceph,vitastor,dev,vcenter,iscsi_libvirt"
|
||||
]
|
||||
|
||||
#*******************************************************************************
|
||||
@@ -612,7 +612,7 @@ TM_MAD = [
|
||||
|
||||
DATASTORE_MAD = [
|
||||
EXECUTABLE = "one_datastore",
|
||||
- ARGUMENTS = "-t 15 -d dummy,fs,lvm,ceph,dev,iscsi_libvirt,vcenter,restic,rsync -s shared,ssh,ceph,fs_lvm,fs_lvm_ssh,qcow2,vcenter"
|
||||
+ ARGUMENTS = "-t 15 -d dummy,fs,lvm,ceph,vitastor,dev,iscsi_libvirt,vcenter,restic,rsync -s shared,ssh,ceph,vitastor,fs_lvm,fs_lvm_ssh,qcow2,vcenter"
|
||||
]
|
||||
|
||||
#*******************************************************************************
|
||||
@@ -1050,6 +1050,9 @@ INHERIT_DATASTORE_ATTR = "VCENTER_DS_IMAGE_DIR"
|
||||
INHERIT_DATASTORE_ATTR = "VCENTER_DS_VOLATILE_DIR"
|
||||
INHERIT_DATASTORE_ATTR = "VCENTER_INSTANCE_ID"
|
||||
|
||||
+INHERIT_DATASTORE_ATTR = "VITASTOR_CONF"
|
||||
+INHERIT_DATASTORE_ATTR = "IMAGE_PREFIX"
|
||||
+
|
||||
INHERIT_IMAGE_ATTR = "DISK_TYPE"
|
||||
INHERIT_IMAGE_ATTR = "VCENTER_ADAPTER_TYPE"
|
||||
INHERIT_IMAGE_ATTR = "VCENTER_DISK_TYPE"
|
||||
@@ -1180,6 +1183,14 @@ TM_MAD_CONF = [
|
||||
CLONE_TARGET_SHARED = "SELF", DISK_TYPE_SHARED = "RBD"
|
||||
]
|
||||
|
||||
+TM_MAD_CONF = [
|
||||
+ NAME = "vitastor", LN_TARGET = "NONE", CLONE_TARGET = "SELF", SHARED = "YES",
|
||||
+ DS_MIGRATE = "NO", DRIVER = "raw", ALLOW_ORPHANS="format",
|
||||
+ TM_MAD_SYSTEM = "ssh,shared", LN_TARGET_SSH = "SYSTEM", CLONE_TARGET_SSH = "SYSTEM",
|
||||
+ DISK_TYPE_SSH = "FILE", LN_TARGET_SHARED = "NONE",
|
||||
+ CLONE_TARGET_SHARED = "SELF", DISK_TYPE_SHARED = "FILE"
|
||||
+]
|
||||
+
|
||||
TM_MAD_CONF = [
|
||||
NAME = "iscsi_libvirt", LN_TARGET = "NONE", CLONE_TARGET = "SELF", SHARED = "YES",
|
||||
DS_MIGRATE = "NO", DRIVER = "raw"
|
||||
@@ -1219,6 +1230,13 @@ DS_MAD_CONF = [
|
||||
MARKETPLACE_ACTIONS = "export"
|
||||
]
|
||||
|
||||
+DS_MAD_CONF = [
|
||||
+ NAME = "vitastor",
|
||||
+ REQUIRED_ATTRS = "DISK_TYPE,BRIDGE_LIST",
|
||||
+ PERSISTENT_ONLY = "NO",
|
||||
+ MARKETPLACE_ACTIONS = "export"
|
||||
+]
|
||||
+
|
||||
DS_MAD_CONF = [
|
||||
NAME = "dev", REQUIRED_ATTRS = "DISK_TYPE", PERSISTENT_ONLY = "YES"
|
||||
]
|
||||
Executable
+63
@@ -0,0 +1,63 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Vitastor OpenNebula driver
|
||||
# Copyright (c) Vitaliy Filippov, 2024+
|
||||
# License: Apache-2.0 http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
# This script is used to remove a VM image from the image repository
|
||||
|
||||
# ------------ 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
|
||||
|
||||
DRIVER_PATH=$(dirname $0)
|
||||
|
||||
source ${DRIVER_PATH}/../libfs.sh
|
||||
|
||||
# -------- Get rm and datastore arguments from OpenNebula core ------------
|
||||
|
||||
DRV_ACTION=`cat -`
|
||||
ID=$1
|
||||
|
||||
XPATH="${DRIVER_PATH}/../xpath.rb -b $DRV_ACTION"
|
||||
|
||||
unset i j XPATH_ELEMENTS
|
||||
|
||||
while IFS= read -r -d '' element; do
|
||||
XPATH_ELEMENTS[i++]="$element"
|
||||
done < <($XPATH \
|
||||
/DS_DRIVER_ACTION_DATA/IMAGE/SOURCE \
|
||||
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/BRIDGE_LIST \
|
||||
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/VITASTOR_CONF)
|
||||
|
||||
IMAGE_NAME="${XPATH_ELEMENTS[j++]}"
|
||||
BRIDGE_LIST="${XPATH_ELEMENTS[j++]}"
|
||||
VITASTOR_CONF="${XPATH_ELEMENTS[j++]}"
|
||||
|
||||
DST_HOST=`get_destination_host $ID`
|
||||
|
||||
if [ -z "$DST_HOST" ]; then
|
||||
error_message "Datastore template missing 'BRIDGE_LIST' attribute."
|
||||
exit -1
|
||||
fi
|
||||
|
||||
CLI=vitastor-cli
|
||||
if [ -n "$VITASTOR_CONF" ]; then
|
||||
CLI="$CLI --config_path ${VITASTOR_CONF}"
|
||||
fi
|
||||
|
||||
# -------- Remove Image from Datastore ------------
|
||||
|
||||
log "Removing $IMAGE_NAME from the image repository in $DST_HOST"
|
||||
|
||||
DELETE_CMD=$(cat <<EOF
|
||||
$CLI rm $IMAGE_NAME
|
||||
EOF
|
||||
)
|
||||
|
||||
ssh_exec_and_log "$DST_HOST" "$DELETE_CMD" "Error deleting $IMAGE_NAME in $DST_HOST"
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Vitastor OpenNebula driver
|
||||
# Copyright (c) Vitaliy Filippov, 2024+
|
||||
# License: Apache-2.0 http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
# This script is used to delete a snapshot of an image
|
||||
|
||||
# -------- Set up the environment to source common tools & conf ------------
|
||||
|
||||
if [ -z "${ONE_LOCATION}" ]; then
|
||||
LIB_LOCATION=/usr/lib/one
|
||||
else
|
||||
LIB_LOCATION=$ONE_LOCATION/lib
|
||||
fi
|
||||
|
||||
. $LIB_LOCATION/sh/scripts_common.sh
|
||||
|
||||
DRIVER_PATH=$(dirname $0)
|
||||
|
||||
source ${DRIVER_PATH}/../libfs.sh
|
||||
|
||||
# -------- Get image and datastore arguments from OpenNebula core ------------
|
||||
|
||||
DRV_ACTION=`cat -`
|
||||
ID=$1
|
||||
|
||||
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/DATASTORE/TEMPLATE/BRIDGE_LIST \
|
||||
/DS_DRIVER_ACTION_DATA/IMAGE/SOURCE \
|
||||
/DS_DRIVER_ACTION_DATA/IMAGE/TARGET_SNAPSHOT \
|
||||
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/VITASTOR_CONF)
|
||||
|
||||
unset i
|
||||
|
||||
BRIDGE_LIST="${XPATH_ELEMENTS[i++]}"
|
||||
IMAGE_NAME="${XPATH_ELEMENTS[i++]}"
|
||||
SNAP_ID="${XPATH_ELEMENTS[i++]}"
|
||||
VITASTOR_CONF="${XPATH_ELEMENTS[i++]}"
|
||||
|
||||
DST_HOST=`get_destination_host $ID`
|
||||
|
||||
if [ -z "$DST_HOST" ]; then
|
||||
error_message "Datastore template missing 'BRIDGE_LIST' attribute."
|
||||
exit -1
|
||||
fi
|
||||
|
||||
CLI=vitastor-cli
|
||||
if [ -n "$VITASTOR_CONF" ]; then
|
||||
CLI="$CLI --config_path ${VITASTOR_CONF}"
|
||||
fi
|
||||
|
||||
SNAP_DELETE_CMD=$(cat <<EOF
|
||||
$CLI rm ${IMAGE_NAME}@${SNAP_ID}
|
||||
EOF
|
||||
)
|
||||
|
||||
ssh_exec_and_log "$DST_HOST" "$SNAP_DELETE_CMD" "Error deleting snapshot $IMAGE_NAME-$SNAP_ID@$SNAP_ID"
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Vitastor OpenNebula driver
|
||||
# Copyright (c) Vitaliy Filippov, 2024+
|
||||
# License: Apache-2.0 http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
# This script is used to flatten a snapshot of a persistent image
|
||||
|
||||
# -------- Set up the environment to source common tools & conf ------------
|
||||
|
||||
if [ -z "${ONE_LOCATION}" ]; then
|
||||
LIB_LOCATION=/usr/lib/one
|
||||
else
|
||||
LIB_LOCATION=$ONE_LOCATION/lib
|
||||
fi
|
||||
|
||||
. $LIB_LOCATION/sh/scripts_common.sh
|
||||
|
||||
DRIVER_PATH=$(dirname $0)
|
||||
|
||||
source ${DRIVER_PATH}/../libfs.sh
|
||||
|
||||
# -------- Get image and datastore arguments from OpenNebula core ------------
|
||||
|
||||
DRV_ACTION=`cat -`
|
||||
ID=$1
|
||||
|
||||
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/DATASTORE/TEMPLATE/BRIDGE_LIST \
|
||||
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/POOL_NAME \
|
||||
/DS_DRIVER_ACTION_DATA/IMAGE/SOURCE \
|
||||
/DS_DRIVER_ACTION_DATA/IMAGE/TARGET_SNAPSHOT \
|
||||
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/VITASTOR_CONF)
|
||||
|
||||
unset i
|
||||
|
||||
BRIDGE_LIST="${XPATH_ELEMENTS[i++]}"
|
||||
POOL_NAME="${XPATH_ELEMENTS[i++]}"
|
||||
IMAGE_NAME="${XPATH_ELEMENTS[i++]}"
|
||||
SNAP_ID="${XPATH_ELEMENTS[i++]}"
|
||||
VITASTOR_CONF="${XPATH_ELEMENTS[i++]}"
|
||||
|
||||
DST_HOST=`get_destination_host $ID`
|
||||
|
||||
if [ -z "$DST_HOST" ]; then
|
||||
error_message "Datastore template missing 'BRIDGE_LIST' attribute."
|
||||
exit -1
|
||||
fi
|
||||
|
||||
CLI=vitastor-cli
|
||||
if [ -n "$VITASTOR_CONF" ]; then
|
||||
CLI="$CLI --config_path ${VITASTOR_CONF}"
|
||||
fi
|
||||
|
||||
SNAP_FLATTEN_CMD=$(cat <<EOF
|
||||
$CLI ls --json ${IMAGE_NAME}@${SNAP_ID} | jq -e 'length > 0'
|
||||
$CLI rm ${IMAGE_NAME}.flatten || true
|
||||
$CLI create --pool "${POOL_NAME}" --parent ${IMAGE_NAME}@${SNAP_ID} ${IMAGE_NAME}.flatten
|
||||
$CLI flatten ${IMAGE_NAME}.flatten
|
||||
$CLI rm ${IMAGE_NAME} || true
|
||||
$CLI modify ${IMAGE_NAME}.flatten --rename ${IMAGE_NAME}
|
||||
EOF
|
||||
)
|
||||
|
||||
ssh_exec_and_log "$DST_HOST" "$SNAP_FLATTEN_CMD" "Error flattening snapshot $SNAP_ID for $IMAGE_NAME"
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Vitastor OpenNebula driver
|
||||
# Copyright (c) Vitaliy Filippov, 2024+
|
||||
# License: Apache-2.0 http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
# This script is used to revert a snapshot of an image
|
||||
|
||||
# -------- Set up the environment to source common tools & conf ------------
|
||||
|
||||
if [ -z "${ONE_LOCATION}" ]; then
|
||||
LIB_LOCATION=/usr/lib/one
|
||||
else
|
||||
LIB_LOCATION=$ONE_LOCATION/lib
|
||||
fi
|
||||
|
||||
. $LIB_LOCATION/sh/scripts_common.sh
|
||||
|
||||
DRIVER_PATH=$(dirname $0)
|
||||
|
||||
source ${DRIVER_PATH}/../libfs.sh
|
||||
|
||||
# -------- Get image and datastore arguments from OpenNebula core ------------
|
||||
|
||||
DRV_ACTION=`cat -`
|
||||
ID=$1
|
||||
|
||||
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/DATASTORE/TEMPLATE/BRIDGE_LIST \
|
||||
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/POOL_NAME \
|
||||
/DS_DRIVER_ACTION_DATA/IMAGE/SOURCE \
|
||||
/DS_DRIVER_ACTION_DATA/IMAGE/TARGET_SNAPSHOT \
|
||||
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/VITASTOR_CONF)
|
||||
|
||||
unset i
|
||||
|
||||
BRIDGE_LIST="${XPATH_ELEMENTS[i++]}"
|
||||
POOL_NAME="${XPATH_ELEMENTS[i++]}"
|
||||
IMAGE_NAME="${XPATH_ELEMENTS[i++]}"
|
||||
SNAP_ID="${XPATH_ELEMENTS[i++]}"
|
||||
VITASTOR_CONF="${XPATH_ELEMENTS[i++]}"
|
||||
|
||||
DST_HOST=`get_destination_host $ID`
|
||||
|
||||
if [ -z "$DST_HOST" ]; then
|
||||
error_message "Datastore template missing 'BRIDGE_LIST' attribute."
|
||||
exit -1
|
||||
fi
|
||||
|
||||
CLI=vitastor-cli
|
||||
if [ -n "$VITASTOR_CONF" ]; then
|
||||
CLI="$CLI --config_path ${VITASTOR_CONF}"
|
||||
fi
|
||||
if [ -n "$POOL_NAME" ]; then
|
||||
CLI="$CLI --pool ${POOL_NAME}"
|
||||
fi
|
||||
|
||||
SNAP_REVERT_CMD=$(cat <<EOF
|
||||
$CLI rm ${IMAGE_NAME}.flatten || true
|
||||
$CLI create --pool "${POOL_NAME}" --parent ${IMAGE_NAME}@${SNAP_ID} ${IMAGE_NAME}.flatten
|
||||
$CLI rm ${IMAGE_NAME} || true
|
||||
$CLI modify ${IMAGE_NAME}.flatten --rename ${IMAGE_NAME}
|
||||
EOF
|
||||
)
|
||||
|
||||
ssh_exec_and_log "$DST_HOST" "$SNAP_REVERT_CMD" "Error reverting snapshot $SNAP_ID for $IMAGE_NAME"
|
||||
@@ -0,0 +1 @@
|
||||
../ceph/stat
|
||||
@@ -0,0 +1,12 @@
|
||||
diff --git /etc/one/vmm_exec/vmm_execrc /etc/one/vmm_exec/vmm_execrc
|
||||
index e210526e63..cb51d3b5e8 100644
|
||||
--- /etc/one/vmm_exec/vmm_execrc
|
||||
+++ /etc/one/vmm_exec/vmm_execrc
|
||||
@@ -1,6 +1,6 @@
|
||||
# Space separated list of VMM-TM pairs that support live disk snapshots. VMM
|
||||
# and TM must be separated by '-'
|
||||
-LIVE_DISK_SNAPSHOTS="kvm-qcow2 kvm-shared kvm-ceph kvm-ssh qemu-qcow2 qemu-shared qemu-ceph qemu-ssh"
|
||||
+LIVE_DISK_SNAPSHOTS="kvm-qcow2 kvm-shared kvm-ceph kvm-vitastor kvm-ssh qemu-qcow2 qemu-shared qemu-ceph qemu-ssh"
|
||||
|
||||
# Space separated list VNM_MAD-ACTION pairs that run locally
|
||||
VNMAD_LOCAL_ACTIONS="elastic-post elastic-clean"
|
||||
Executable
+97
@@ -0,0 +1,97 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Vitastor OpenNebula driver
|
||||
# Copyright (c) Vitaliy Filippov, 2024+
|
||||
# License: Apache-2.0 http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
# 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
|
||||
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
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# 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}')
|
||||
VM_DST="${SRC_PATH}-${VM_ID}-${DISK_ID}"
|
||||
DST_DS_ID=`echo $DST | sed s#//*#/#g | awk -F/ '{print $(NF-2)}'`
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# 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]/VITASTOR_CONF \
|
||||
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/SIZE)
|
||||
|
||||
VITASTOR_CONF="${XPATH_ELEMENTS[j++]}"
|
||||
SIZE="${XPATH_ELEMENTS[j++]}"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Get Datastore information
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
unset i j XPATH_ELEMENTS
|
||||
|
||||
while IFS= read -r -d '' element; do
|
||||
XPATH_ELEMENTS[i++]="$element"
|
||||
done < <(onedatastore show -x $DST_DS_ID | $XPATH \
|
||||
/DATASTORE/TEMPLATE/POOL_NAME)
|
||||
|
||||
POOL_NAME="${XPATH_ELEMENTS[j++]}"
|
||||
|
||||
disable_local_monitoring $DST_HOST $DST_DIR
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Clone the image
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
CLI=vitastor-cli
|
||||
if [ -n "$VITASTOR_CONF" ]; then
|
||||
CLI="$CLI --config_path ${VITASTOR_CONF}"
|
||||
fi
|
||||
if [ -n "$POOL_NAME" ]; then
|
||||
CLI="$CLI --pool ${POOL_NAME}"
|
||||
fi
|
||||
|
||||
CLONE_CMD=$(cat <<EOF
|
||||
$CLI create --parent $SRC_PATH --size ${SIZE}M $VM_DST
|
||||
EOF
|
||||
)
|
||||
|
||||
ssh_exec_and_log "$DST_HOST" "$CLONE_CMD" "Error cloning $SRC_PATH to $VM_DST in $DST_HOST"
|
||||
exit 0
|
||||
+1
@@ -0,0 +1 @@
|
||||
../ceph/context
|
||||
Executable
+113
@@ -0,0 +1,113 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Vitastor OpenNebula driver
|
||||
# Copyright (c) Vitaliy Filippov, 2024+
|
||||
# License: Apache-2.0 http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
# cpds host:remote_system_ds/disk.i fe:SOURCE snapid vmid dsid
|
||||
# - 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
|
||||
# - snapid is the snapshot id. "-1" for none
|
||||
|
||||
SRC=$1
|
||||
DST=$2
|
||||
SNAP_ID=$3
|
||||
VM_ID=$4
|
||||
DS_ID=$5
|
||||
|
||||
#--------------------------------------------------------------------------------
|
||||
|
||||
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}/../../datastore/libfs.sh
|
||||
source ${DRIVER_PATH}/../../etc/vmm/kvm/kvmrc
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Set dst path and dir
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
SRC_HOST=`arg_host $SRC`
|
||||
SRC_PATH=`arg_path $SRC`
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Get Image information
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
DISK_ID=$(echo "$SRC_PATH" | $AWK -F. '{print $NF}')
|
||||
|
||||
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]/SOURCE \
|
||||
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/CLONE \
|
||||
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/VITASTOR_CONF \
|
||||
/VM/LCM_STATE)
|
||||
|
||||
SRC_IMAGE="${XPATH_ELEMENTS[j++]}"
|
||||
CLONE="${XPATH_ELEMENTS[j++]}"
|
||||
VITASTOR_CONF="${XPATH_ELEMENTS[j++]}"
|
||||
LCM_STATE="${XPATH_ELEMENTS[j++]}"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Get Datastore information
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
unset i j XPATH_ELEMENTS
|
||||
|
||||
while IFS= read -r -d '' element; do
|
||||
XPATH_ELEMENTS[i++]="$element"
|
||||
done < <(onedatastore show -x $DS_ID | $XPATH \
|
||||
/DATASTORE/TEMPLATE/POOL_NAME \
|
||||
/DATASTORE/TEMPLATE/BRIDGE_LIST)
|
||||
|
||||
POOL_NAME="${XPATH_ELEMENTS[j++]}"
|
||||
BRIDGE_LIST="${XPATH_ELEMENTS[j++]}"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Copy Image back to the datastore
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
if [ "$CLONE" = "YES" ]; then
|
||||
SRC_IMAGE="${SRC_IMAGE}-${VM_ID}-${DISK_ID}"
|
||||
fi
|
||||
|
||||
CLI=vitastor-cli
|
||||
if [ -n "$VITASTOR_CONF" ]; then
|
||||
CLI="$CLI --config_path ${VITASTOR_CONF}"
|
||||
fi
|
||||
if [ -n "$POOL_NAME" ]; then
|
||||
CLI="$CLI --pool ${POOL_NAME}"
|
||||
fi
|
||||
|
||||
# Undeployed VM state, do not use front-end, choose host from bridge_list
|
||||
if [ "$LCM_STATE" = '67' ] || [ "$LCM_STATE" = '68' ]; then
|
||||
if [ -n "$BRIDGE_LIST" ]; then
|
||||
SRC_HOST=`get_destination_host`
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$SNAP_ID" != "-1" ]; then
|
||||
SRC_IMAGE=$SRC_IMAGE@$SNAP_ID
|
||||
fi
|
||||
|
||||
COPY_CMD=$(cat <<EOF
|
||||
$CLI dd iimg=$SRC_IMAGE oimg=$DST
|
||||
EOF
|
||||
)
|
||||
|
||||
ssh_exec_and_log "$SRC_HOST" "$COPY_CMD" "Error cloning $SRC_IMAGE to $DST in $SRC_HOST"
|
||||
Executable
+139
@@ -0,0 +1,139 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Vitastor OpenNebula driver
|
||||
# Copyright (c) Vitaliy Filippov, 2024+
|
||||
# License: Apache-2.0 http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
# 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
|
||||
VM_ID=$2
|
||||
DS_ID=$3
|
||||
|
||||
#--------------------------------------------------------------------------------
|
||||
|
||||
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}/../../datastore/libfs.sh
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Process destination
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
DST_PATH=`arg_path $DST`
|
||||
DST_HOST=`arg_host $DST`
|
||||
|
||||
XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Delete and exit if directory
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
if [ `is_disk $DST_PATH` -eq 0 ]; then
|
||||
# Directory: delete checkpoint and directory
|
||||
|
||||
unset i j XPATH_ELEMENTS
|
||||
|
||||
while IFS= read -r -d '' element; do
|
||||
XPATH_ELEMENTS[i++]="$element"
|
||||
done < <(onedatastore show -x $DS_ID | $XPATH \
|
||||
/DATASTORE/TEMPLATE/SOURCE \
|
||||
/DATASTORE/TEMPLATE/CLONE \
|
||||
/DATASTORE/TEMPLATE/VITASTOR_CONF \
|
||||
/DATASTORE/TEMPLATE/IMAGE_PREFIX \
|
||||
/DATASTORE/TEMPLATE/POOL_NAME)
|
||||
|
||||
SRC="${XPATH_ELEMENTS[j++]}"
|
||||
CLONE="${XPATH_ELEMENTS[j++]}"
|
||||
VITASTOR_CONF="${XPATH_ELEMENTS[j++]}"
|
||||
IMAGE_PREFIX="${XPATH_ELEMENTS[j++]}"
|
||||
POOL_NAME="${XPATH_ELEMENTS[j++]}"
|
||||
|
||||
CLI=vitastor-cli
|
||||
if [ -n "$VITASTOR_CONF" ]; then
|
||||
CLI="$CLI --config_path ${VITASTOR_CONF}"
|
||||
fi
|
||||
|
||||
SRC_CHECKPOINT="${IMAGE_PREFIX}one-sys-${VM_ID}-checkpoint"
|
||||
|
||||
ssh_exec_and_log "$DST_HOST" "$CLI rm $SRC_CHECKPOINT 2>/dev/null || exit 0" \
|
||||
"Error deleting $SRC_CHECKPOINT in $DST_HOST"
|
||||
|
||||
log "Deleting $DST_PATH"
|
||||
ssh_exec_and_log "$DST_HOST" "rm -rf $DST_PATH" "Error deleting $DST_PATH"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Get Image information
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
DISK_ID=$(echo "$DST_PATH" | $AWK -F. '{print $NF}')
|
||||
|
||||
# Reads the disk parameters -- taken from image datastore
|
||||
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]/SOURCE \
|
||||
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/CLONE \
|
||||
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/VITASTOR_CONF \
|
||||
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/IMAGE_PREFIX \
|
||||
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/POOL_NAME)
|
||||
|
||||
SRC="${XPATH_ELEMENTS[j++]}"
|
||||
CLONE="${XPATH_ELEMENTS[j++]}"
|
||||
VITASTOR_CONF="${XPATH_ELEMENTS[j++]}"
|
||||
IMAGE_PREFIX="${XPATH_ELEMENTS[j++]}"
|
||||
POOL_NAME="${XPATH_ELEMENTS[j++]}"
|
||||
|
||||
if is_undeployed "$VM_ID" "$DST_HOST"; then
|
||||
# get BRIDGE_LIST from datastore
|
||||
XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin"
|
||||
IFS= read -r -d '' BRIDGE_LIST < <(onedatastore show -x "$DS_ID" \
|
||||
| $XPATH /DATASTORE/TEMPLATE/BRIDGE_LIST )
|
||||
|
||||
if [ -n "$BRIDGE_LIST" ]; then
|
||||
DST_HOST=$(get_destination_host)
|
||||
fi
|
||||
fi
|
||||
|
||||
# No need to delete not cloned images
|
||||
if [ "$CLONE" = "NO" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
CLI=vitastor-cli
|
||||
if [ -n "$VITASTOR_CONF" ]; then
|
||||
CLI="$CLI --config_path ${VITASTOR_CONF}"
|
||||
fi
|
||||
|
||||
if [ -n "$SRC" ]; then
|
||||
# cloned, so the name will be "one-<imageid>-<vmid>-<diskid>"
|
||||
SRC_IMAGE="${SRC}-${VM_ID}-${DISK_ID}"
|
||||
else
|
||||
# volatile
|
||||
SRC_IMAGE="${IMAGE_PREFIX}one-sys-${VM_ID}-${DISK_ID}"
|
||||
fi
|
||||
|
||||
# Delete the image
|
||||
|
||||
log "Deleting $DST_PATH"
|
||||
|
||||
DELETE_CMD=$(cat <<EOF
|
||||
$CLI rm $SRC_IMAGE
|
||||
EOF
|
||||
)
|
||||
|
||||
ssh_exec_and_log "$DST_HOST" "$DELETE_CMD" "Error deleting $SRC_IMAGE in $DST_HOST"
|
||||
@@ -0,0 +1 @@
|
||||
../ceph/failmigrate
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Vitastor OpenNebula driver
|
||||
# Copyright (c) Vitaliy Filippov, 2024+
|
||||
# License: Apache-2.0 http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
# <CLONE|LN>(.tm_mad_system) tm_mad fe:SOURCE host:remote_system_ds/disk.i vmid dsid
|
||||
|
||||
# LN = Attach disk to a VM (Vitastor doesn't need to do anything in this case)
|
||||
|
||||
SRC=$1
|
||||
DST=$2
|
||||
VM_ID=$3
|
||||
DS_ID=$4
|
||||
|
||||
exit 0
|
||||
Executable
+120
@@ -0,0 +1,120 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Vitastor OpenNebula driver
|
||||
# Copyright (c) Vitaliy Filippov, 2024+
|
||||
# License: Apache-2.0 http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
# mkimage size format host:remote_system_ds/disk.i vmid dsid
|
||||
# - 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
|
||||
# - vmid is the id of the VM
|
||||
# - dsid is the target datastore (0 is the system datastore)
|
||||
|
||||
SIZE=$1
|
||||
FORMAT=$2
|
||||
DST=$3
|
||||
|
||||
VMID=$4
|
||||
DSID=$5
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
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/datastore.conf
|
||||
source ${DRIVER_PATH}/../../datastore/libfs.sh
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Set dst path and dir
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
DST_PATH=`arg_path $DST`
|
||||
DST_HOST=`arg_host $DST`
|
||||
DST_DIR=`dirname $DST_PATH`
|
||||
|
||||
DISK_ID=$(echo $DST|awk -F. '{print $NF}')
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# 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 $VMID | $XPATH \
|
||||
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/VITASTOR_CONF \
|
||||
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/POOL_NAME \
|
||||
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/IMAGE_PREFIX \
|
||||
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/FS)
|
||||
|
||||
VITASTOR_CONF="${XPATH_ELEMENTS[j++]}"
|
||||
POOL_NAME="${XPATH_ELEMENTS[j++]}"
|
||||
IMAGE_PREFIX="${XPATH_ELEMENTS[j++]}"
|
||||
FS="${XPATH_ELEMENTS[j++]}"
|
||||
|
||||
CLI=
|
||||
QEMU_ARG=""
|
||||
if [ -n "$VITASTOR_CONF" ]; then
|
||||
CLI="$CLI --config_path ${VITASTOR_CONF}"
|
||||
QEMU_ARG=":config_path=${VITASTOR_CONF}"
|
||||
fi
|
||||
|
||||
IMAGE_NAME="${IMAGE_PREFIX}one-sys-${VMID}-${DISK_ID}"
|
||||
|
||||
ssh_make_path $DST_HOST $DST_DIR
|
||||
|
||||
set -e -o pipefail
|
||||
|
||||
# if user requested a swap or specifies a FS, we need to create a local
|
||||
# formatted image and upload into existing Vitastor image
|
||||
FS_OPTS=$(eval $(echo "echo \$FS_OPTS_$FS"))
|
||||
|
||||
MKIMAGE_CMD=$(cat <<EOF
|
||||
set -e -o pipefail
|
||||
export PATH=/usr/sbin:/sbin:\$PATH
|
||||
vitastor-cli $CLI create --pool "${POOL_NAME}" "$IMAGE_NAME" --size "${SIZE}M"
|
||||
EOF
|
||||
)
|
||||
|
||||
if [ -n "$FS" -o "$FORMAT" = "swap" ]; then
|
||||
MKFS_CMD=`mkfs_command '$NBD' raw "$SIZE" "$SUPPORTED_FS" "$FS" "$FS_OPTS" | grep -v $QEMU_IMG`
|
||||
MKIMAGE_CMD=$(cat <<EOF
|
||||
$MKIMAGE_CMD
|
||||
NBD=\$(sudo vitastor-nbd $CLI map --image "$IMAGE_NAME")
|
||||
trap "sudo vitastor-nbd $CLI unmap \$NBD" EXIT
|
||||
$MKFS_CMD
|
||||
EOF
|
||||
)
|
||||
fi
|
||||
|
||||
DELIMAGE_CMD=$(cat <<EOF
|
||||
vitastor-cli $CLI rm "$IMAGE_NAME"
|
||||
EOF
|
||||
)
|
||||
|
||||
log "Making volatile disk of ${SIZE}M at $DST"
|
||||
|
||||
ssh_exec_and_log_no_error "$DST_HOST" "$MKIMAGE_CMD" "Error creating volatile disk.$DISK_ID ($IMAGE_NAME) in $DST_HOST in pool $POOL_NAME."
|
||||
|
||||
rc=$?
|
||||
|
||||
if [ $rc != 0 ]; then
|
||||
ssh_exec_and_log_no_error "$DST_HOST" "$DELIMAGE_CMD" "Error removing image"
|
||||
fi
|
||||
|
||||
exit $rc
|
||||
+1
@@ -0,0 +1 @@
|
||||
../ceph/mkswap
|
||||
+1
@@ -0,0 +1 @@
|
||||
../../datastore/vitastor/monitor
|
||||
+1
@@ -0,0 +1 @@
|
||||
../ceph/mv
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Vitastor OpenNebula driver
|
||||
# Copyright (c) Vitaliy Filippov, 2024+
|
||||
# License: Apache-2.0 http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
# mvds host:remote_system_ds/disk.i fe:SOURCE vmid dsid
|
||||
# - 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
|
||||
# - vmid is the id of the VM
|
||||
# - dsid is the target datastore (0 is the system datastore)
|
||||
|
||||
exit 0
|
||||
@@ -0,0 +1 @@
|
||||
postbackup_live
|
||||
@@ -0,0 +1 @@
|
||||
../ceph/postbackup_live
|
||||
@@ -0,0 +1 @@
|
||||
../ceph/postmigrate
|
||||
Executable
+152
@@ -0,0 +1,152 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# Vitastor OpenNebula driver
|
||||
# Copyright (c) Vitaliy Filippov, 2024+
|
||||
# License: Apache-2.0 http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
ONE_LOCATION = ENV['ONE_LOCATION']
|
||||
LIVE = ENV['LIVE']
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION = '/usr/lib/one/ruby'
|
||||
GEMS_LOCATION = '/usr/share/one/gems'
|
||||
VMDIR = '/var/lib/one'
|
||||
CONFIG_FILE = '/var/lib/one/config'
|
||||
else
|
||||
RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby'
|
||||
GEMS_LOCATION = ONE_LOCATION + '/share/gems'
|
||||
VMDIR = ONE_LOCATION + '/var'
|
||||
CONFIG_FILE = ONE_LOCATION + '/var/config'
|
||||
end
|
||||
|
||||
# %%RUBYGEMS_SETUP_BEGIN%%
|
||||
if File.directory?(GEMS_LOCATION)
|
||||
real_gems_path = File.realpath(GEMS_LOCATION)
|
||||
if !defined?(Gem) || Gem.path != [real_gems_path]
|
||||
$LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
|
||||
|
||||
# Suppress warnings from Rubygems
|
||||
# https://github.com/OpenNebula/one/issues/5379
|
||||
begin
|
||||
verb = $VERBOSE
|
||||
$VERBOSE = nil
|
||||
require 'rubygems'
|
||||
Gem.use_paths(real_gems_path)
|
||||
ensure
|
||||
$VERBOSE = verb
|
||||
end
|
||||
end
|
||||
end
|
||||
# %%RUBYGEMS_SETUP_END%%
|
||||
|
||||
$LOAD_PATH << RUBY_LIB_LOCATION
|
||||
|
||||
require 'rexml/document'
|
||||
|
||||
require_relative '../lib/tm_action'
|
||||
require_relative '../lib/kvm'
|
||||
require_relative '../lib/datastore'
|
||||
|
||||
if LIVE
|
||||
# TODO: fsfreeze for each hypervisor based on VM_MAD
|
||||
include TransferManager::KVM
|
||||
end
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# BACKUP tm_mad host:remote_dir DISK_ID:...:DISK_ID deploy_id bjid vmid dsid
|
||||
#-------------------------------------------------------------------------------
|
||||
TransferManager::Datastore.load_env
|
||||
|
||||
vm_xml = STDIN.read
|
||||
|
||||
dir = ARGV[0].split ':'
|
||||
disks = ARGV[1].split ':'
|
||||
deploy_id = ARGV[2]
|
||||
_bjid = ARGV[3]
|
||||
vmid = ARGV[4]
|
||||
_dsid = ARGV[5]
|
||||
|
||||
rhost = dir[0]
|
||||
rdir = dir[1]
|
||||
|
||||
xml_doc = REXML::Document.new(vm_xml)
|
||||
vm = xml_doc.root
|
||||
|
||||
ds = TransferManager::Datastore.from_vm_backup_ds(:vm_xml => vm_xml)
|
||||
|
||||
base_path = ENV['BACKUP_BASE_PATH']
|
||||
|
||||
bck_dir = if base_path
|
||||
"#{base_path}/#{vmid}/backup"
|
||||
else
|
||||
"#{rdir}/backup"
|
||||
end
|
||||
|
||||
snap_cmd = ''
|
||||
expo_cmd = ''
|
||||
clup_cmd = ''
|
||||
|
||||
vm.elements.each 'TEMPLATE/DISK' do |d|
|
||||
did = d.elements['DISK_ID'].text
|
||||
next unless disks.include? did
|
||||
|
||||
src = d.elements['SOURCE'].text
|
||||
clon = d.elements['CLONE'].text
|
||||
|
||||
src_image = if clon == 'NO' then src else "#{src}-#{vmid}-#{did}" end
|
||||
|
||||
cmd = 'vitastor-cli'
|
||||
qemu_arg = ''
|
||||
if d.elements['VITASTOR_CONF']
|
||||
cmd = cmd + ' --config_path ' + d.elements['VITASTOR_CONF']
|
||||
qemu_arg += 'config_path='+d.elements['VITASTOR_CONF']+':'
|
||||
end
|
||||
|
||||
draw = "#{bck_dir}/disk.#{did}.raw"
|
||||
ddst = "#{bck_dir}/disk.#{did}.0"
|
||||
|
||||
expo_cmd << ds.cmd_confinement("qemu-img convert -m 4 -O qcow2 'vitastor:#{qemu_arg}image=#{src_image}' #{ddst}\n", rdir)
|
||||
|
||||
clup_cmd << "rm -f #{draw}\n"
|
||||
rescue StandardError => e
|
||||
STDERR.puts "Missing configuration attributes in DISK: #{e.message}"
|
||||
exit(1)
|
||||
end
|
||||
|
||||
if LIVE
|
||||
freeze, thaw = fsfreeze(vm, deploy_id)
|
||||
end
|
||||
|
||||
script = <<~EOS
|
||||
set -ex -o pipefail
|
||||
|
||||
# Prepare backup folder
|
||||
[ -d #{bck_dir} ] && rm -rf #{bck_dir}
|
||||
|
||||
mkdir -p #{bck_dir}
|
||||
|
||||
echo "#{Base64.encode64(vm_xml)}" > #{bck_dir}/vm.xml
|
||||
|
||||
#{freeze}
|
||||
|
||||
#{snap_cmd}
|
||||
|
||||
#{thaw}
|
||||
|
||||
#{expo_cmd}
|
||||
|
||||
#{clup_cmd}
|
||||
EOS
|
||||
|
||||
rc = TransferManager::Action.ssh('prebackup_live',
|
||||
:host => rhost,
|
||||
:cmds => script,
|
||||
:nostdout => false,
|
||||
:nostderr => false
|
||||
)
|
||||
|
||||
if rc.code != 0
|
||||
STDERR.puts "Error preparing disk files: #{rc.stdout} #{rc.stderr}"
|
||||
end
|
||||
|
||||
exit(rc.code)
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Vitastor OpenNebula driver
|
||||
# Copyright (c) Vitaliy Filippov, 2024+
|
||||
# License: Apache-2.0 http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
export LIVE=1
|
||||
`dirname $0`/prebackup $@
|
||||
@@ -0,0 +1 @@
|
||||
../ceph/premigrate
|
||||
Executable
+81
@@ -0,0 +1,81 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Vitastor OpenNebula driver
|
||||
# Copyright (c) Vitaliy Filippov, 2024+
|
||||
# License: Apache-2.0 http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
# resize image size vmid
|
||||
|
||||
SRC=$1
|
||||
SIZE=$2
|
||||
VM_ID=$3
|
||||
|
||||
#--------------------------------------------------------------------------------
|
||||
|
||||
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
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Set dst path and dir
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
SRC_HOST=`arg_host $SRC`
|
||||
SRC_PATH=`arg_path $SRC`
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Get Image information
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
DISK_ID=$(echo "$SRC_PATH" | $AWK -F. '{print $NF}')
|
||||
|
||||
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]/SOURCE \
|
||||
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/VITASTOR_CONF \
|
||||
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/IMAGE_PREFIX \
|
||||
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/PERSISTENT)
|
||||
|
||||
SRC_IMAGE="${XPATH_ELEMENTS[j++]}"
|
||||
VITASTOR_CONF="${XPATH_ELEMENTS[j++]}"
|
||||
IMAGE_PREFIX="${XPATH_ELEMENTS[j++]}"
|
||||
PERSISTENT="${XPATH_ELEMENTS[j++]}"
|
||||
|
||||
if [ -n "${SRC_IMAGE}" ]; then
|
||||
if [ "${PERSISTENT}" != 'YES' ]; then
|
||||
SRC_IMAGE="${SRC_IMAGE}-${VM_ID}-${DISK_ID}"
|
||||
fi
|
||||
else
|
||||
SRC_IMAGE="${IMAGE_PREFIX}one-sys-${VM_ID}-${DISK_ID}"
|
||||
fi
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Resize disk
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
CLI=vitastor-cli
|
||||
if [ -n "$VITASTOR_CONF" ]; then
|
||||
CLI="$CLI --config_path ${VITASTOR_CONF}"
|
||||
fi
|
||||
|
||||
RESIZE_CMD=$(cat <<EOF
|
||||
$CLI modify --resize ${SIZE}M "$SRC_IMAGE"
|
||||
EOF
|
||||
)
|
||||
|
||||
ssh_exec_and_log "$SRC_HOST" "$RESIZE_CMD" "Error resizing disk $SRC_IMAGE"
|
||||
|
||||
exit 0
|
||||
Executable
+203
@@ -0,0 +1,203 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# Vitastor OpenNebula driver
|
||||
# Copyright (c) Vitaliy Filippov, 2024+
|
||||
# License: Apache-2.0 http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
ONE_LOCATION = ENV['ONE_LOCATION']
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION = '/usr/lib/one/ruby'
|
||||
GEMS_LOCATION = '/usr/share/one/gems'
|
||||
VMDIR = '/var/lib/one'
|
||||
CONFIG_FILE = '/var/lib/one/config'
|
||||
else
|
||||
RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby'
|
||||
GEMS_LOCATION = ONE_LOCATION + '/share/gems'
|
||||
VMDIR = ONE_LOCATION + '/var'
|
||||
CONFIG_FILE = ONE_LOCATION + '/var/config'
|
||||
end
|
||||
|
||||
# %%RUBYGEMS_SETUP_BEGIN%%
|
||||
if File.directory?(GEMS_LOCATION)
|
||||
real_gems_path = File.realpath(GEMS_LOCATION)
|
||||
if !defined?(Gem) || Gem.path != [real_gems_path]
|
||||
$LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
|
||||
|
||||
# Suppress warnings from Rubygems
|
||||
# https://github.com/OpenNebula/one/issues/5379
|
||||
begin
|
||||
verb = $VERBOSE
|
||||
$VERBOSE = nil
|
||||
require 'rubygems'
|
||||
Gem.use_paths(real_gems_path)
|
||||
ensure
|
||||
$VERBOSE = verb
|
||||
end
|
||||
end
|
||||
end
|
||||
# %%RUBYGEMS_SETUP_END%%
|
||||
|
||||
$LOAD_PATH << RUBY_LIB_LOCATION
|
||||
|
||||
require 'rexml/document'
|
||||
require 'json'
|
||||
require 'securerandom'
|
||||
|
||||
require_relative '../lib/tm_action'
|
||||
require_relative '../lib/datastore'
|
||||
|
||||
def get_vitastor_disks(vm_xml)
|
||||
vm_xml = REXML::Document.new(vm_xml) if vm_xml.is_a?(String)
|
||||
vm = vm_xml.root
|
||||
vmid = vm.elements['VMID'].text
|
||||
|
||||
indexed_disks = []
|
||||
vm.elements.each('DISK[TM_MAD="vitastor"]') do |d|
|
||||
disk = new(vmid, d)
|
||||
indexed_disks[disk.id] = disk
|
||||
end
|
||||
|
||||
indexed_disks
|
||||
end
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# RESTORE vm_id img_id inc_id disk_id
|
||||
#-------------------------------------------------------------------------------
|
||||
_dir = ARGV[0].split ':'
|
||||
vm_id = ARGV[1]
|
||||
bk_img_id = ARGV[2].to_i
|
||||
inc_id = ARGV[3]
|
||||
disk_id = ARGV[4].to_i
|
||||
|
||||
begin
|
||||
action = TransferManager::Action.new(:action_name => 'restore',
|
||||
:vm_id => vm_id)
|
||||
# --------------------------------------------------------------------------
|
||||
# Image & Datastore information
|
||||
# --------------------------------------------------------------------------
|
||||
bk_img = OpenNebula::Image.new_with_id(bk_img_id, action.one)
|
||||
|
||||
rc = bk_img.info
|
||||
raise rc.message.to_s if OpenNebula.is_error?(rc)
|
||||
|
||||
bk_ds = TransferManager::Datastore.from_image_ds(:image => bk_img,
|
||||
:client => action.one)
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
# Backup information
|
||||
# sample output: {"0":"rsync://100//0:3ffce7/var/lib/one/datastores/100/1/3ffce7/disk.0.0"}
|
||||
# --------------------------------------------------------------------------
|
||||
xml_data = <<~EOS
|
||||
#{action.vm.to_xml}
|
||||
#{bk_img.to_xml}
|
||||
EOS
|
||||
|
||||
rc = bk_ds.action("ls -i #{inc_id}", xml_data)
|
||||
|
||||
raise 'cannot list backup contents' unless rc.code == 0
|
||||
|
||||
disk_urls = JSON.parse(rc.stdout)
|
||||
disk_urls = disk_urls.select {|id, _url| id.to_i == disk_id } if disk_id != -1
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
# Restore disk_urls in Host VM folder
|
||||
# --------------------------------------------------------------------------
|
||||
vitastor_disks = get_vitastor_disks(action.vm.template_xml)
|
||||
success_disks = []
|
||||
|
||||
info = {}
|
||||
|
||||
disk_urls.each do |id, url|
|
||||
vitastor_disk = vitastor_disks[id.to_i]
|
||||
randsuffix = SecureRandom.hex(5)
|
||||
|
||||
vitastor_one_ds = OpenNebula::Datastore.new_with_id(
|
||||
action.vm["/VM/TEMPLATE/DISK[DISK_ID = #{id}]/DATASTORE_ID"].to_i, action.one
|
||||
)
|
||||
vitastor_ds = TransferManager::Datastore.new(:ds => vitastor_one_ds, :client => action.one)
|
||||
|
||||
src_image = vitastor_disk.elements['SOURCE'].text
|
||||
disk_id = vitastor_disk.elements['DISK_ID'].text
|
||||
if vitastor_disk.elements['CLONE'].text == 'YES'
|
||||
src_image += '-'+vm_id+'-'+disk_id
|
||||
end
|
||||
|
||||
cli = 'vitastor-cli'
|
||||
config_path = vitastor_disk.elements['VITASTOR_CONF']
|
||||
qemu_args = ''
|
||||
if config_path:
|
||||
cli += ' --config_path "'+config_path.text+'"'
|
||||
qemu_args += ':config_path='+config_path.text
|
||||
|
||||
info[vitastor_disk] = {
|
||||
:br => vitastor_ds.pick_bridge,
|
||||
:bak => "#{src_image}.backup.#{randsuffix}",
|
||||
:old => "#{src_image}.old.#{randsuffix}",
|
||||
:cli => cli,
|
||||
:img => src_image,
|
||||
}
|
||||
|
||||
upload_vitastor = <<~EOS
|
||||
set -e
|
||||
tmpimg="$(mktemp -t disk#{id}.XXXX)"
|
||||
#{__dir__}/../../datastore/downloader.sh --nodecomp #{url} $tmpimg
|
||||
#{cli} create -s $(qemu-img info --output json $tmpimg | jq -r '.["virtual-size"]') #{info[vitastor_disk][:bak]}
|
||||
qemu-img convert -m 4 -O raw $tmpimg "vitastor:image=#{info[vitastor_disk][:bak]}#{qemu_args}"
|
||||
rm -f $tmpimg
|
||||
EOS
|
||||
|
||||
rc = action.ssh(:host => info[vitastor_disk][:br],
|
||||
:cmds => upload_ceph,
|
||||
:forward => false,
|
||||
:nostdout => false,
|
||||
:nostderr => false)
|
||||
|
||||
break if rc.code != 0
|
||||
|
||||
success_disks << vitastor_disk
|
||||
end
|
||||
|
||||
# Rollback and raise error if it was unable to backup all disks
|
||||
if success_disks.length != disk_urls.length
|
||||
success_disks.each do |vitastor_disk|
|
||||
cleanup = <<~EOS
|
||||
#{info[vitastor_disk][:cli]} rm #{info[vitastor_disk][:bak]}
|
||||
EOS
|
||||
|
||||
action.ssh(:host => info[vitastor_disk][:br],
|
||||
:cmds => cleanup,
|
||||
:forward => false,
|
||||
:nostdout => false,
|
||||
:nostderr => false)
|
||||
end
|
||||
|
||||
raise "error uploading backup disk to Vitastor (#{success_disks.length}/#{disk_urls.length})"
|
||||
end
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
# Replace VM disk_urls with backup copies (~prolog)
|
||||
# --------------------------------------------------------------------------
|
||||
success_disks.each do |vitastor_disk|
|
||||
move = <<~EOS
|
||||
set -e
|
||||
#{info[vitastor_disk][:cli]} mv #{info[vitastor_disk][:img]} #{info[vitastor_disk][:old]};
|
||||
#{info[vitastor_disk][:cli]} mv #{info[vitastor_disk][:bak]} #{info[vitastor_disk][:img]};
|
||||
for i in $(#{info[vitastor_disk][:cli]} ls --json "#{info[vitastor_disk][:img]}@*"); do
|
||||
#{info[vitastor_disk][:cli]} rm "$i"
|
||||
done
|
||||
#{info[vitastor_disk][:cli]} rm #{info[vitastor_disk][:old]}
|
||||
EOS
|
||||
|
||||
rc = action.ssh(:host => info[vitastor_disk][:br],
|
||||
:cmds => move,
|
||||
:forward => false,
|
||||
:nostdout => false,
|
||||
:nostderr => false)
|
||||
|
||||
warn 'cannot restore disk backup' if rc.code != 0
|
||||
end
|
||||
rescue StandardError => e
|
||||
STDERR.puts "Error restoring VM disks: #{e.message}"
|
||||
exit(1)
|
||||
end
|
||||
Executable
+78
@@ -0,0 +1,78 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Vitastor OpenNebula driver
|
||||
# Copyright (c) Vitaliy Filippov, 2024+
|
||||
# License: Apache-2.0 http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
# snap_create host:parent_image snap_id vmid ds_id
|
||||
|
||||
SRC=$1
|
||||
SNAP_ID=$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
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Set dst path and dir
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
SRC_HOST=`arg_host $SRC`
|
||||
SRC_PATH=`arg_path $SRC`
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Get Image information
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
DISK_ID=$(echo "$SRC_PATH" | $AWK -F. '{print $NF}')
|
||||
|
||||
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]/SOURCE \
|
||||
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/CLONE \
|
||||
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/VITASTOR_CONF \
|
||||
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/TYPE )
|
||||
|
||||
SRC_IMAGE="${XPATH_ELEMENTS[j++]}"
|
||||
CLONE="${XPATH_ELEMENTS[j++]}"
|
||||
VITASTOR_CONF="${XPATH_ELEMENTS[j++]}"
|
||||
TYPE="${XPATH_ELEMENTS[j++]}"
|
||||
|
||||
if [ "$CLONE" = "YES" ]; then
|
||||
SRC_IMAGE="${SRC_IMAGE}-${VM_ID}-${DISK_ID}"
|
||||
fi
|
||||
|
||||
CLI=vitastor-cli
|
||||
if [ -n "$VITASTOR_CONF" ]; then
|
||||
CLI="$CLI --config_path ${VITASTOR_CONF}"
|
||||
fi
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Create snapshots
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
SNAP_CREATE_CMD=$(cat <<EOF
|
||||
$CLI snap-create "$SRC_IMAGE@$SNAP_ID"
|
||||
EOF
|
||||
)
|
||||
|
||||
ssh_exec_and_log "$SRC_HOST" "$SNAP_CREATE_CMD" "Error creating snapshot $SRC_IMAGE@$SNAP_ID"
|
||||
|
||||
exit 0
|
||||
@@ -0,0 +1 @@
|
||||
snap_create
|
||||
Executable
+75
@@ -0,0 +1,75 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Vitastor OpenNebula driver
|
||||
# Copyright (c) Vitaliy Filippov, 2024+
|
||||
# License: Apache-2.0 http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
# snap_delete host:parent_image snap_id vmid ds_id
|
||||
|
||||
SRC=$1
|
||||
SNAP_ID=$2
|
||||
VM_ID=$3
|
||||
DS_ID=$4
|
||||
|
||||
# FIXME: copypaste below, down to "delete snapshot"
|
||||
#--------------------------------------------------------------------------------
|
||||
|
||||
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
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Set dst path and dir
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
SRC_HOST=`arg_host $SRC`
|
||||
SRC_PATH=`arg_path $SRC`
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Get Image information
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
DISK_ID=$(echo "$SRC_PATH" | $AWK -F. '{print $NF}')
|
||||
|
||||
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]/SOURCE \
|
||||
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/CLONE \
|
||||
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/VITASTOR_CONF )
|
||||
|
||||
SRC_IMAGE="${XPATH_ELEMENTS[j++]}"
|
||||
CLONE="${XPATH_ELEMENTS[j++]}"
|
||||
VITASTOR_CONF="${XPATH_ELEMENTS[j++]}"
|
||||
|
||||
if [ "$CLONE" = "YES" ]; then
|
||||
SRC_IMAGE="${SRC_IMAGE}-${VM_ID}-${DISK_ID}"
|
||||
fi
|
||||
|
||||
CLI=vitastor-cli
|
||||
if [ -n "$VITASTOR_CONF" ]; then
|
||||
CLI="$CLI --config_path ${VITASTOR_CONF}"
|
||||
fi
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Delete snapshot
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
SNAP_DELETE_CMD=$(cat <<EOF
|
||||
$CLI rm "$SRC_IMAGE@$SNAP_ID"
|
||||
EOF
|
||||
)
|
||||
|
||||
ssh_exec_and_log "$SRC_HOST" "$SNAP_DELETE_CMD" "Error deleting snapshot $SRC_IMAGE@$SNAP_ID"
|
||||
Executable
+79
@@ -0,0 +1,79 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Vitastor OpenNebula driver
|
||||
# Copyright (c) Vitaliy Filippov, 2024+
|
||||
# License: Apache-2.0 http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
# snap_revert host:parent_image snap_id vmid ds_id
|
||||
|
||||
SRC=$1
|
||||
SNAP_ID=$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
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Set dst path and dir
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
SRC_HOST=`arg_host $SRC`
|
||||
SRC_PATH=`arg_path $SRC`
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Get Image information
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
DISK_ID=$(echo "$SRC_PATH" | $AWK -F. '{print $NF}')
|
||||
|
||||
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]/SOURCE \
|
||||
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/CLONE \
|
||||
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/VITASTOR_CONF \
|
||||
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/TYPE )
|
||||
|
||||
SRC_IMAGE="${XPATH_ELEMENTS[j++]}"
|
||||
CLONE="${XPATH_ELEMENTS[j++]}"
|
||||
VITASTOR_CONF="${XPATH_ELEMENTS[j++]}"
|
||||
TYPE="${XPATH_ELEMENTS[j++]}"
|
||||
|
||||
if [ "$CLONE" = "YES" ]; then
|
||||
SRC_IMAGE="${SRC_IMAGE}-${VM_ID}-${DISK_ID}"
|
||||
fi
|
||||
|
||||
CLI=vitastor-cli
|
||||
if [ -n "$VITASTOR_CONF" ]; then
|
||||
CLI="$CLI --config_path ${VITASTOR_CONF}"
|
||||
fi
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Revert to snapshot (== remove current image and recreate it as a clone)
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
SNAP_REVERT_CMD=$(cat <<EOF
|
||||
set -e
|
||||
$CLI ls --json "$SRC_IMAGE@$SNAP_ID" | jq -s -e '[ .[][] | select(.name == "$SRC_IMAGE@$SNAP_ID") ] | length > 0'
|
||||
$CLI rm "$SRC_IMAGE" || true
|
||||
$CLI create --parent "$SRC_IMAGE@$SNAP_ID" "$SRC_IMAGE"
|
||||
EOF
|
||||
)
|
||||
|
||||
ssh_exec_and_log "$SRC_HOST" "$SNAP_REVERT_CMD" "Error reverting snapshot $SNAP_ID for $SRC_IMAGE"
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Vitastor OpenNebula driver
|
||||
# Copyright (c) Vitaliy Filippov, 2024+
|
||||
# License: Apache-2.0 http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
DRIVER_PATH=$(dirname $0)
|
||||
DEP_FILE=$1
|
||||
DEP_FILE_LOCATION=$(dirname $DEP_FILE)
|
||||
|
||||
cat > $DEP_FILE
|
||||
|
||||
python3 $DRIVER_PATH/deploy_vitastor.py $DEP_FILE $DEP_FILE_LOCATION/vm.xml
|
||||
|
||||
cat $DEP_FILE | $DRIVER_PATH/deploy $@
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Vitastor OpenNebula driver
|
||||
# Copyright (c) Vitaliy Filippov, 2024+
|
||||
# License: Apache-2.0 http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
import base64
|
||||
from sys import argv, stderr
|
||||
from xml.etree import ElementTree as ET
|
||||
|
||||
dep_file = argv[1]
|
||||
with open(dep_file, 'rb') as fd:
|
||||
dep_txt = base64.b64decode(fd.read())
|
||||
dep = ET.fromstring(dep_txt)
|
||||
|
||||
vm_file = argv[2]
|
||||
with open(vm_file, 'rb') as fd:
|
||||
vm_txt = base64.b64decode(fd.read())
|
||||
vm = ET.fromstring(vm_txt)
|
||||
|
||||
ET.register_namespace('qemu', 'http://libvirt.org/schemas/domain/qemu/1.0')
|
||||
ET.register_namespace('one', 'http://opennebula.org/xmlns/libvirt/1.0')
|
||||
|
||||
vm_id = vm.find('./ID').text
|
||||
context_disk_id = vm.find('./TEMPLATE/CONTEXT/DISK_ID').text
|
||||
changed = 0
|
||||
txt = lambda x: '' if x is None else x.text
|
||||
|
||||
for disk in dep.findall('./devices/disk[@type="file"]'):
|
||||
try:
|
||||
disk_id = disk.find('./source').attrib['file'].split('.')[-1]
|
||||
vm_disk = vm.find('./TEMPLATE/DISK[DISK_ID="{}"]'.format(disk_id))
|
||||
if vm_disk is None:
|
||||
continue
|
||||
tm_mad = txt(vm_disk.find('./TM_MAD'))
|
||||
if tm_mad != 'vitastor':
|
||||
continue
|
||||
src_image = txt(vm_disk.find('./SOURCE'))
|
||||
clone = txt(vm_disk.find('./CLONE'))
|
||||
vitastor_conf = txt(vm_disk.find('./VITASTOR_CONF'))
|
||||
if clone == "YES":
|
||||
src_image += "-"+vm_id+"-"+disk_id
|
||||
# modify
|
||||
changed = 1
|
||||
disk.attrib['type'] = 'network'
|
||||
disk.remove(disk.find('./source'))
|
||||
src = ET.SubElement(disk, 'source')
|
||||
src.attrib['protocol'] = 'vitastor'
|
||||
src.attrib['name'] = src_image
|
||||
if vitastor_conf:
|
||||
# path to config should be added to /etc/apparmor.d/local/abstractions/libvirt-qemu
|
||||
config = ET.SubElement(src, 'config')
|
||||
config.text = vitastor_conf
|
||||
except Exception as e:
|
||||
print("Error: {}".format(e), file=stderr)
|
||||
|
||||
if changed:
|
||||
ET.ElementTree(dep).write(dep_file)
|
||||
Executable
+37
@@ -0,0 +1,37 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Vitastor OpenNebula driver
|
||||
# Copyright (c) Vitaliy Filippov, 2024+
|
||||
# License: Apache-2.0 http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
DRIVER_PATH=$(dirname $0)
|
||||
|
||||
source $DRIVER_PATH/../../etc/vmm/kvm/kvmrc
|
||||
source $DRIVER_PATH/../../scripts_common.sh
|
||||
|
||||
FILE=$1
|
||||
HOST=$2
|
||||
DEPLOY_ID=$3
|
||||
VM_ID=$4
|
||||
DS_ID=$5
|
||||
|
||||
XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin"
|
||||
|
||||
while IFS= read -r -d '' element; do
|
||||
XPATH_ELEMENTS[i++]="$element"
|
||||
done < <($XPATH \
|
||||
/VMM_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/VITASTOR_CONF \
|
||||
/VMM_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/IMAGE_PREFIX)
|
||||
|
||||
VITASTOR_CONF="${XPATH_ELEMENTS[j++]}"
|
||||
IMAGE_PREFIX="${XPATH_ELEMENTS[j++]}"
|
||||
|
||||
CLI=vitastor-cli
|
||||
if [ -n "$VITASTOR_CONF" ]; then
|
||||
CLI="$CLI --config_path $VITASTOR_CONF"
|
||||
fi
|
||||
|
||||
SRC_IMAGE="${IMAGE_PREFIX}one-sys-${VM_ID}-checkpoint"
|
||||
|
||||
exec_and_log "$CLI dd iimg=$SRC_IMAGE of=$FILE" "Error exporting checkpoint into from $SRC_IMAGE to $FILE"
|
||||
exec_and_log "$CLI rm $SRC_IMAGE" "Error removing checkpoint $SRC_IMAGE"
|
||||
Executable
+45
@@ -0,0 +1,45 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Vitastor OpenNebula driver
|
||||
# Copyright (c) Vitaliy Filippov, 2024+
|
||||
# License: Apache-2.0 http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
DRIVER_PATH=$(dirname $0)
|
||||
|
||||
source $DRIVER_PATH/../../etc/vmm/kvm/kvmrc
|
||||
source $DRIVER_PATH/../../scripts_common.sh
|
||||
|
||||
DEPLOY_ID=$1
|
||||
FILE=$2
|
||||
VM_ID=$4
|
||||
DS_ID=$5
|
||||
|
||||
XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin"
|
||||
|
||||
unset i j XPATH_ELEMENTS
|
||||
|
||||
while IFS= read -r -d '' element; do
|
||||
XPATH_ELEMENTS[i++]="$element"
|
||||
done < <($XPATH \
|
||||
/VMM_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/VITASTOR_CONF \
|
||||
/VMM_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/IMAGE_PREFIX \
|
||||
/VMM_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/POOL_NAME)
|
||||
|
||||
VITASTOR_CONF="${XPATH_ELEMENTS[j++]}"
|
||||
IMAGE_PREFIX="${XPATH_ELEMENTS[j++]}"
|
||||
POOL_NAME="${XPATH_ELEMENTS[j++]}"
|
||||
|
||||
CLI=vitastor-cli
|
||||
if [ -n "$VITASTOR_CONF" ]; then
|
||||
CLI="$CLI --config_path ${VITASTOR_CONF}"
|
||||
fi
|
||||
if [ -n "$POOL_NAME" ]; then
|
||||
CLI="$CLI --pool ${POOL_NAME}"
|
||||
fi
|
||||
|
||||
DST_IMAGE="${IMAGE_PREFIX}one-sys-${VM_ID}-checkpoint"
|
||||
|
||||
exec_and_log "$CLI dd if=$FILE oimg=$DST_IMAGE" "Error importing checkpoint into $DST_IMAGE"
|
||||
exec_and_log "$RM -f $FILE" "Error removing checkpoint ($FILE)"
|
||||
|
||||
exit 0
|
||||
@@ -0,0 +1 @@
|
||||
oneadmin ALL=(ALL) NOPASSWD: /usr/bin/vitastor-nbd
|
||||
@@ -0,0 +1,9 @@
|
||||
NAME = "Vitastor Images"
|
||||
DS_MAD = "vitastor"
|
||||
TM_MAD = "vitastor"
|
||||
TYPE = "IMAGE_DS"
|
||||
DISK_TYPE = "file"
|
||||
BRIDGE_LIST = "opennebula1"
|
||||
POOL_NAME = "test1"
|
||||
IMAGE_PREFIX = "my"
|
||||
STAGING_DIR = /var/tmp
|
||||
@@ -0,0 +1,6 @@
|
||||
NAME = "Vitastor System"
|
||||
TM_MAD = "vitastor"
|
||||
TYPE = "SYSTEM_DS"
|
||||
BRIDGE_LIST = "opennebula1"
|
||||
POOL_NAME = "test1"
|
||||
IMAGE_PREFIX = "my"
|
||||
@@ -43,5 +43,5 @@ RUN set -e; \
|
||||
rpmbuild -ba vitastor.spec; \
|
||||
mkdir -p /root/packages/vitastor-el7; \
|
||||
rm -rf /root/packages/vitastor-el7/*; \
|
||||
cp ~/rpmbuild/RPMS/*/vitastor* /root/packages/vitastor-el7/; \
|
||||
cp ~/rpmbuild/RPMS/*/*vitastor* /root/packages/vitastor-el7/; \
|
||||
cp ~/rpmbuild/SRPMS/vitastor* /root/packages/vitastor-el7/
|
||||
|
||||
@@ -89,6 +89,19 @@ Requires: fio = 3.7-1.el7
|
||||
Vitastor fio drivers for benchmarking.
|
||||
|
||||
|
||||
%package -n opennebula-vitastor
|
||||
Summary: Vitastor for OpenNebula
|
||||
Group: Development/Libraries
|
||||
Requires: vitastor-client
|
||||
Requires: jq
|
||||
Requires: python3-lxml
|
||||
Requires: patch
|
||||
|
||||
|
||||
%description -n opennebula-vitastor
|
||||
Vitastor storage plugin for OpenNebula.
|
||||
|
||||
|
||||
%prep
|
||||
%setup -q
|
||||
|
||||
@@ -113,6 +126,11 @@ mkdir -p %buildroot/lib/systemd/system
|
||||
cp mon/scripts/vitastor.target mon/scripts/vitastor-mon.service mon/scripts/vitastor-osd@.service %buildroot/lib/systemd/system
|
||||
mkdir -p %buildroot/lib/udev/rules.d
|
||||
cp mon/scripts/90-vitastor.rules %buildroot/lib/udev/rules.d
|
||||
mkdir -p %buildroot/var/lib/one
|
||||
cp -r opennebula/remotes %buildroot/var/lib/one
|
||||
cp opennebula/install.sh %buildroot/var/lib/one/remotes/datastore/vitastor/
|
||||
mkdir -p %buildroot/etc/
|
||||
cp -r opennebula/sudoers.d %buildroot/etc/
|
||||
|
||||
|
||||
%files
|
||||
@@ -173,4 +191,14 @@ chown vitastor:vitastor /var/lib/vitastor
|
||||
%_libdir/libfio_vitastor_sec.so
|
||||
|
||||
|
||||
%files -n opennebula-vitastor
|
||||
/var/lib/one
|
||||
/etc/sudoers.d/opennebula-vitastor
|
||||
|
||||
|
||||
%triggerin -n opennebula-vitastor -- opennebula
|
||||
[ $2 = 0 ] || exit 0
|
||||
/var/lib/one/remotes/datastore/vitastor/install.sh
|
||||
|
||||
|
||||
%changelog
|
||||
|
||||
@@ -42,5 +42,5 @@ RUN set -e; \
|
||||
rpmbuild -ba vitastor.spec; \
|
||||
mkdir -p /root/packages/vitastor-el8; \
|
||||
rm -rf /root/packages/vitastor-el8/*; \
|
||||
cp ~/rpmbuild/RPMS/*/vitastor* /root/packages/vitastor-el8/; \
|
||||
cp ~/rpmbuild/RPMS/*/*vitastor* /root/packages/vitastor-el8/; \
|
||||
cp ~/rpmbuild/SRPMS/vitastor* /root/packages/vitastor-el8/
|
||||
|
||||
@@ -87,6 +87,19 @@ Requires: fio = 3.7-3.el8
|
||||
Vitastor fio drivers for benchmarking.
|
||||
|
||||
|
||||
%package -n opennebula-vitastor
|
||||
Summary: Vitastor for OpenNebula
|
||||
Group: Development/Libraries
|
||||
Requires: vitastor-client
|
||||
Requires: jq
|
||||
Requires: python3-lxml
|
||||
Requires: patch
|
||||
|
||||
|
||||
%description -n opennebula-vitastor
|
||||
Vitastor storage plugin for OpenNebula.
|
||||
|
||||
|
||||
%prep
|
||||
%setup -q
|
||||
|
||||
@@ -110,6 +123,11 @@ mkdir -p %buildroot/lib/systemd/system
|
||||
cp mon/scripts/vitastor.target mon/scripts/vitastor-mon.service mon/scripts/vitastor-osd@.service %buildroot/lib/systemd/system
|
||||
mkdir -p %buildroot/lib/udev/rules.d
|
||||
cp mon/scripts/90-vitastor.rules %buildroot/lib/udev/rules.d
|
||||
mkdir -p %buildroot/var/lib/one
|
||||
cp -r opennebula/remotes %buildroot/var/lib/one
|
||||
cp opennebula/install.sh %buildroot/var/lib/one/remotes/datastore/vitastor/
|
||||
mkdir -p %buildroot/etc/
|
||||
cp -r opennebula/sudoers.d %buildroot/etc/
|
||||
|
||||
|
||||
%files
|
||||
@@ -170,4 +188,14 @@ chown vitastor:vitastor /var/lib/vitastor
|
||||
%_libdir/libfio_vitastor_sec.so
|
||||
|
||||
|
||||
%files -n opennebula-vitastor
|
||||
/var/lib/one
|
||||
/etc/sudoers.d/opennebula-vitastor
|
||||
|
||||
|
||||
%triggerin -n opennebula-vitastor -- opennebula
|
||||
[ $2 = 0 ] || exit 0
|
||||
/var/lib/one/remotes/datastore/vitastor/install.sh
|
||||
|
||||
|
||||
%changelog
|
||||
|
||||
@@ -25,5 +25,5 @@ RUN set -e; \
|
||||
rpmbuild -ba vitastor.spec; \
|
||||
mkdir -p /root/packages/vitastor-el9; \
|
||||
rm -rf /root/packages/vitastor-el9/*; \
|
||||
cp ~/rpmbuild/RPMS/*/vitastor* /root/packages/vitastor-el9/; \
|
||||
cp ~/rpmbuild/RPMS/*/*vitastor* /root/packages/vitastor-el9/; \
|
||||
cp ~/rpmbuild/SRPMS/vitastor* /root/packages/vitastor-el9/
|
||||
|
||||
@@ -81,6 +81,19 @@ Requires: fio = 3.27-8.el9
|
||||
Vitastor fio drivers for benchmarking.
|
||||
|
||||
|
||||
%package -n opennebula-vitastor
|
||||
Summary: Vitastor for OpenNebula
|
||||
Group: Development/Libraries
|
||||
Requires: vitastor-client
|
||||
Requires: jq
|
||||
Requires: python3-lxml
|
||||
Requires: patch
|
||||
|
||||
|
||||
%description -n opennebula-vitastor
|
||||
Vitastor storage plugin for OpenNebula.
|
||||
|
||||
|
||||
%prep
|
||||
%setup -q
|
||||
|
||||
@@ -103,6 +116,11 @@ mkdir -p %buildroot/lib/systemd/system
|
||||
cp mon/scripts/vitastor.target mon/scripts/vitastor-mon.service mon/scripts/vitastor-osd@.service %buildroot/lib/systemd/system
|
||||
mkdir -p %buildroot/lib/udev/rules.d
|
||||
cp mon/scripts/90-vitastor.rules %buildroot/lib/udev/rules.d
|
||||
mkdir -p %buildroot/var/lib/one
|
||||
cp -r opennebula/remotes %buildroot/var/lib/one
|
||||
cp opennebula/install.sh %buildroot/var/lib/one/remotes/datastore/vitastor/
|
||||
mkdir -p %buildroot/etc/
|
||||
cp -r opennebula/sudoers.d %buildroot/etc/
|
||||
|
||||
|
||||
%files
|
||||
@@ -163,4 +181,14 @@ chown vitastor:vitastor /var/lib/vitastor
|
||||
%_libdir/libfio_vitastor_sec.so
|
||||
|
||||
|
||||
%files -n opennebula-vitastor
|
||||
/var/lib/one
|
||||
/etc/sudoers.d/opennebula-vitastor
|
||||
|
||||
|
||||
%triggerin -n opennebula-vitastor -- opennebula
|
||||
[ $2 = 0 ] || exit 0
|
||||
/var/lib/one/remotes/datastore/vitastor/install.sh
|
||||
|
||||
|
||||
%changelog
|
||||
|
||||
Reference in New Issue
Block a user