@ -1,5 +1,5 @@
#!/bin/bash
# create-arista-veos-image.sh V1.2
# create-arista-veos-image.sh V1.3
# HS-Fulda - sebastian.rieger@informatik.hs-fulda.de
#
# changelog:
@ -7,6 +7,8 @@
# V1.11 fixed device mapping of extracted partitions, fixed problems with stale swi directory
# V1.12 rc.eos now supports e1000 and virtio as vnic types (virtio is supported in vEOS >=4.14.5F)
# V1.2 added dynamic handling of device mapping of extacted partitions
# V1.21 checking whether it safe to unmount working directories
# V1.3 added support to delete existing image with the same name and generating the default nova flavor
# usage
if [ ! $# -eq 3 ] ; then
@ -30,6 +32,42 @@ GLANCE_IMAGE_RELEASE=$VEOS_VMDK_BASENAME-$ABOOT_SERIAL_ISO_BASENAME
TMP_NAME = " vEOS- $GLANCE_IMAGE_RELEASE "
TIMESTAMP = $( date +%Y%m%d%H%M%S)
function safe_unmount( ) {
echo -n " Unmounting $1 ... "
RETRY = 0
until umount $1 & >/dev/null
do
echo -n "."
sleep 1
RETRY = $(( RETRY+1))
if [ " $RETRY " -ge "5" ] ; then
echo
echo " ERROR: unable to unmount working directory $1 "
exit 1
fi
done
echo
return 0
}
# 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)
if [ $? = = 0 ] ; then
glance 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
if [ [ $RESPONSE = ~ ^( [ yY] [ eE] [ sS] | [ yY] ) $ ] ] ; then
echo " Deleting existing image $GLANCE_IMAGE_NAME ... "
echo "==========================================================="
glance 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
fi
fi
echo
echo "Creating vEOS image..."
echo "==========================================================="
@ -92,7 +130,9 @@ cp /mnt/flash/startup-config.tmp /mnt/flash/startup-config
EOF
chmod 755 rc.eos
cd ..
umount swi-$TIMESTAMP
safe_unmount swi-$TIMESTAMP
rm -rf swi-$TIMESTAMP
echo
@ -157,7 +197,26 @@ rm $VEOS_VMDK_BASENAME.raw
echo
echo "Importing image into glance..."
echo "==========================================================="
glance image-create --container-format bare --disk-format qcow2 --is-public true --name $GLANCE_IMAGE_NAME --file $TMP_NAME .qcow2 --property hw_disk_bus = ide --property serial = 1 --property hw_vif_model = e1000 --property hw_cdrom_type = ide --property release = " $GLANCE_IMAGE_RELEASE " --property subtype = IOSv --property config_disk_type = disk
glance image-create --container-format bare --disk-format qcow2 --is-public true --name $GLANCE_IMAGE_NAME \
--file $TMP_NAME .qcow2 --property hw_disk_bus = ide --property serial = 1 \
--property hw_vif_model = e1000 --property hw_cdrom_type = ide --property release = " $GLANCE_IMAGE_RELEASE " --property subtype = IOSv --property config_disk_type = disk
# create default flavor
CHECKING_FOR_EXISTING_FLAVOR = $( nova flavor-show vEOS.small 2>& 1)
if [ $? = = 1 ] ; then
echo "Creating default flavor vEOS.small..."
echo "==========================================================="
nova flavor-create --is-public true vEOS.small auto 1024 0 1
fi
CHECKING_FOR_EXISTING_FLAVOR = $( nova flavor-show vEOS.medium 2>& 1)
if [ $? = = 1 ] ; then
echo "Creating default flavor vEOS.medium..."
echo "==========================================================="
nova flavor-create --is-public true vEOS.medium auto 2048 0 1
fi
#testing:
#