Implement OpenNebula driver
This commit is contained in:
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
|
||||
Reference in New Issue
Block a user