3 # Copyright (c) 2016 Cisco and/or its affiliates.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
18 echo "Syntax: $0 <path to image file>"
20 echo "Environment variables that are required:"
21 echo " VIRL_USER, VIRL_PASSWORD - VIRL username and password"
22 echo " VIRL_IMAGE_SUBTYPE - Image subtype to use (most likely 'server')"
23 echo " VIRL_IMAGE_NAME - The intended name for the image in VIRL"
29 if [ "$VIRL_USER" = "" ] || [ "$VIRL_PASSWORD" = "" ]
31 echo "VIRL user or password not defined, not uploading image to VIRL."
32 echo "Define VIRL_USER and VIRL_PASSWORD environment variables if image upload"
33 echo "to VIRL is intended."
37 if [ "$VIRL_IMAGE_SUBTYPE" = "" ] || [ "$VIRL_IMAGE_NAME" = "" ]
39 echo "VIRL_IMAGE_SUBTYPE, VIRL_IMAGE_NAME must both be defined"
40 echo "variables must all be set."
44 if [ ! -f $VIRL_IMAGE_FILE ]
46 echo "VIRL image file $VIRL_IMAGE_FILE not found"
50 echo Uploading file $VIRL_IMAGE_FILE to VIRL
51 echo as $VIRL_IMAGE_NAME
53 export VIRL_IMAGE_NAME
55 existing_image_id=$(virl_uwm_client --quiet -u ${VIRL_USER} -p ${VIRL_PASSWORD} \
57 grep -E "^ u'name'|^ u'id'" | \
58 grep -B 1 "u'${VIRL_IMAGE_SUBTYPE}-${VIRL_IMAGE_NAME}'" | \
62 if [ "${existing_image_id}" = "" ]
64 echo Image does not exist yet
66 echo Image exists with ID $existing_image_id
67 virl_uwm_client --quiet -u ${VIRL_USER} -p ${VIRL_PASSWORD} image-delete \
68 --id ${existing_image_id}
71 virl_uwm_client -u ${VIRL_USER} -p ${VIRL_PASSWORD} image-create --subtype ${VIRL_IMAGE_SUBTYPE} --version ${VIRL_IMAGE_NAME} --image-on-server ${VIRL_IMAGE_FILE}