Search code examples
pythonopenstackopenstacksdk

How To Fetch Projec quotas using OpenstackSDK?


I am looking for a small code to fetch all my projects quotas limits. From openstacksdk dev repository i can see there is connection called compute.v2.limits, but using that i m getting blank output like below.

import openstack
import openstack.compute.v2.limits
import os
import datetime

################## getting limits ##########################
ip='10.6.X.X'
auth_url_domain="https://10.6.X.X:13000/v3"
conn = openstack.connect(auth_url=auth_url_domain, project_name="admin", username="admin", domain_name="default",password="XXXXXX", cacert="/root/app/cacrt/cacrt/ca.crt10.6.X.X.pem")
data=openstack.compute.v2.limits.AbsoluteLimits(session=conn)
print(data.to_dict())

Output i m getting ( key is ok but values are none . I want values should be as per values set for all projects):

{'server_groups': None, 'keypairs': None, 'total_ram_used': None,
 'total_cores': None, 'instances_used': None, 'total_cores_used': None,
 'instances': None, 'id': None, 'security_groups': None,
 'total_ram': None, 'floating_ips': None, 'location': None,
 'personality_size': None, 'server_groups_used': None,
 'personality': None, 'security_group_rules': None,
 'name': None, 'server_group_members': None, 'floating_ips_used': None,
 'image_meta': None, 'server_meta': None, 'security_groups_used': None}

Solution

  • You could get the project quota only by openstack.connection, like this:

    conn = openstack.connect(auth_url=auth_url_domain...)
    quotas = conn.get_compute_quotas(project_name_or_id)
    

    And there is more other common methods, you could check it while you need.

    I want values should be as per values set for all projects

    If you want to get all projects quotas, you should create the consistent connection because of the connection bind the project as the parameter of openstack.connect method. But if you are the admin role, you could get all projects info.