One of the more tedious constant tasks in Openstack, especially if you’re using CI/CD, is to update images. Here’s a little script to make this just a little easier for you.
#!/bin/sh
asksure() {
echo -n "Are you sure (Y/N)? "
while read -r -n 1 -s answer; do
if [[ $answer = [YyNn] ]]; then
[[ $answer = [Yy] ]] && retval=0
[[ $answer = [Nn] ]] && retval=1
break
fi
done
echo # just a final linefeed, optics...
return $retval
}
template=$(basename $1|sed s/.qcow2//ig)
filename=$1
images=$(glance image-list|grep $template|cut -f 3 -d '|'|sed s/\ /''/g)
guids=$(glance image-list|grep $template|cut -f 2 -d '|'|sed s/\ /''/g)
if [ ! -z $images ]; then
echo images exist in glance
echo $images
echo "Image(s) will be deleted"
if asksure; then
echo "Delete in progress ..."
glance image-delete $guids
else
exit 1
fi
fi
echo creating image $filename for new template $template
glanceout=$(openstack image create \
--disk-format qcow2 \
--container-format bare \
--public \
--file $filename \
$template)
id=$(glance image-list |grep $template|cut -f 2 -d '|'|sed s/\ //g)
glance image-update \
--property hw_disk_bus=scsi \
--property hw_cdrom_bus=ide \
$id
NOTE: On some versions of Ubuntu, the Read command doesn’t work exactly as expected (I haven’t put the effort in to fine-tune this) so please debug this before using, and as always: Please be careful.
Discover more from Christine Alifrangis
Subscribe to get the latest posts sent to your email.
