From 5c9dffe5d7b13e54a8de72d6024c694fea458d1a Mon Sep 17 00:00:00 2001 From: Sebastian Rieger Date: Tue, 28 Feb 2017 17:31:53 +0100 Subject: [PATCH] fixed default subtype creation to support VIRL version <1.3 --- .../create-arista-veos-image.sh | 81 ++++++++++++++----- 1 file changed, 59 insertions(+), 22 deletions(-) diff --git a/create-arista-veos-image/create-arista-veos-image.sh b/create-arista-veos-image/create-arista-veos-image.sh index ce7f50e..f601ccf 100644 --- a/create-arista-veos-image/create-arista-veos-image.sh +++ b/create-arista-veos-image/create-arista-veos-image.sh @@ -15,6 +15,7 @@ # V1.4.1 fixed check for existing images # V1.5 fixed detection of missing loop files for Ubuntu 16.04 in VIRL >=1.3, added default subtype creation # V1.51 fixed default subtype creation to use ssh management and max 22 ports, changed ram to 2GB as recommended by Arista +# V1.52 fixed default subtype creation to support VIRL version <1.3 # usage if [ ! $# -eq 3 ] ; then @@ -318,43 +319,79 @@ else fi # create deault subtype -cat << EOF > dynamic-subtype-$GLANCE_IMAGE_NAME.json.default +cat << EOF > dynamic-subtype-$GLANCE_IMAGE_NAME.json.default.virl-above-1.3 { "dynamic-subtypes": [ { - "plugin_base": "generic", - "device_type": "switch", - "plugin_desc": "Arista vEOS", - "cli_protocol": "ssh", + "plugin_base": "generic", + "device_type": "switch", + "plugin_desc": "Arista vEOS", + "cli_protocol": "ssh", "plugin_name": "$GLANCE_IMAGE_NAME", - "cli_serial": 1, - "interface_range": 22, - "gui_visible": true, - "interface_pattern": "Ethernet{0}", - "baseline_image": "$GLANCE_IMAGE_NAME", - "config_disk_type": "disk", - "hw_ram": 2048, - "hw_vm_extra": "", - "gui_icon": "iosvl2", - "config_file": "/veos_config.txt", - "interface_first": 1, - "deprecated_use": "", - "baseline_flavor": "$GLANCE_IMAGE_NAME.medium", + "cli_serial": 1, + "interface_range": 22, + "gui_visible": true, + "interface_pattern": "Ethernet{0}", + "baseline_image": "$GLANCE_IMAGE_NAME", + "config_disk_type": "disk", + "hw_ram": 2048, + "hw_vm_extra": "", + "gui_icon": "iosvl2", + "config_file": "/veos_config.txt", + "interface_first": 1, + "deprecated_use": "", + "baseline_flavor": "$GLANCE_IMAGE_NAME.medium", "interface_management": "Management1" } ] } EOF -CHECKING_FOR_EXISTING_SUBTYPE=$(virl_uwm_client subtype-info 2>&1 | grep $GLANCE_IMAGE_NAME) -if [ $? == 1 ]; then +cat << EOF > dynamic-subtype-$GLANCE_IMAGE_NAME.json.default.virl-below-1.3 +{ + "dynamic-subtypes": [ + { + "plugin_base": "generic", + "plugin_desc": "Arista vEOS", + "cli_protocol": "ssh", + "plugin_name": "$GLANCE_IMAGE_NAME", + "cli_serial": 1, + "interface_range": 22, + "gui_visible": true, + "interface_pattern": "Ethernet{0}", + "baseline_image": "$GLANCE_IMAGE_NAME", + "config_disk_type": "disk", + "hw_ram": 2048, + "hw_vm_extra": "", + "gui_icon": "iosvl2", + "config_file": "/veos_config.txt", + "interface_first": 1, + "deprecated_use": "", + "baseline_flavor": "$GLANCE_IMAGE_NAME.medium", + "interface_management": "Management1" + } + ] +} +EOF +CHECKING_FOR_EXISTING_SUBTYPE=$(virl_uwm_client subtype-info --name $GLANCE_IMAGE_NAME 2>&1) +if [ $? == 255 ]; then echo "Creating default subtype $GLANCE_IMAGE_NAME..." echo "===========================================================" - virl_uwm_client subtype-import --dynamic-subtypes @dynamic-subtype-$GLANCE_IMAGE_NAME.json.default + CHECKING_FOR_EXISTING_DEVICE_TYPE=$(virl_uwm_client subtype-info 2>&1 | grep u\'device_type\':) + if [ $? == 1 ]; then + # device_type attribute is not available in VIRL < 1.3, use JSON definition of subtype without this attribute + echo "detected VIRL version < 1.3, selecting appropriate subtype to import" + virl_uwm_client subtype-import --dynamic-subtypes @dynamic-subtype-$GLANCE_IMAGE_NAME.json.default.virl-below-1.3 + else + echo "detected VIRL version > 1.3.0, selecting appropriate subtype to import" + # device_type attribute is available, use JSON definition of subtype including this attribute + virl_uwm_client subtype-import --dynamic-subtypes @dynamic-subtype-$GLANCE_IMAGE_NAME.json.default.virl-above-1.3 + fi else echo "Default subtype $GLANCE_IMAGE_NAME already exists..." fi -rm dynamic-subtype-$GLANCE_IMAGE_NAME.json.default +rm dynamic-subtype-$GLANCE_IMAGE_NAME.json.default.virl-above-1.3 +rm dynamic-subtype-$GLANCE_IMAGE_NAME.json.default.virl-below-1.3 echo echo "Image creation successful."