Created
February 9, 2018 18:20
-
-
Save niedbalski/bd449fae04d67530209c167d453eaa7e to your computer and use it in GitHub Desktop.
OpenStack Quota by project
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 python3 | |
# ./{0} cloud.linaro.cloud cloud.csv | |
from collections import OrderedDict | |
import shade | |
import sys | |
import csv | |
def main(cloud): | |
cloud = shade.openstack_cloud(cloud=cloud) | |
attrs = ('ram', 'cores', 'instances', 'floatingip', 'subnetpool') | |
to_skip = ('service', ) | |
to_print = [] | |
for project in filter(lambda name: name not in to_skip, | |
cloud.list_projects()): | |
compute, network = (cloud.get_compute_quotas(project.id), | |
cloud.get_network_quotas(project.id)) | |
project_quota = OrderedDict({'project': project.name}) | |
project_quota.update({'description': project.description}) | |
for attribute, value in compute.items(): | |
if attribute in attrs: | |
project_quota.update({attribute: value}) | |
for attribute, value in network.items(): | |
if attribute in attrs: | |
project_quota.update({attribute: value}) | |
to_print.append(project_quota) | |
with open(sys.argv[2], 'w', newline='') as fd: | |
writer = csv.DictWriter(fd, fieldnames=to_print[0].keys()) | |
writer.writeheader() | |
for row in to_print: | |
writer.writerow(row) | |
if __name__ == "__main__": | |
main(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment