[Openstack-operators] Getting help with Python API

Jared Wilkinson JWilkinson at ebsco.com
Thu Jul 7 14:30:08 UTC 2016


Thanks. I finally figured it out with the help of someone with a bit more Python knowledge than I have. I wasn’t able to figure out that the list was a list of arrays on my own. I would try to get the type for each one of the items in the list (which was the list of tenants, ids, etc), but it would return that it was  ‘<class 'keystoneclient.v2_0.tenants.Tenant'>’ and I didn’t know what to do with that since I expected something like <type ‘dict’> since that’s what it looked like when I just printed the line. After he pointed me to the fact it was an array (still not sure how to determine that other than just recognizing the output), I was able to pull the id just as you referenced.

Now on to figure out the new python-openstackclient API so I can use that instead!

Jared Wilkinson | Senior Infrastructure Engineer – Team Lead
jwilkinson at ebsco.com | (W) 205/981-4018 | (M) 205/259-9802
5724 US Highway 280 East, Birmingham, AL 35242, USA

From: <tadowguy at gmail.com> on behalf of Matt Fischer <matt at mattfischer.com>
Date: Wednesday, July 6, 2016 at 9:04 PM
To: Jared Wilkinson <JWilkinson at ebsco.com>
Cc: "openstack-operators at lists.openstack.org" <openstack-operators at lists.openstack.org>
Subject: Re: [Openstack-operators] Getting help with Python API

When you make the API calls you're going to get back a list python objects which you need to iterate. I believe some APIs will let you ask for specific fields only, but this is simple enough:

    keystone = client.Client(username=Username, password=Password, tenant_name=Tenant,
        auth_url='http://%s:5000/v2.0' % (Ip))
    tenants = keystone.tenants.list()
    tenant_ids = []
    for tenant in tenants:
        tenant_ids.append(tenant.id<http://tenant.id>)

Then you can process the tenant_ids list, of course once you done that you've lost the context of the object (like the name of the tenant).

For stuff like this the docs are your best bet along with introspecting the objects using the interactive python shell:

http://docs.openstack.org/developer/python-keystoneclient/

On Wed, Jul 6, 2016 at 12:53 PM, Jared Wilkinson <JWilkinson at ebsco.com<mailto:JWilkinson at ebsco.com>> wrote:
Hey folks,

I am in the process of teaching myself Python and I have done a couple of free online courses but still have a fairly rudimentary understanding of Python, especially when it comes to using the OpenStack SDK. I was hoping you guys could point me to a mailing list for getting help with using the Python API calls in custom scripts. Specifically, something as simple as, return a list of all the tenant IDs (only) and push that send that to nova quota show and return just the CPU, memory, and storage metrics.

I can get the list of tenants from Keystone, but I can’t get it to just send me the list of IDs (we are using v2 of identity). I have read the documentation, but nothing there seems to help (or I am not quite strong enough in my Python skills to understand it) for this specific instance.

Any direction would be appreciated.

Thanks,
Jared

Jared Wilkinson | Senior Infrastructure Engineer – Team Lead
jwilkinson at ebsco.com<mailto:jwilkinson at ebsco.com> | (W) 205/981-4018<tel:205%2F981-4018> | (M) 205/259-9802<tel:205%2F259-9802>
5724 US Highway 280 East, Birmingham, AL 35242, USA

_______________________________________________
OpenStack-operators mailing list
OpenStack-operators at lists.openstack.org<mailto:OpenStack-operators at lists.openstack.org>
http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-operators

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstack.org/pipermail/openstack-operators/attachments/20160707/5d9121ea/attachment.html>


More information about the OpenStack-operators mailing list