From 1bfcb521ca36c01b92380d88ba4c4424cd92de51 Mon Sep 17 00:00:00 2001 From: Sebastian Rieger Date: Mon, 11 Jul 2016 21:40:39 +0200 Subject: [PATCH] fixed check for existing images, added support for Cumulus VX 3.x --- .../create-cumulus-vx-image.sh | 59 ++++++++++++++----- .../dynamic-subtype-CumulusVX.json | 21 +++---- 2 files changed, 55 insertions(+), 25 deletions(-) diff --git a/create-cumulusvx-image/create-cumulus-vx-image.sh b/create-cumulusvx-image/create-cumulus-vx-image.sh index 65ec279..ce7282a 100644 --- a/create-cumulusvx-image/create-cumulus-vx-image.sh +++ b/create-cumulusvx-image/create-cumulus-vx-image.sh @@ -4,9 +4,11 @@ # # changelog: # -# V0.2 added support to delete existing image with the same name and generating the default nova flavor -# V0.3 checking whether it is safe to unmount the working directory -# V0.31 added support for newer glance releases (e.g. kilo) used in VIRL 1.0.0 +# V0.2 added support to delete existing image with the same name and generating the default nova flavor +# V0.3 checking whether it is safe to unmount the working directory +# V0.3.1 added support for newer glance releases (e.g. kilo) used in VIRL 1.0.0 +# V0.4 fixed check for existing images, added support for Cumulus VX 3.x + # usage if [ ! $# -eq 2 ] ; then @@ -48,9 +50,9 @@ function safe_unmount() { } # check for an existing image with the same name and offer to delete it prior to creating a new one -CHECK_FOR_EXISTING_IMAGE=$(glance image-show $GLANCE_IMAGE_NAME 2>&1) +CHECK_FOR_EXISTING_IMAGE=$(glance --os-image-api-version 1 image-show $GLANCE_IMAGE_NAME 2>&1) if [ $? == 0 ] ; then - glance image-show $GLANCE_IMAGE_NAME + glance --os-image-api-version 1 image-show $GLANCE_IMAGE_NAME echo echo read -r -p "There is already an image with the same name in glance. Do you want to overwrite it? [y/N] " RESPONSE @@ -58,7 +60,7 @@ if [ $? == 0 ] ; then echo "Deleting existing image $GLANCE_IMAGE_NAME..." echo "===========================================================" - glance image-delete $GLANCE_IMAGE_NAME + glance --os-image-api-version 1 image-delete $GLANCE_IMAGE_NAME else echo "An image with the same name already exists. Either delete this image or choose another name." exit 1 @@ -69,10 +71,30 @@ echo echo "Creating CumulusVX image..." echo "===========================================================" +# check version +if [[ "$CUMULUS_QCOW2_BASENAME" =~ ^cumulus-vx-2\.5 ]] ; then + # handle 2.5.x versions + CUMULUS_VERSION=2 +elif [[ "$CUMULUS_QCOW2_BASENAME" =~ ^cumulus-linux-3\. ]] ; then + # handle 3.x versions + CUMULUS_VERSION=3 +else + echo "Unsupported version of Cumulus VX, currently this script supports versions 2.5.x and 3.x" + exit 1 +fi + qemu-img convert -O raw $CUMULUS_QCOW2 $CUMULUS_QCOW2_BASENAME.raw LOOPDEV=$(kpartx -av $CUMULUS_QCOW2_BASENAME.raw) -LOOPDEV_PART1=$(echo "$LOOPDEV" | sed '1q;d' | cut -d " " -f 3) -LOOPDEV_PART2=$(echo "$LOOPDEV" | sed '2q;d' | cut -d " " -f 3) + +if [ $CUMULUS_VERSION == 2 ]; then + # partition layout Cumulus VX 2.5.x: part1 = boot, part2 = root + LOOPDEV_PART_BOOT=$(echo "$LOOPDEV" | sed '1q;d' | cut -d " " -f 3) + LOOPDEV_PART_ROOT=$(echo "$LOOPDEV" | sed '2q;d' | cut -d " " -f 3) +elif [ $CUMULUS_VERSION == 3 ]; then + # partition layout Cumulus VX 3.x: part1 = grubboot, part2 = onieboot, part3 = boot, part4 = root + LOOPDEV_PART_BOOT=$(echo "$LOOPDEV" | sed '3q;d' | cut -d " " -f 3) + LOOPDEV_PART_ROOT=$(echo "$LOOPDEV" | sed '4q;d' | cut -d " " -f 3) +fi mkdir cumulusvx-boot-$TIMESTAMP mkdir cumulusvx-root-$TIMESTAMP @@ -81,12 +103,19 @@ echo echo "Injecting changes to use serial console and startup script to get switch config..." echo "==================================================================================" -mount /dev/mapper/$LOOPDEV_PART1 cumulusvx-boot-$TIMESTAMP -mount /dev/mapper/$LOOPDEV_PART2 cumulusvx-root-$TIMESTAMP -# changing grub and inittab to use a serial console on kernel command line -sed -i.bak -e s/"linux \/bzImage root=\/dev\/sda2"/"linux \/bzImage root=\/dev\/sda2 console=ttyS0 console=tty0"/g cumulusvx-root-$TIMESTAMP/vbox_grub.cfg -sed -i.bak -e s/"linux \/bzImage root=\/dev\/sda2"/"linux \/bzImage root=\/dev\/sda2 console=ttyS0 console=tty0"/g cumulusvx-boot-$TIMESTAMP/grub/grub.cfg -sed -i.bak -e s/"# S0:3:respawn:\/sbin\/getty -L \$(get-cmdline-console) vt100"/"S0:3:respawn:\/sbin\/getty -L \$(get-cmdline-console) vt100"/g cumulusvx-root-$TIMESTAMP/etc/inittab +mount /dev/mapper/$LOOPDEV_PART_BOOT cumulusvx-boot-$TIMESTAMP +mount /dev/mapper/$LOOPDEV_PART_ROOT cumulusvx-root-$TIMESTAMP + +if [ $CUMULUS_VERSION == 2 ]; then + # changing grub and inittab to use a serial console on kernel command line + sed -i.bak -e s/"linux \/bzImage root=\/dev\/sda2"/"linux \/bzImage root=\/dev\/sda2 console=ttyS0 console=tty0"/g cumulusvx-root-$TIMESTAMP/vbox_grub.cfg + sed -i.bak -e s/"linux \/bzImage root=\/dev\/sda2"/"linux \/bzImage root=\/dev\/sda2 console=ttyS0 console=tty0"/g cumulusvx-boot-$TIMESTAMP/grub/grub.cfg + sed -i.bak -e s/"# S0:3:respawn:\/sbin\/getty -L \$(get-cmdline-console) vt100"/"S0:3:respawn:\/sbin\/getty -L \$(get-cmdline-console) vt100"/g cumulusvx-root-$TIMESTAMP/etc/inittab +elif [ $CUMULUS_VERSION == 3 ]; then + # changing grub to show boot log + sed -i.bak -e s/"console=tty0 quiet"/"console=tty0"/g cumulusvx-boot-$TIMESTAMP/grub/grub.cfg +fi + # append a script to import the configuration defined in VM Maestro to rc.local sed -i.bak -e s/"^exit 0$"/""/g cumulusvx-root-$TIMESTAMP/etc/rc.local cat << EOF >> cumulusvx-root-$TIMESTAMP/etc/rc.local @@ -99,7 +128,7 @@ EOF #DEBUG: # run bash to allow manual changes to the image before packing # -#bash +bash safe_unmount cumulusvx-boot-$TIMESTAMP safe_unmount cumulusvx-root-$TIMESTAMP diff --git a/create-cumulusvx-image/dynamic-subtype-CumulusVX.json b/create-cumulusvx-image/dynamic-subtype-CumulusVX.json index 6f7cce8..86087d6 100644 --- a/create-cumulusvx-image/dynamic-subtype-CumulusVX.json +++ b/create-cumulusvx-image/dynamic-subtype-CumulusVX.json @@ -1,22 +1,23 @@ { "dynamic-subtypes": [ { - "config_file": "/cumulusvx.sh", + "cli_protocol": "ssh", "gui_icon": "iosvl2", + "plugin_desc": "CumulusVX", + "interface_first": 1, + "baseline_flavor": "CumulusVX.small", "plugin_base": "generic", "interface_management": "eth0", "interface_pattern": "swp{0}", - "interface_range": 25, - "cli_protocol": "ssh", - "baseline_flavor": "CumulusVX.small", - "plugin_name": "CumulusVX", - "interface_first": 1, + "config_file": "/cumulusvx.sh", + "deprecated_use": "", + "hw_vm_extra": "", "cli_serial": 1, - "plugin_desc": "CumulusVX", + "interface_range": 25, "config_disk_type": "disk", - "hw_vm_extra": "", - "baseline_image": "CumulusVX", - "gui_visible": true + "plugin_name": "CumulusVX", + "gui_visible": true, + "baseline_image": "CumulusVX" } ] } \ No newline at end of file