Ask Your Question
1

How to get service catalog with Python API?

asked 2019-08-07 15:01:07 -0500

Josh Fuhs gravatar image

I've been unsuccessful at finding documentation describing how to pull the service catalog via the Python API. It seems like this should be included in any "Getting Started with OpenStack and Python," but my search results are empty.

This describes the REST structures a bit: https://docs.openstack.org/keystone/latest/contributor/service-catalog.html (https://docs.openstack.org/keystone/l...)

edit retag flag offensive close merge delete

Comments

The OpenStack SDK has a method for listing all endpoints. There is also a service list documented further down on that page.

DISCLAIMER: I haven't tried it.

Bernd Bausch gravatar imageBernd Bausch ( 2019-08-07 18:33:47 -0500 )edit

I hadn't even been using the openstack module. Most of the documentation I see goes directly to the service client APIs. I've found something that appears to work with keystoneauth1. I'll write it up shortly.

Josh Fuhs gravatar imageJosh Fuhs ( 2019-08-08 14:39:44 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-08-09 11:35:09 -0500

Josh Fuhs gravatar image

The following code will produce a service-type to public-endpoint URL dictionary in service_endpoints:

from keystoneauth1 import loading, identity, session, exceptions

auth = identity.Password(
    auth_url,
    username=username,
    password=password,
    user_domain_id="default",
    project_domain_id="default",
    project_name=project_name )
sess = session.Session( auth=auth )

# Non-intuitive line
auth_info = sess.auth.get_auth_ref(sess)
catalog = auth_ref.service_catalog.get_endpoints( interface="public" )
service_endpoints = {}
for s_name in catalog:
    s = catalog[s_name]
    service_endpoints[s_name] = s[0]["url"]

# Here's the map.
service_endpoints
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower

Stats

Asked: 2019-08-07 15:01:07 -0500

Seen: 30 times

Last updated: Aug 07