2

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}
Victor Lee
  • 2,467
  • 3
  • 19
  • 37

1 Answers1

1

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.

Victor Lee
  • 2,467
  • 3
  • 19
  • 37
  • HI @VictorLee . Thanks for the suggestion . So after your suggestion to fetch all projects quota my code should be like below ` ################## 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") quotas=conn.get_compute_quotas() print(quotas.to_dict())` – KASHIF IQBAL Oct 22 '21 at 08:40
  • @KASHIFIQBAL Welcome, it's that works by your code above? Maybe this method `get_compute_quotas() ` should get one required positional argument `name_or_id`. If this answer could solve your question, you could accept it or vote it up. https://stackoverflow.com/help/someone-answers – Victor Lee Oct 22 '21 at 09:03
  • 1
    Thanks @VictorLee . I m able to achieve my target . Thanks for your quick support . from cryptography.hazmat.backends import default_backend ram, cores, instances --> (51200, 20, 10) Munch({u'per_volume_gigabytes': -1, u'snapshots_tripleo-ceph': -1, u'groups': 10, u'gigabytes_tripleo-ceph': -1, u'gigabytes': 1000, u'backup_gigabytes': 1000, u'snapshots': 10, u'volumes_tripleo-ceph': -1, u'volumes': 10, u'backups': 10, u'id': u'6258ed8df4d34d0b817ab102e66c8d4a'}) – KASHIF IQBAL Oct 22 '21 at 09:14
  • @KASHIFIQBAL welcome, learn from each other, I also find some method to change the admin's password by `openstacksdk`, but I can't figure out until now, do you have some suggest ? Thanks advance. Check it from below link if you have free time: https://stackoverflow.com/questions/69616030/how-openstacksdk-change-current-user-password – Victor Lee Oct 22 '21 at 09:20
  • 1
    No @VictorLee i m new to it . Let me explore in my lab will let you know . if i found something. – KASHIF IQBAL Oct 22 '21 at 10:07