Ask Your Question

Can I make API calls using Python SDK?

asked 2020-05-13 07:30:05 -0500

cacack gravatar image

Essentially I'd like to be able to reuse the connection I've already established using the Python SDK, but be able to make API calls directly. Does the Python SDK provide "helper" functions to do this? I'm trying to avoid having to construct all of this using urllib or something similar.

Additional details -- I'm trying to access metadata attached to a project, which the SDK doesn't appear to make available. See (my other question) regarding that...

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2020-05-14 01:59:53 -0500

pas-ha gravatar image

Yes, with openstacksdk you can make "raw" requests, like:

import openstack
cloud = openstack.connect(cloud="your cloud name from clouds.yaml")
response = cloud.compute.get("/servers")
servers = response.json()["servers"]

The "Connection" object has various 'services' (like "compute" or "identity") that behave much like requests' Sessions already mounted to the appropriate (versioned) API endpoint from the keystone catalog, plus more convenience methods that wrap the raw requests ones.

edit flag offensive delete link more

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower


Asked: 2020-05-13 07:30:05 -0500

Seen: 59 times

Last updated: May 14 '20