sh 检查图像是否存在于 Openstack 中

sh to check if an image exists in Openstack

有没有一种方法可以使用 shell 脚本通过名称 "myimage" 检查 glance 创建的图像是否存在于 Openstack 中?

glance image-create --name "myimage" --disk-format qcow2 --container-format bare --is-public True --progress < myimage.qcow2

您可以在 shell 脚本中使用此命令来检查 "myimage" 是否已存在于 glnace 中。

glance image-list | grep myimage

如果图像存在,它将 return 匹配图像名称,否则您将得到零结果。

编辑

#!/bin/sh
image="myimage"
if glance image-list | grep $image > /dev/null
then
    echo "$image already exists"
else
    echo "$image does not exist"
fi