-
Notifications
You must be signed in to change notification settings - Fork 125
/
rose-admin
executable file
·73 lines (56 loc) · 1.8 KB
/
rose-admin
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
69
70
71
72
73
#!/usr/bin/env python3
import sys
import os
import logging
from xmlrpc import client as xmlrpclib
from rose.common import config
log = logging.getLogger('admin')
class Client(object):
def __init__(self, args):
self.args = args
self.server = None
def run(self):
logging.basicConfig(level=logging.INFO)
if len(self.args) < 2:
self.usage('server-address required')
server_address = self.args[1]
url = 'http://%s:%d/rpc2' % (server_address, config.web_port)
self.server = xmlrpclib.Server(url)
if len(self.args) < 3:
self.usage('Verb required')
verb = self.args[2]
method_name = 'do_' + verb.replace('-', '_')
try:
method = getattr(self, method_name)
except AttributeError:
self.usage('Unknown verb: %r' % verb)
try:
method()
except Exception as e:
log.error("Error running: %s, %s", verb, e)
sys.exit(1)
def do_start(self):
"""start"""
self.server.start()
def do_stop(self):
"""stop"""
self.server.stop()
def do_set_rate(self):
"""set-rate RATE"""
if len(self.args) < 4:
self.usage("RATE required")
rate = float(self.args[3])
self.server.set_rate(rate)
def commands(self):
return sorted(getattr(self, name).__doc__
for name in dir(self)
if name.startswith('do_'))
def usage(self, msg=None):
if msg:
log.info(msg)
basename = os.path.basename(self.args[0])
commands = '|'.join(self.commands())
log.info('Usage: %s <server-address> [%s]', basename, commands)
sys.exit(2)
if __name__ == '__main__':
Client(sys.argv).run()