|
@ -1,6 +1,9 @@ |
|
|
#!/bin/bash |
|
|
#!/bin/bash |
|
|
# create-arista-veos-image.sh V1.0 |
|
|
|
|
|
|
|
|
# create-arista-veos-image.sh V1.1 |
|
|
# HS-Fulda - sebastian.rieger@informatik.hs-fulda.de |
|
|
# HS-Fulda - sebastian.rieger@informatik.hs-fulda.de |
|
|
|
|
|
# |
|
|
|
|
|
# changelog: |
|
|
|
|
|
# V1.1 added injection of config defined in VM Maestro using config-drivex |
|
|
|
|
|
|
|
|
# usage |
|
|
# usage |
|
|
if [ ! $# -eq 3 ] ; then |
|
|
if [ ! $# -eq 3 ] ; then |
|
@ -11,7 +14,7 @@ fi |
|
|
|
|
|
|
|
|
# sudo check |
|
|
# sudo check |
|
|
if [ ! $UID -eq 0 ] ; then |
|
|
if [ ! $UID -eq 0 ] ; then |
|
|
echo "Insufficient privileges. Please consider using sudo." |
|
|
|
|
|
|
|
|
echo "Insufficient privileges. Please consider using sudo -s." |
|
|
exit -1 |
|
|
exit -1 |
|
|
fi |
|
|
fi |
|
|
|
|
|
|
|
@ -23,6 +26,7 @@ GLANCE_IMAGE_NAME=$3 |
|
|
GLANCE_IMAGE_RELEASE=$VEOS_VMDK_BASENAME-$ABOOT_SERIAL_ISO_BASENAME |
|
|
GLANCE_IMAGE_RELEASE=$VEOS_VMDK_BASENAME-$ABOOT_SERIAL_ISO_BASENAME |
|
|
TMP_NAME="vEOS-$GLANCE_IMAGE_RELEASE" |
|
|
TMP_NAME="vEOS-$GLANCE_IMAGE_RELEASE" |
|
|
|
|
|
|
|
|
|
|
|
echo |
|
|
echo "Creating vEOS image..." |
|
|
echo "Creating vEOS image..." |
|
|
echo "===========================================================" |
|
|
echo "===========================================================" |
|
|
|
|
|
|
|
@ -30,6 +34,7 @@ echo "===========================================================" |
|
|
cp $1 $TMP_NAME.raw |
|
|
cp $1 $TMP_NAME.raw |
|
|
truncate -s +3G $TMP_NAME.raw |
|
|
truncate -s +3G $TMP_NAME.raw |
|
|
|
|
|
|
|
|
|
|
|
echo |
|
|
echo "Extracting partitions from vEOS vmdk..." |
|
|
echo "Extracting partitions from vEOS vmdk..." |
|
|
echo "===========================================================" |
|
|
echo "===========================================================" |
|
|
|
|
|
|
|
@ -40,6 +45,45 @@ dd if=/dev/loop0p1 of=$VEOS_VMDK_BASENAME-p1.raw |
|
|
dd if=/dev/loop0p2 of=$VEOS_VMDK_BASENAME-p2.raw |
|
|
dd if=/dev/loop0p2 of=$VEOS_VMDK_BASENAME-p2.raw |
|
|
kpartx -d $VEOS_VMDK_BASENAME.raw |
|
|
kpartx -d $VEOS_VMDK_BASENAME.raw |
|
|
|
|
|
|
|
|
|
|
|
echo |
|
|
|
|
|
echo "Injecting rc.eos startup script to get switch config..." |
|
|
|
|
|
echo "===========================================================" |
|
|
|
|
|
|
|
|
|
|
|
# inject rc.eos script in first partition of the image, to get switch config defined in VM Maestro (config-drive) |
|
|
|
|
|
mkdir swi |
|
|
|
|
|
mount -o loop $VEOS_VMDK_BASENAME-p1.raw swi |
|
|
|
|
|
cd swi |
|
|
|
|
|
cat << EOF > rc.eos |
|
|
|
|
|
#!/bin/sh |
|
|
|
|
|
# |
|
|
|
|
|
# startup script to get node configs from VM Maestro |
|
|
|
|
|
# |
|
|
|
|
|
|
|
|
|
|
|
echo "Getting switch config from config drive..." |
|
|
|
|
|
echo "==========================================" |
|
|
|
|
|
mkdir /config-drive |
|
|
|
|
|
mount /dev/sdb1 /config-drive |
|
|
|
|
|
|
|
|
|
|
|
echo "Getting ip address for ma1 via dhcp..." |
|
|
|
|
|
echo "==========================================" |
|
|
|
|
|
dhclient -r ma1 |
|
|
|
|
|
dhclient -1 -v ma1 >/mnt/flash/dhclient.log |
|
|
|
|
|
IP=\$(ip addr show ma1 | grep inet | tr -s ' ' | cut -d ' ' -f 3 | sed s/"\/"/"\\\\\\\\\/"/g) |
|
|
|
|
|
echo \$IP |
|
|
|
|
|
sed s/"! ip of ma1 configured on launch"/"ip address \$IP"/g /config-drive/veos_config.txt >/mnt/flash/startup-config.tmp |
|
|
|
|
|
cat /mnt/flash/startup-config.tmp |
|
|
|
|
|
echo |
|
|
|
|
|
|
|
|
|
|
|
echo "Copying switch config from config drive..." |
|
|
|
|
|
echo "==========================================" |
|
|
|
|
|
cp /mnt/flash/startup-config.tmp /mnt/flash/startup-config |
|
|
|
|
|
EOF |
|
|
|
|
|
chmod 755 rc.eos |
|
|
|
|
|
cd .. |
|
|
|
|
|
umount swi |
|
|
|
|
|
rmdir swi |
|
|
|
|
|
|
|
|
|
|
|
echo |
|
|
echo "Injecting new partitions from vEOS vmdk in Aboot image..." |
|
|
echo "Injecting new partitions from vEOS vmdk in Aboot image..." |
|
|
echo "===========================================================" |
|
|
echo "===========================================================" |
|
|
|
|
|
|
|
@ -79,12 +123,14 @@ dd if=$VEOS_VMDK_BASENAME-p1.raw of=/dev/loop0p2 |
|
|
dd if=$VEOS_VMDK_BASENAME-p2.raw of=/dev/loop0p3 |
|
|
dd if=$VEOS_VMDK_BASENAME-p2.raw of=/dev/loop0p3 |
|
|
kpartx -d $TMP_NAME.raw |
|
|
kpartx -d $TMP_NAME.raw |
|
|
|
|
|
|
|
|
|
|
|
echo |
|
|
echo "Convert new image to qcow2..." |
|
|
echo "Convert new image to qcow2..." |
|
|
echo "===========================================================" |
|
|
echo "===========================================================" |
|
|
|
|
|
|
|
|
# convert raw to qcow2 |
|
|
# convert raw to qcow2 |
|
|
qemu-img convert -O qcow2 $TMP_NAME.raw $TMP_NAME.qcow2 |
|
|
qemu-img convert -O qcow2 $TMP_NAME.raw $TMP_NAME.qcow2 |
|
|
|
|
|
|
|
|
|
|
|
echo |
|
|
echo "Cleaning up..." |
|
|
echo "Cleaning up..." |
|
|
echo "===========================================================" |
|
|
echo "===========================================================" |
|
|
|
|
|
|
|
@ -94,9 +140,10 @@ rm $VEOS_VMDK_BASENAME-p1.raw |
|
|
rm $VEOS_VMDK_BASENAME-p2.raw |
|
|
rm $VEOS_VMDK_BASENAME-p2.raw |
|
|
rm $VEOS_VMDK_BASENAME.raw |
|
|
rm $VEOS_VMDK_BASENAME.raw |
|
|
|
|
|
|
|
|
|
|
|
echo |
|
|
echo "Importing image into glance..." |
|
|
echo "Importing image into glance..." |
|
|
echo "===========================================================" |
|
|
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=cdrom |
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
#testing: |
|
|
#testing: |
|
|
# |
|
|
# |
|
|