forked from RedHat-Israel/ROSE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rtp-admin
executable file
·66 lines (53 loc) · 1.64 KB
/
rtp-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
#!/usr/bin/env python
import sys
import os
import xmlrpclib
from rtp.common import config
class Client(object):
def __init__(self, args):
self.args = args
self.server = None
def run(self):
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:
print 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:
print msg
basename = os.path.basename(self.args[0])
commands = '|'.join(self.commands())
print 'Usage: %s <server-address> [%s]' % (basename, commands)
sys.exit(2)
if __name__ == '__main__':
Client(sys.argv).run()