Ask Your Question
0

Can I make API calls using Python SDK?

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

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 https://ask.openstack.org/en/question/127408/how-to-retrieve-project-properties/ (my other question) regarding that...

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

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

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

Stats

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

Seen: 49 times

Last updated: May 14 '20