Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1818 from rackerlabs/worker-tenants-script
script to print worker tenants
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/env python | ||
|
||
""" | ||
Script to print worker tenants. It gets all tenants from metrics and prints | ||
tenants which are not in "convergence-tenants" config. Takes chef otter.json | ||
as argument | ||
""" | ||
|
||
from __future__ import print_function | ||
|
||
import json | ||
import os | ||
import sys | ||
|
||
import treq | ||
|
||
from twisted.internet import task | ||
from twisted.internet.defer import inlineCallbacks | ||
|
||
from otter.auth import generate_authenticator, public_endpoint_url | ||
from otter.util.http import append_segments, check_success, headers | ||
|
||
|
||
def get_tenant_ids(token, catalog): | ||
endpoint = public_endpoint_url(catalog, "cloudMetrics", "IAD") | ||
d = treq.get( | ||
append_segments(endpoint, "metrics", "search"), | ||
headers=headers(token), params={"query": "*.*.desired"}) | ||
d.addCallback(check_success, [200]) | ||
d.addCallback(treq.json_content) | ||
d.addCallback(lambda body: [item["metric"].split(".")[1] for item in body]) | ||
return d | ||
|
||
|
||
@inlineCallbacks | ||
def main(reactor): | ||
conf = json.load(open(sys.argv[1])) | ||
conf = conf["default_attributes"]["otter"]["config"] | ||
conf["identity"]["strategy"] = "single_tenant" | ||
conf["identity"]["username"] = os.environ["OTTERPROD_UNAME"] | ||
conf["identity"]["password"] = os.environ["OTTERPROD_PWD"] | ||
authenticator = generate_authenticator(reactor, conf["identity"]) | ||
token, catalog = yield authenticator.authenticate_tenant("764771") | ||
all_tenants = set((yield get_tenant_ids(token, catalog))) | ||
worker_tenants = all_tenants - set(conf["convergence-tenants"]) | ||
print(*worker_tenants, sep='\n') | ||
|
||
|
||
if __name__ == '__main__': | ||
task.react(main, ()) |