List OpenStack images via API
The snippet can be accessed without any authentication.
Authored by
František Řezníček
# source application credentials
[freznicek@lenovo-t14 ~ 0]$ source ~/conf/prod-meta-cloud-new-openstack-all-roles-openrc.sh.inc
# execute single purpose script
[freznicek@lenovo-t14 ~ 0]$ python3 /tmp/image-list.py > images.log
[freznicek@lenovo-t14 ~ 0]$ head images.log
[{'checksum': '79a35332384d05c2a2b282df4a58d8e4',
'container_format': 'bare',
'created_at': '2022-12-01T12:16:59Z',
'default_user': 'ubuntu',
'disk_format': 'raw',
'file': '/v2/images/37c1***49-b***a-4**e-a**6-6***3c7a5/file',
'hw_disk_bus': 'scsi',
'hw_qemu_guest_agent': 'yes',
'hw_rng_model': 'virtio',
image-list.py 611 B
import os
import pprint
import glanceclient
from keystoneauth1 import session
from keystoneauth1.identity.v3.application_credential import ApplicationCredential
AUTH = ApplicationCredential(
auth_url=os.environ.get("OS_AUTH_URL", None),
application_credential_id=os.environ.get("OS_APPLICATION_CREDENTIAL_ID", None),
application_credential_secret=os.environ.get("OS_APPLICATION_CREDENTIAL_SECRET", None),
)
# Establishing OpenStack general session
SESSION = session.Session(auth=AUTH)
# ask for Glance images
GC = glanceclient.Client("2", session=SESSION)
pprint.pprint(list(GC.images.list()))
Please register or sign in to comment