Browse Source

fixed check for exsiting images

master
Sebastian Rieger 8 years ago
parent
commit
4ca0613a08
  1. 137
      create-arista-veos-image/create-arista-veos-image.sh
  2. 332
      create-f5-bigip-image/create-f5-big-ip-image.sh

137
create-arista-veos-image/create-arista-veos-image.sh

@ -3,18 +3,16 @@
# HS-Fulda - sebastian.rieger@informatik.hs-fulda.de
#
# changelog:
# V1.1 added injection of config defined in VM Maestro using config-drivex
# 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
# V1.31 added support for newer glance releases (e.g. kilo) used in VIRL 1.0.0
# V1.32 changed the extension of the bootloader iso to match the size of the partitions to be injected
# V1.4 support for variable VEOS image sizes (as requested by @Jade_Deane to use custom VEOS images)
# V1.5 automatic import of subtype and creation of flavors based on image name,
# short instructions on how to use the image and hint to default node configuration,
# removed detection of existing image as new VIRL version supports multiple versions
# V1.1 added injection of config defined in VM Maestro using config-drivex
# V1.1.1 fixed device mapping of extracted partitions, fixed problems with stale swi directory
# V1.1.2 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
# V1.3.1 added support for newer glance releases (e.g. kilo) used in VIRL 1.0.0
# V1.3.2 changed the extension of the bootloader iso to match the size of the partitions to be injected
# V1.4 support for variable VEOS image sizes (as requested by @Jade_Deane to use custom VEOS images)
# V1.4.1 fixed check for existing images
# usage
if [ ! $# -eq 3 ] ; then
@ -56,6 +54,24 @@ function safe_unmount() {
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 --os-image-api-version 1 image-show $GLANCE_IMAGE_NAME 2>&1)
if [ $? == 0 ] ; then
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
if [[ $RESPONSE =~ ^([yY][eE][sS]|[yY])$ ]] ; then
echo "Deleting existing image $GLANCE_IMAGE_NAME..."
echo "==========================================================="
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
fi
fi
echo
echo "Creating vEOS image..."
echo "==========================================================="
@ -200,105 +216,14 @@ if [ $? == 1 ]; then
nova flavor-create --is-public true vEOS.small auto 1024 0 1
fi
CHECKING_FOR_EXISTING_FLAVOR=$(nova flavor-show $GLANCE_IMAGE_NAME.medium 2>&1)
if [ $? == 1 ]; then
echo "Creating default flavor $GLANCE_IMAGE_NAME.medium..."
echo "==========================================================="
nova flavor-create --is-public true $GLANCE_IMAGE_NAME.medium auto 2048 0 1
fi
CHECKING_FOR_EXISTING_FLAVOR=$(nova flavor-show $GLANCE_IMAGE_NAME.small 2>&1)
CHECKING_FOR_EXISTING_FLAVOR=$(nova flavor-show vEOS.medium 2>&1)
if [ $? == 1 ]; then
echo "Creating default flavor $GLANCE_IMAGE_NAME.small..."
echo "Creating default flavor vEOS.medium..."
echo "==========================================================="
nova flavor-create --is-public true $GLANCE_IMAGE_NAME.small auto 1024 0 1
nova flavor-create --is-public true vEOS.medium auto 2048 0 1
fi
#CHECKING_FOR_EXISTING_SUBTYPE=$(virl_uwm_client subtype-export 2>/dev/null | grep -Po '"'"plugin_desc"'"\s*:\s*"\K([^"]*)')
CHECKING_FOR_EXISTING_SUBTYPE=$(virl_uwm_client subtype-export 2>/dev/null | grep "\"plugin_name\": \"$GLANCE_IMAGE_NAME\",")
if [ $? == 1 ]; then
# create default subtype
cat << EOF > $TIMESTAMP.default-subtype
{
"dynamic-subtypes": [
{
"interface_range": 22,
"config_disk_type": "disk",
"baseline_image": "$GLANCE_IMAGE_NAME",
"baseline_flavor": "$GLANCE_IMAGE_NAME.medium",
"hw_vm_extra": "",
"plugin_desc": "Arista vEOS",
"interface_pattern": "Ethernet{0}",
"interface_management": "Management1",
"gui_visible": true,
"cli_serial": 1,
"hw_ram": 1024,
"plugin_name": "$GLANCE_IMAGE_NAME",
"interface_first": 1,
"config_file": "/veos_config.txt",
"gui_icon": "iosvl2",
"plugin_base": "generic"
}
]
}
EOF
echo "Creating default subtype vEOS..."
echo "==========================================================="
virl_uwm_client subtype-import --dynamic-subtypes @$TIMESTAMP.default-subtype
rm $TIMESTAMP.default-subtype
fi
echo
echo "Creation of the image finished successfully"
echo "==========================================================="
echo "You can import the default Subtype in VM Maestro using"
echo "\"File->Preferences->Node Subtypes->Restore Defaults\""
echo "followed by clicking on \"Fetch from Server\". Afterwards,"
echo "vEOS should appear in the \"Nodes\" section of VM Maestro's"
echo "Topology Palette. The following default config can be used"
echo "by pasting it into the Configuration tab after clicking on"
echo "each vEOS node created in your topology:"
echo -e "
! device: veos-1 (vEOS, EOS-4.14.2F)
!
! boot system flash:/vEOS.swi
!
transceiver qsfp default-mode 4x10G
!
hostname veos-1
!
spanning-tree mode mstp
!
no aaa root
!
username admin role network-admin secret 5 \$1\$93LlZesx\$MSqS1D/8NGTSY724FGx1K0
username cisco role network-admin secret 5 \$1\$rQS0W9wP\$ZUzVG2XoGCCZCJopFp1aV/
!
interface Ethernet1
!
interface Ethernet2
!
interface Management1
! ip of ma1 configured on launch
!
no ip routing
!
!
"
echo "Of course you must modify the config (name, version) to your needs."
echo "Otherwise, vEOS will will start with an empty configuration and"
echo "go into Zero-Touch-Provisioning (ZTP) mode. You should also disable"
echo "\"Auto-generate the configuration based on these attributes\" in"
echo "the AutoNetkit tab of the node, as AutoNetkit is only supported"
echo "for the Cisco images in VIRL."
#testing:
#

332
create-f5-bigip-image/create-f5-big-ip-image.sh

@ -1,166 +1,166 @@
#!/bin/bash
# create-f5-big-ip-image.sh
# HS-Fulda - sebastian.rieger@informatik.hs-fulda.de
#
# changelog:
#
# V0.1 initial version
# usage
if [ ! $# -eq 2 ] ; then
echo -e "usage: $0 <BIGIP-12.0.0.0.0.606.qcow2> <new glance image name>, e.g.:\n"
echo "$0 BIGIP-12.0.0.0.0.606.qcow2 F5-BIGIP"
exit -1
fi
# sudo check
if [ ! $UID -eq 0 ] ; then
echo "Insufficient privileges. Please consider using sudo -s."
exit -1
fi
BIGIP_QCOW2=$1
BIGIP_QCOW2_BASENAME=$(basename -s .qcow2 $1)
BIGIP_PATCHED_QCOW2=$1-patched.qcow2
GLANCE_IMAGE_NAME=$2
GLANCE_IMAGE_RELEASE=$BIGIP_QCOW2_BASENAME
TMP_NAME="BIGIP-$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 F5 BIGIP image..."
echo "==========================================================="
qemu-img convert -O raw $BIGIP_QCOW2 $BIGIP_QCOW2_BASENAME.raw
LOOPDEV=$(kpartx -av $BIGIP_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)
LOOPDEV_PART3=$(echo "$LOOPDEV" | sed '3q;d' | cut -d " " -f 3)
mkdir bigip-part1-boot-$TIMESTAMP
# part2 is swap
#mkdir bigip-part3-lvm-dat.log.1-$TIMESTAMP
#mkdir bigip-part3-lvm-dat.maint.1-$TIMESTAMP
#mkdir bigip-part3-lvm-dat.share.1-$TIMESTAMP
#mkdir bigip-part3-lvm-dat.swapvol.1-$TIMESTAMP
mkdir bigip-part3-lvm-set.1._config-$TIMESTAMP
#mkdir bigip-part3-lvm-set.1._usr-$TIMESTAMP
#mkdir bigip-part3-lvm-set.1._var-$TIMESTAMP
#mkdir bigip-part3-lvm-set.1.root-$TIMESTAMP
echo
echo "Injecting changes to use serial console and startup script to get config..."
echo "=================================================================================="
mount /dev/mapper/$LOOPDEV_PART1 bigip-part1-boot-$TIMESTAMP
# scan for new lvm volumes in part3
pvscan
# activate the new volume groups
vgchange -ay
mount /dev/mapper/vg--db--hda-set.1._config bigip-part3-lvm-set.1._config-$TIMESTAMP
## change grub to add kernel config console=ttyS0
sed -i.bak -e s/"^splashimage="/"#splashimage="/g bigip-part1-boot-$TIMESTAMP/grub/grub.conf
sed -i.bak -e s/"^timeout=8"/"timeout=8\nserial --unit=0 --speed=115200\nterminal --timeout=2 serial console"/g bigip-part1-boot-$TIMESTAMP/grub/grub.conf
sed -i.bak -e s/"default_cpu_order quiet"/"default_cpu_order quiet console=ttyS0"/g bigip-part1-boot-$TIMESTAMP/grub/grub.conf
## append call to userscript in /config/startup
cat << EOF >> bigip-part3-lvm-set.1._config-$TIMESTAMP/startup
mkdir /virl-config
mount /dev/hdd1 /virl-config
chmod +x /virl-config/bigip-config.sh
/virl-config/bigip-config.sh >/var/log/virl-startup.log
EOF
#DEBUG:
# run bash to allow manual changes to the image before packing
#
#bash
safe_unmount bigip-part1-boot-$TIMESTAMP
#part2 is swap
#safe_unmount bigip-part3-lvm-dat.log.1-$TIMESTAMP
#safe_unmount bigip-part3-lvm-dat.maint.1-$TIMESTAMP
#safe_unmount bigip-part3-lvm-dat.share.1-$TIMESTAMP
#safe_unmount bigip-part3-lvm-dat.swapvol.1-$TIMESTAMP
safe_unmount bigip-part3-lvm-set.1._config-$TIMESTAMP
#safe_unmount bigip-part3-lvm-set.1._usr-$TIMESTAMP
#safe_unmount bigip-part3-lvm-set.1._var-$TIMESTAMP
#safe_unmount bigip-part3-lvm-set.1.root-$TIMESTAMP
rm -rf bigip-part1-boot-$TIMESTAMP
#part2 is swap
#rm -rf bigip-part3-lvm-dat.log.1-$TIMESTAMP
#rm -rf bigip-part3-lvm-dat.maint.1-$TIMESTAMP
#rm -rf bigip-part3-lvm-dat.share.1-$TIMESTAMP
#rm -rf bigip-part3-lvm-dat.swapvol.1-$TIMESTAMP
rm -rf bigip-part3-lvm-set.1._config-$TIMESTAMP
#rm -rf bigip-part3-lvm-set.1._usr-$TIMESTAMP
#rm -rf bigip-part3-lvm-set.1._var-$TIMESTAMP
#rm -rf bigip-part3-lvm-set.1.root-$TIMESTAMP
# deactive part3 volume groups
vgchange -an
kpartx -d $BIGIP_QCOW2_BASENAME.raw
echo
echo "Saving F5 BIGIP image..."
echo "==========================================================="
qemu-img convert -O qcow2 $BIGIP_QCOW2_BASENAME.raw $BIGIP_PATCHED_QCOW2
# use recommendations from https://support.f5.com/kb/en-us/products/big-ip_ltm/manuals/product/bigip-ve-kvm-setup-11-3-0/2.html#r_ve_vmware_1022_esx_mach_reqs
glance image-create --container-format bare --disk-format qcow2 --visibility public --name $GLANCE_IMAGE_NAME \
--file $BIGIP_PATCHED_QCOW2 --property hw_disk_bus=virtio --property serial=1 \
--property hw_vif_model=virtio --property hw_cdrom_type=ide --property release="$GLANCE_IMAGE_RELEASE" --property subtype=F5-BIGIP --property config_disk_type=disk
# create default flavor
CHECKING_FOR_EXISTING_FLAVOR=$(nova flavor-show F5-BIGIP.small 2>&1)
if [ $? == 1 ]; then
echo "Creating default flavor F5-BIGIP.small..."
echo "==========================================================="
nova flavor-create --is-public true F5-BIGIP.small auto 4096 0 2
fi
echo
echo "Cleaning up..."
echo "==========================================================="
rm $BIGIP_QCOW2_BASENAME.raw
#!/bin/bash
# create-f5-big-ip-image.sh
# HS-Fulda - sebastian.rieger@informatik.hs-fulda.de
#
# changelog:
#
# V0.1 initial version
# usage
if [ ! $# -eq 2 ] ; then
echo -e "usage: $0 <BIGIP-12.0.0.0.0.606.qcow2> <new glance image name>, e.g.:\n"
echo "$0 BIGIP-12.0.0.0.0.606.qcow2 F5-BIGIP"
exit -1
fi
# sudo check
if [ ! $UID -eq 0 ] ; then
echo "Insufficient privileges. Please consider using sudo -s."
exit -1
fi
BIGIP_QCOW2=$1
BIGIP_QCOW2_BASENAME=$(basename -s .qcow2 $1)
BIGIP_PATCHED_QCOW2=$1-patched.qcow2
GLANCE_IMAGE_NAME=$2
GLANCE_IMAGE_RELEASE=$BIGIP_QCOW2_BASENAME
TMP_NAME="BIGIP-$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 F5 BIGIP image..."
echo "==========================================================="
qemu-img convert -O raw $BIGIP_QCOW2 $BIGIP_QCOW2_BASENAME.raw
LOOPDEV=$(kpartx -av $BIGIP_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)
LOOPDEV_PART3=$(echo "$LOOPDEV" | sed '3q;d' | cut -d " " -f 3)
mkdir bigip-part1-boot-$TIMESTAMP
# part2 is swap
#mkdir bigip-part3-lvm-dat.log.1-$TIMESTAMP
#mkdir bigip-part3-lvm-dat.maint.1-$TIMESTAMP
#mkdir bigip-part3-lvm-dat.share.1-$TIMESTAMP
#mkdir bigip-part3-lvm-dat.swapvol.1-$TIMESTAMP
mkdir bigip-part3-lvm-set.1._config-$TIMESTAMP
#mkdir bigip-part3-lvm-set.1._usr-$TIMESTAMP
#mkdir bigip-part3-lvm-set.1._var-$TIMESTAMP
#mkdir bigip-part3-lvm-set.1.root-$TIMESTAMP
echo
echo "Injecting changes to use serial console and startup script to get config..."
echo "=================================================================================="
mount /dev/mapper/$LOOPDEV_PART1 bigip-part1-boot-$TIMESTAMP
# scan for new lvm volumes in part3
pvscan
# activate the new volume groups
vgchange -ay
mount /dev/mapper/vg--db--hda-set.1._config bigip-part3-lvm-set.1._config-$TIMESTAMP
## change grub to add kernel config console=ttyS0
sed -i.bak -e s/"^splashimage="/"#splashimage="/g bigip-part1-boot-$TIMESTAMP/grub/grub.conf
sed -i.bak -e s/"^timeout=8"/"timeout=8\nserial --unit=0 --speed=115200\nterminal --timeout=2 serial console"/g bigip-part1-boot-$TIMESTAMP/grub/grub.conf
sed -i.bak -e s/"default_cpu_order quiet"/"default_cpu_order quiet console=ttyS0"/g bigip-part1-boot-$TIMESTAMP/grub/grub.conf
## append call to userscript in /config/startup
cat << EOF >> bigip-part3-lvm-set.1._config-$TIMESTAMP/startup
mkdir /virl-config
mount /dev/hdd1 /virl-config
chmod +x /virl-config/bigip-config.sh
/virl-config/bigip-config.sh >/var/log/virl-startup.log
EOF
#DEBUG:
# run bash to allow manual changes to the image before packing
#
#bash
safe_unmount bigip-part1-boot-$TIMESTAMP
#part2 is swap
#safe_unmount bigip-part3-lvm-dat.log.1-$TIMESTAMP
#safe_unmount bigip-part3-lvm-dat.maint.1-$TIMESTAMP
#safe_unmount bigip-part3-lvm-dat.share.1-$TIMESTAMP
#safe_unmount bigip-part3-lvm-dat.swapvol.1-$TIMESTAMP
safe_unmount bigip-part3-lvm-set.1._config-$TIMESTAMP
#safe_unmount bigip-part3-lvm-set.1._usr-$TIMESTAMP
#safe_unmount bigip-part3-lvm-set.1._var-$TIMESTAMP
#safe_unmount bigip-part3-lvm-set.1.root-$TIMESTAMP
rm -rf bigip-part1-boot-$TIMESTAMP
#part2 is swap
#rm -rf bigip-part3-lvm-dat.log.1-$TIMESTAMP
#rm -rf bigip-part3-lvm-dat.maint.1-$TIMESTAMP
#rm -rf bigip-part3-lvm-dat.share.1-$TIMESTAMP
#rm -rf bigip-part3-lvm-dat.swapvol.1-$TIMESTAMP
rm -rf bigip-part3-lvm-set.1._config-$TIMESTAMP
#rm -rf bigip-part3-lvm-set.1._usr-$TIMESTAMP
#rm -rf bigip-part3-lvm-set.1._var-$TIMESTAMP
#rm -rf bigip-part3-lvm-set.1.root-$TIMESTAMP
# deactive part3 volume groups
vgchange -an
kpartx -d $BIGIP_QCOW2_BASENAME.raw
echo
echo "Saving F5 BIGIP image..."
echo "==========================================================="
qemu-img convert -O qcow2 $BIGIP_QCOW2_BASENAME.raw $BIGIP_PATCHED_QCOW2
# use recommendations from https://support.f5.com/kb/en-us/products/big-ip_ltm/manuals/product/bigip-ve-kvm-setup-11-3-0/2.html#r_ve_vmware_1022_esx_mach_reqs
glance image-create --container-format bare --disk-format qcow2 --visibility public --name $GLANCE_IMAGE_NAME \
--file $BIGIP_PATCHED_QCOW2 --property hw_disk_bus=virtio --property serial=1 \
--property hw_vif_model=virtio --property hw_cdrom_type=ide --property release="$GLANCE_IMAGE_RELEASE" --property subtype=F5-BIGIP --property config_disk_type=disk
# create default flavor
CHECKING_FOR_EXISTING_FLAVOR=$(nova flavor-show F5-BIGIP.small 2>&1)
if [ $? == 1 ]; then
echo "Creating default flavor F5-BIGIP.small..."
echo "==========================================================="
nova flavor-create --is-public true F5-BIGIP.small auto 4096 0 2
fi
echo
echo "Cleaning up..."
echo "==========================================================="
rm $BIGIP_QCOW2_BASENAME.raw
Loading…
Cancel
Save