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

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)
CHECKING_FOR_EXISTING_FLAVOR=$(nova flavor-show vEOS.medium 2>&1)
if [ $? == 1 ]; then
echo "Creating default flavor $GLANCE_IMAGE_NAME.medium..."
echo "Creating default flavor vEOS.medium..."
echo "==========================================================="
nova flavor-create --is-public true $GLANCE_IMAGE_NAME.medium auto 2048 0 1
nova flavor-create --is-public true vEOS.medium auto 2048 0 1
fi
CHECKING_FOR_EXISTING_FLAVOR=$(nova flavor-show $GLANCE_IMAGE_NAME.small 2>&1)
if [ $? == 1 ]; then
echo "Creating default flavor $GLANCE_IMAGE_NAME.small..."
echo "==========================================================="
nova flavor-create --is-public true $GLANCE_IMAGE_NAME.small auto 1024 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:
#

Loading…
Cancel
Save