summaryrefslogtreecommitdiff
path: root/tools/heat-jeos.sh
blob: 54034ca5e916f6f13315c0fda3c3fbe57a79a087 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
# Build a JEOS image using OZ

exit_usage(){
    echo "Error : $1"
    echo "Usage $0 <tdl file> <image name>"
    echo "Note tdl file must be a valid Oz TDL"
    echo "Note image name must match the name defined in the TDL"
    exit 1
}

DISK_FORMAT="qcow2"
LIBVIRT_IMGDIR="/var/lib/libvirt/images"
DEBUG="-d 3"

if [ $# -ne 2 ]; then
    exit_usage "Insufficient arguments"
fi
TDLFILE=$1
TDLNAME=$2
LIBVIRT_XMLFILE="/tmp/${TDLNAME}_libvirtxml.$$"

# Sanity check user input
if [ ! -s "${TDLFILE}" ]
then
    exit_usage "${TDLFILE} does not exist or is empty"
fi

if ! grep -q ${TDLNAME} ${TDLFILE}; then
    exit_usage "${TDLNAME} not defined in ${TDLFILE}"
fi

if [ -e "${LIBVIRT_IMGDIR}/${TDLNAME}.dsk" ]; then
    exit_usage "${LIBVIRT_IMGDIR}/${TDLNAME}.dsk already exists, please remove then re-run"
fi

oz-install -u ${DEBUG} ${TDLFILE} -x ${LIBVIRT_XMLFILE}

DSKFILE="${LIBVIRT_IMGDIR}/${TDLNAME}.dsk"
FMTFILE="${LIBVIRT_IMGDIR}/${TDLNAME}.${DISK_FORMAT}"
qemu-img convert -c -O ${DISK_FORMAT} ${DSKFILE} ${FMTFILE}

if [ -f ${FMTFILE} ]; then
    echo "Image ${FMTFILE} creation complete."
    echo "Add the image to glance with the command:"
    GLANCECMD="sudo -E glance add name=${TDLNAME} is_public=true disk_format=${DISK_FORMAT} container_format=bare"
    echo "${GLANCECMD} < ${FMTFILE}"
else
    echo "Error creating image file ${FMTFILE}"
fi

rm -f ${LIBVIRT_XMLFILE}