OpenStack: Image

Deaktivate image

IMAGE_NAME="Ubuntu 14.04"
openstack image list --status active --name "${IMAGE_NAME}" -c ID -f value | xargs openstack image set --deactivate --private
openstack image list --status active

List the images

openstack image list

Delete all images

for IMAGE in $(openstack image list -c ID -f value); do
    openstack image set --unprotected ${IMAGE}
    openstack image delete ${IMAGE}
done

Delete image

IMAGE_NAME="Ubuntu 16.04"
openstack image set --unprotected ${IMAGE_NAME}
openstack image delete ${IMAGE_NAME}

Deploy ISO image

openstack image create grml --file grml64-small_2018.12.iso  --disk-format iso --container-format bare

Get server image project relation

export OS_CLOUD=dev
echo SERVER_ID IMAGE PROJECT_ID
for IMAGE in $(openstack image list -c ID -c Name -f value | grep -i "Windows Server" | cut -d" " -f1); do
    for SERVER in $(openstack server list --all-projects --image ${IMAGE} -c ID -f value); do
        openstack server show ${SERVER} -f value -c id -c image -c project_id | paste - - -
        # openstack project show sd32sd0fsdfj9sdf9sdf0sda7fsda -f value -c name 
    done
done
 
openstack project show XXX --os-cloud=dev  -f value -c name
openstack server show XXX --os-cloud=dev -f value -c name

Links
https://docs.openstack.org/python-openstackclient/latest/cli/command-objects/image.html
https://docs.openstack.org/glance/latest/admin/manage-images.html