-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild_stat_browser.py
executable file
·68 lines (56 loc) · 2.37 KB
/
build_stat_browser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#! /usr/bin/env python
"""
Connects to PAPI to download list of current keys.
Outputs an html app that provides an interface to browse stat keys.
"""
from builtins import input
import getpass
import logging
import sys
from optparse import OptionParser
import urllib3
from stat_key_browser.browser_builder import BrowserBuilder
def get_parser():
"""Return a parser to parse CLI args."""
parser = OptionParser()
parser.add_option('-c', '--cluster', dest='cluster', type='string',
help='Cluster IP or hostname')
parser.add_option('-u', '--user', dest='username', type='string',
help='Username to authenticate to PAPI or omit for prompt')
parser.add_option('-p', '--password', dest='password', type='string',
help='Password to authenticate to PAPI or omit for prompt')
parser.add_option('-l', '--log', dest='logfile', type='string',
help='Log to a file instead of STDERR')
parser.add_option('-x', '--anon-ip', action='store_true', dest='anon_ip',
default=False, help='Do not store cluster IP in output')
parser.add_option('--debug', action='store_true', dest='debug', default=False)
return parser
def build_browser():
"""Parse opts and run a BrowerBuilder."""
parser = get_parser()
(opts, args) = parser.parse_args()
if opts.cluster is None:
opts.cluster = input('Cluster IP or hostname: ')
if opts.debug:
log_lvl = logging.DEBUG
logging.getLogger("urllib3").setLevel(logging.INFO)
else:
log_lvl = logging.INFO
logging.getLogger("urllib3").setLevel(logging.WARNING)
if opts.logfile:
logging.basicConfig(level=log_lvl, datefmt='%Y-%m-%dT%H:%M:%S',
format='%(asctime)s [%(levelname)s] %(message)s',
filename=opts.logfile)
else:
logging.basicConfig(level=log_lvl, datefmt='%Y-%m-%dT%H:%M:%S',
format='%(asctime)s [%(levelname)s] %(message)s')
if not opts.username:
opts.username = input('Cluster username: ')
if not opts.password:
opts.password = getpass.getpass()
store_ip = not opts.anon_ip
bb = BrowserBuilder(opts.cluster, opts.username, opts.password, store_ip)
bb.build_browser()
if __name__ == '__main__':
urllib3.disable_warnings()
build_browser()