Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #/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])
Add Comment
Please, Sign In to add comment