forked from membase/membase-cli
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinfo.py
94 lines (75 loc) · 2.5 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
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
info class
This class implements methods that provide info about a
particular server
"""
import pprint
from membase_info import usage
import restclient
class Info:
def __init__(self):
"""
constructor
"""
# defaults
self.debug = False
self.verbose = False
self.method = 'GET'
self.info = 'all'
self.output = 'standard'
def runCmd(
self,
cmd,
server,
port,
user,
password,
opts,
):
# defaults
standard_result = ''
self.user = user
self.password = password
# set standard opts
output= 'default'
for (o, a) in opts:
if o in ('-o', '--output'):
self.output = a
if o == '-v' or o == '--verbose':
self.verbose = True
if o == '-d' or o == '--debug':
self.debug = True
# allow user to be lazy and not specify port
rest = restclient.RestClient(server, port, {'debug':self.debug})
rest_uri = '/nodes/Self'
# get the parameters straight
opts = {'error_msg':'Unable to obtain server information'}
data = rest.restCmd('GET',
rest_uri,
self.user,
self.password)
if self.output == 'json':
print data
else:
json = rest.getJson(data)
print "%s" % json['hostname']
print "version: %s" % json['version']
print "license: %s" % json['license']
print "licenseValid : %s" % json['licenseValid']
print "licenseUntil: %s" % json['licenseValidUntil']
print "os: %s" % json['os']
print "memoryQuota: %s" % json['memoryQuota']
print "ports:\n\tproxy: %s\n\tdirect: %s" % \
(json['ports']['proxy'], json['ports']['direct'])
storage = json['storage']
for stype in storage:
if storage[stype]:
sobj = storage[stype][0]
print "%s:" % stype
print "\tstate: %s" % sobj['state']
print "\tusage: %d%%" % sobj['diskStats']['usagePercent']
print "\tsize: %d" % sobj['diskStats']['sizeKBytes']
print "\tpath: %s" % sobj['path']
print "\tquota: %s" % sobj['quotaMb']