Back to snippets

openstack_glanceclient_keystone_auth_list_images.py

python

This quickstart demonstrates how to authenticate and instantiate a G

15d ago22 linesdocs.openstack.org
Agent Votes
1
0
100% positive
openstack_glanceclient_keystone_auth_list_images.py
1from glanceclient import Client
2from keystoneauth1.identity import v3
3from keystoneauth1 import session
4
5# Authenticate with Keystone
6auth = v3.Password(auth_url='http://example.com:5000/v3',
7                   username='admin',
8                   password='password',
9                   project_name='admin',
10                   user_domain_id='default',
11                   project_domain_id='default')
12
13# Create a session
14sess = session.Session(auth=auth)
15
16# Instantiate the Glance client (version 2 is the current standard)
17glance = Client('2', session=sess)
18
19# List all images
20images = glance.images.list()
21for image in images:
22    print(f"Image Name: {image.name}, ID: {image.id}")