/
info.py
42 lines (33 loc) · 1.12 KB
/
info.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Provides info about a particular server.
"""
from usage import usage
import restclient
import simplejson
import subprocess
import sys
class Info:
def __init__(self):
self.debug = False
def runCmd(self, cmd, server, port,
user, password, opts):
for (o, a) in opts:
if o == '-d' or o == '--debug':
self.debug = True
rest = restclient.RestClient(server, port, {'debug':self.debug})
opts = {'error_msg': 'server-info error'}
data = rest.restCmd('GET', '/nodes/self',
user, password, opts)
json = rest.getJson(data)
for x in ['license', 'licenseValid', 'licenseValidUntil']:
if x in json:
del(json[x])
if cmd == 'get-server-info':
return json
elif cmd == 'server-eshell':
p = subprocess.call(['erl','-name','ctl@127.0.0.1',
'-setcookie',json['otpCookie'],'-hidden','-remsh',json['otpNode']])
else:
print simplejson.dumps(json, sort_keys=True, indent=2)