openstackopenstack-cinderopenstacksdkopenstack-python-api

Showing Volume Details using python openstacksdk, python novaclient, python cinderclient


Hello guys and I hope you're having a great day. I have a question about using Openstack API in Python.

I'm using python-novaclient for getting server details and flavor details. And I want to get the volume details too but I don't know how to do it, I've tried to collect volume details but it failed somehow and I need to ask you guys if you have any idea.

This information is what I want to get:
volume_id, attached to (w/c volume), name, status and volume_type (CEPH or LVM)

I used python-cinderclient, but I only got the volume_id.
Here's the code:

volumes = cinder.volumes.list()

Can someone help me to get the other data? Other than running Openstack command-line in the server, I just need some Python module to get these data.

Thanks in advance.


Solution

  • I've finally figured it out, and I'm going to answer this for anyone who is interested in Openstack SDK or other Python API for Openstack.

    First, for authentication you need to use Keystone API, the documentation is all over the internet so no need to worry, you could just oversee in your Openstack for credentials needed. And for my question, I use the function get_volume from Connection class. Please see the documentation for this. You can read other documentation as well on the internet.

    So, here is the example of how to get volumes details:

    vol = conn.get_volume(volume_id)
    print(vol)