Merge "devstack: allow creating more than one volume for a VM"

This commit is contained in:
Zuul 2019-08-09 17:48:08 +00:00 committed by Gerrit Code Review
commit 007c7babb9
4 changed files with 39 additions and 17 deletions

View File

@ -147,6 +147,7 @@ IRONIC_VM_EMULATOR=${IRONIC_VM_EMULATOR:-'/usr/bin/qemu-system-x86_64'}
IRONIC_VM_ENGINE=${IRONIC_VM_ENGINE:-qemu}
IRONIC_VM_NETWORK_BRIDGE=${IRONIC_VM_NETWORK_BRIDGE:-brbm}
IRONIC_VM_INTERFACE_COUNT=${IRONIC_VM_INTERFACE_COUNT:-2}
IRONIC_VM_VOLUME_COUNT=${IRONIC_VM_VOLUME_COUNT:-1}
IRONIC_VM_MACS_CSV_FILE=${IRONIC_VM_MACS_CSV_FILE:-$IRONIC_DATA_DIR/ironic_macs.csv}
IRONIC_CLEAN_NET_NAME=${IRONIC_CLEAN_NET_NAME:-${IRONIC_PROVISION_NETWORK_NAME:-${PRIVATE_NETWORK_NAME}}}
IRONIC_RESCUE_NET_NAME=${IRONIC_RESCUE_NET_NAME:-${IRONIC_CLEAN_NET_NAME}}
@ -1812,7 +1813,8 @@ function create_bridge_and_vms {
$IRONIC_SCRIPTS_DIR/create-node.sh -n $vm_name \
-c $IRONIC_VM_SPECS_CPU -m $IRONIC_VM_SPECS_RAM -d $IRONIC_VM_SPECS_DISK \
-a $IRONIC_VM_SPECS_CPU_ARCH -b $IRONIC_VM_NETWORK_BRIDGE $vm_opts -p $vbmc_port -o $pdu_outlet \
-i $IRONIC_VM_INTERFACE_COUNT -f $IRONIC_VM_SPECS_DISK_FORMAT -M $PUBLIC_BRIDGE_MTU $log_arg >> $IRONIC_VM_MACS_CSV_FILE
-i $IRONIC_VM_INTERFACE_COUNT -f $IRONIC_VM_SPECS_DISK_FORMAT -M $PUBLIC_BRIDGE_MTU $log_arg \
-v $IRONIC_VM_VOLUME_COUNT >> $IRONIC_VM_MACS_CSV_FILE
SUBSHELL
if is_deployed_by_ipmi; then

View File

@ -15,6 +15,8 @@
import argparse
import os.path
import string
import sys
import jinja2
import libvirt
@ -57,7 +59,7 @@ def main():
description="Configure a kvm virtual machine for the seed image.")
parser.add_argument('--name', default='seed',
help='the name to give the machine in libvirt.')
parser.add_argument('--image',
parser.add_argument('--image', action='append', default=[],
help='Use a custom image file (must be qcow2).')
parser.add_argument('--engine', default='qemu',
help='The virtualization engine to use')
@ -92,9 +94,14 @@ def main():
env = jinja2.Environment(loader=jinja2.FileSystemLoader(templatedir))
template = env.get_template('vm.xml')
images = list(zip(args.image, string.ascii_lowercase))
if not images or len(images) > 6:
# 6 is an artificial limitation because of the way we generate PCI IDs
sys.exit("Up to 6 images are required")
params = {
'name': args.name,
'imagefile': args.image,
'images': images,
'engine': args.engine,
'arch': args.arch,
'memory': args.memory,

View File

@ -12,7 +12,7 @@ export PS4='+ ${BASH_SOURCE:-}:${FUNCNAME[0]:-}:L${LINENO:-}: '
# Keep track of the DevStack directory
TOP_DIR=$(cd $(dirname "$0")/.. && pwd)
while getopts "n:c:i:m:M:d:a:b:e:E:p:o:f:l:L:N:A:D:" arg; do
while getopts "n:c:i:m:M:d:a:b:e:E:p:o:f:l:L:N:A:D:v:" arg; do
case $arg in
n) NAME=$OPTARG;;
c) CPU=$OPTARG;;
@ -34,6 +34,7 @@ while getopts "n:c:i:m:M:d:a:b:e:E:p:o:f:l:L:N:A:D:" arg; do
N) UEFI_NVRAM=$OPTARG;;
A) MAC_ADDRESS=$OPTARG;;
D) NIC_DRIVER=$OPTARG;;
v) VOLUME_COUNT=$OPTARG;;
esac
done
@ -76,7 +77,6 @@ if [ -n "$LOGDIR" ] ; then
else
VM_LOGGING=""
fi
VOL_NAME="${NAME}.${DISK_FORMAT}"
UEFI_OPTS=""
if [ ! -z "$UEFI_LOADER" ]; then
@ -111,20 +111,31 @@ if [ -n "$MAC_ADDRESS" ] ; then
MAC_ADDRESS="--mac $MAC_ADDRESS"
fi
VOLUME_COUNT=${VOLUME_COUNT:-1}
if ! virsh list --all | grep -q $NAME; then
virsh vol-list --pool $LIBVIRT_STORAGE_POOL | grep -q $VOL_NAME &&
virsh vol-delete $VOL_NAME --pool $LIBVIRT_STORAGE_POOL >&2
virsh vol-create-as $LIBVIRT_STORAGE_POOL ${VOL_NAME} ${DISK}G --format $DISK_FORMAT $PREALLOC >&2
volume_path=$(virsh vol-path --pool $LIBVIRT_STORAGE_POOL $VOL_NAME)
# Pre-touch the VM to set +C, as it can only be set on empty files.
sudo touch "$volume_path"
sudo chattr +C "$volume_path" || true
vm_opts=""
for int in $(seq 1 $VOLUME_COUNT); do
if [[ "$int" == "1" ]]; then
# Compatibility with old naming
vol_name="$NAME.$DISK_FORMAT"
else
vol_name="$NAME-$int.$DISK_FORMAT"
fi
virsh vol-list --pool $LIBVIRT_STORAGE_POOL | grep -q $vol_name &&
virsh vol-delete $vol_name --pool $LIBVIRT_STORAGE_POOL >&2
virsh vol-create-as $LIBVIRT_STORAGE_POOL ${vol_name} ${DISK}G --format $DISK_FORMAT $PREALLOC >&2
volume_path=$(virsh vol-path --pool $LIBVIRT_STORAGE_POOL $vol_name)
# Pre-touch the VM to set +C, as it can only be set on empty files.
sudo touch "$volume_path"
sudo chattr +C "$volume_path" || true
vm_opts+="--image $volume_path "
done
if [[ -n "$EMULATOR" ]]; then
vm_opts+="--emulator $EMULATOR "
fi
$PYTHON $TOP_DIR/scripts/configure-vm.py \
--bootdev network --name $NAME --image "$volume_path" \
--bootdev network --name $NAME \
--arch $ARCH --cpus $CPU --memory $MEM --libvirt-nic-driver $LIBVIRT_NIC_DRIVER \
--disk-format $DISK_FORMAT $VM_LOGGING --engine $ENGINE $UEFI_OPTS $vm_opts \
--interface-count $INTERFACE_COUNT $MAC_ADDRESS >&2

View File

@ -30,19 +30,21 @@
<on_crash>restart</on_crash>
<devices>
<emulator>{{ emulator }}</emulator>
{% for (imagefile, letter) in images %}
<disk type='file' device='disk'>
<driver name='qemu' type='{{ disk_format }}' cache='writeback'/>
<source file='{{ imagefile }}'/>
<!-- NOTE(lucasagomes): The virtio disk controller apparently does
not work with UEFI, so let's use IDE. -->
{% if uefi_loader %}
<target dev='vda' bus='ide'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
<target dev='vd{{ letter }}' bus='ide'/>
<address type='drive' controller='0' bus='0' target='0' unit='{{ loop.index }}'/>
{% else %}
<target dev='vda' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
<target dev='vd{{ letter }}' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x0{{ letter }}' function='0x0'/>
{% endif %}
</disk>
{% endfor %}
<controller type='ide' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
</controller>