Allow to sepecify VM disk format

Disk format may be set by configuring IRONIC_VM_SPECS_DISK_FORMAT variable.
By default it is set to qcow2.

Change-Id: I8f8a0b75b41f0e2712496c275b91ee027aa37f76
This commit is contained in:
Vasyl Saienko 2016-04-27 03:53:51 -04:00 committed by vsaienko
parent 03ab6011ee
commit 2305c95052
4 changed files with 11 additions and 6 deletions

View File

@ -102,6 +102,7 @@ IRONIC_VM_COUNT=${IRONIC_VM_COUNT:-1}
IRONIC_VM_SPECS_CPU=${IRONIC_VM_SPECS_CPU:-1}
IRONIC_VM_SPECS_RAM=${IRONIC_VM_SPECS_RAM:-1024}
IRONIC_VM_SPECS_DISK=${IRONIC_VM_SPECS_DISK:-10}
IRONIC_VM_SPECS_DISK_FORMAT=${IRONIC_VM_SPECS_DISK_FORMAT:-qcow2}
IRONIC_VM_EPHEMERAL_DISK=${IRONIC_VM_EPHEMERAL_DISK:-0}
IRONIC_VM_EMULATOR=${IRONIC_VM_EMULATOR:-/usr/bin/qemu-system-x86_64}
IRONIC_VM_NETWORK_BRIDGE=${IRONIC_VM_NETWORK_BRIDGE:-brbm}
@ -711,7 +712,7 @@ function create_bridge_and_vms {
sudo su $STACK_USER -c "$IRONIC_SCRIPTS_DIR/create-node.sh $vm_name \
$IRONIC_VM_SPECS_CPU $IRONIC_VM_SPECS_RAM $IRONIC_VM_SPECS_DISK \
amd64 $IRONIC_VM_NETWORK_BRIDGE $IRONIC_VM_EMULATOR \
$vbmc_port $log_arg" >> $IRONIC_VM_MACS_CSV_FILE
$vbmc_port $log_arg $IRONIC_VM_SPECS_DISK_FORMAT" >> $IRONIC_VM_MACS_CSV_FILE
vbmc_port=$((vbmc_port+1))
done
create_ovs_taps

View File

@ -76,6 +76,8 @@ def main():
help='File to log console')
parser.add_argument('--emulator', default=None,
help='Path to emulator bin for vm template')
parser.add_argument('--disk-format', default='qcow2',
help='Disk format to use.')
args = parser.parse_args()
with file(templatedir + '/vm.xml', 'rb') as f:
source_template = f.read()
@ -90,6 +92,7 @@ def main():
'network': args.network,
'nicdriver': args.libvirt_nic_driver,
'emulator': args.emulator,
'disk_format': args.disk_format
}
if args.emulator:

View File

@ -26,6 +26,7 @@ BRIDGE=$6
EMULATOR=$7
VBMC_PORT=$8
LOGDIR=$9
DISK_FORMAT=${10}
LIBVIRT_NIC_DRIVER=${LIBVIRT_NIC_DRIVER:-"virtio"}
LIBVIRT_STORAGE_POOL=${LIBVIRT_STORAGE_POOL:-"default"}
@ -50,7 +51,7 @@ if [ -n "$LOGDIR" ] ; then
fi
PREALLOC=
if [ -f /etc/debian_version ]; then
if [ -f /etc/debian_version && "$DISK_FORMAT" == "qcow2" ]; then
PREALLOC="--prealloc-metadata"
fi
@ -59,12 +60,12 @@ if [ -n "$LOGDIR" ] ; then
else
VM_LOGGING=""
fi
VOL_NAME="${NAME}.qcow2"
VOL_NAME="${NAME}.${DISK_FORMAT}"
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 qcow2 $PREALLOC >&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"
@ -72,7 +73,7 @@ if ! virsh list --all | grep -q $NAME; then
$TOP_DIR/scripts/configure-vm.py \
--bootdev network --name $NAME --image "$volume_path" \
--arch $ARCH --cpus $CPU --memory $MEM --libvirt-nic-driver $LIBVIRT_NIC_DRIVER \
--emulator $EMULATOR --network $BRIDGE $VM_LOGGING >&2
--emulator $EMULATOR --network $BRIDGE --disk-format $DISK_FORMAT $VM_LOGGING >&2
# Createa Virtual BMC for the node if IPMI is used
if [[ $(type -P vbmc) != "" ]]; then

View File

@ -20,7 +20,7 @@
<devices>
<emulator>%(emulator)s</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2' cache='writeback'/>
<driver name='qemu' type='%(disk_format)s' cache='writeback'/>
<source file='%(imagefile)s'/>
<target dev='vda' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>