Created
March 1, 2019 11:33
-
-
Save dmi-try/c2ca0eaf984adc05e1aab6593ab738ed to your computer and use it in GitHub Desktop.
Sum openstack quotas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import openstack | |
from collections import defaultdict | |
default_compute_quotas= { | |
'injected_file_content_bytes': 10240, | |
'metadata_items': 128, | |
'server_group_members': 50, | |
'server_groups': 10, | |
'ram': 0, | |
'floating_ips': 10, | |
'key_pairs': 100, | |
'id': '', | |
'instances': -1, | |
'security_group_rules': 20, | |
'injected_files': 5, | |
'cores': 0, | |
'fixed_ips': -1, | |
'injected_file_path_bytes': 255, | |
'security_groups': 10 | |
} | |
default_network_quotas= { | |
'subnet': 500, | |
'network': 500, | |
'floatingip': 200, | |
'subnetpool': -1, | |
'security_group_rule': 500, | |
'security_group': 50, | |
'router': 50, | |
'rbac_policy': 10, | |
'port': -1 | |
} | |
default_volume_quotas={ | |
'snapshots_ceph-ssd': -1, | |
'per_volume_gigabytes': -1, | |
'gigabytes_ceph-ssd': -1, | |
'groups': 10, | |
'volumes_standard-iops': -1, | |
'gigabytes': 1000, | |
'backup_gigabytes': 1000, | |
'snapshots': 50, | |
'volumes_ceph-ssd': -1, | |
'gigabytes_standard-iops': -1, | |
'volumes': 50, | |
'backups': 10, | |
'id': '', | |
'snapshots_standard-iops': -1 | |
} | |
openstack.enable_logging() | |
conn = openstack.connect() | |
interesting_quotas=['ram', 'cores', 'floatingip', 'gigabytes'] | |
total = defaultdict(int) | |
def show_diff_and_sum(data, default): | |
for q in data: | |
if q != 'id' and data[q] != default[q]: | |
print("\t%s: %d" %(q, data[q])) | |
if q in interesting_quotas: | |
total[q] += data[q] | |
for project in conn.identity.projects(): | |
if project.name.endswith('team'): | |
print("Project: %s" % project.name) | |
show_diff_and_sum(conn.get_compute_quotas(project.id), default_compute_quotas) | |
show_diff_and_sum(conn.get_network_quotas(project.id), default_network_quotas) | |
show_diff_and_sum(conn.get_volume_quotas(project.id), default_volume_quotas) | |
print("Total:") | |
for (key, value) in total.items(): | |
print("\t%s: %d" % (key, value)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment