Created
March 1, 2017 19:29
-
-
Save freyes/96ebf02428f02fd2414d5ce2047e8c58 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/python | |
| # Example output: | |
| # 7 foo | |
| # 32 bar | |
| # 33 some | |
| # 32 example | |
| __author__ = "Felipe Reyes <[email protected]>" | |
| import os | |
| from collections import defaultdict | |
| from novaclient import client | |
| from keystoneauth1.identity import v2 | |
| from keystoneauth1 import session | |
| from keystoneclient.v2_0 import client as kclient | |
| username = os.environ['OS_USERNAME'] | |
| password = os.environ['OS_PASSWORD'] | |
| tenant_name = os.environ['OS_TENANT_NAME'] | |
| auth_url = os.environ['OS_AUTH_URL'] | |
| auth = v2.Password(username=username, password=password, | |
| tenant_name=tenant_name, auth_url=auth_url) | |
| sess = session.Session(auth=auth) | |
| keystone = kclient.Client(session=sess) | |
| c = client.Client(2, username, | |
| password, | |
| tenant_name, | |
| auth_url) | |
| tenants = defaultdict(int) | |
| for server in c.servers.list(search_opts={'all_tenants': True}): | |
| tenants[getattr(server, 'tenant_id')] += 1 | |
| for k, v in tenants.items(): | |
| print('{:>3} {}'.format(v, keystone.tenants.get(k).name)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment