-
Notifications
You must be signed in to change notification settings - Fork 3
/
buckets.py
executable file
·105 lines (88 loc) · 3.19 KB
/
buckets.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
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from usage import usage
import restclient
rest_cmds = {
'bucket-list': '/pools/default/buckets',
'bucket-stats': '/pools/default/buckets/{0}/stats?zoom=hour',
'bucket-node-stats': '/pools/default/buckets/{0}/stats/{1}?zoom={2}'
}
methods = {
'bucket-list': 'GET',
'bucket-stats': 'GET',
'bucket-node-stats': 'GET',
}
class Buckets:
def __init__(self):
self.debug = False
self.rest_cmd = rest_cmds['bucket-list']
self.method = 'GET'
def runCmd(self, cmd, server, port,
user, password, opts):
self.user = user
self.password = password
bucketname = ''
buckettype = ''
authtype = 'sasl'
bucketport = '11211'
bucketpassword = ''
bucketramsize = ''
bucketreplication = '1'
output = 'default'
for (o, a) in opts:
if o == '-b' or o == '--bucket':
bucketname = a
if o == '--bucket-type':
buckettype = a
if o == '--bucket-port':
bucketport = a
if o == '--bucket-password':
bucketpassword = a
if o == '--bucket-ramsize':
bucketramsize = a
if o == '--bucket-replica':
bucketreplication = a
if o == '-d' or o == '--debug':
self.debug = True
if o in ('-o', '--output'):
output = a
self.rest_cmd = rest_cmds[cmd]
rest = restclient.RestClient(server, port, {'debug':self.debug})
# get the parameters straight
opts = {}
opts['error_msg'] = "unable to %s" % cmd
opts['success_msg'] = "%s" % cmd
data = rest.restCmd(methods[cmd], self.rest_cmd,
self.user, self.password, opts)
return rest.getJson(data)
class BucketStats:
def __init__(self, bucket_name):
self.debug = False
self.rest_cmd = rest_cmds['bucket-stats'].format(bucket_name)
self.method = 'GET'
def runCmd(self, cmd, server, port,
user, password, opts):
opts = {}
opts['error_msg'] = "unable to %s" % cmd
opts['success_msg'] = "%s" % cmd
#print server, port, cmd, self.rest_cmd
rest = restclient.RestClient(server, port, {'debug':self.debug})
data = rest.restCmd(methods[cmd], self.rest_cmd,
user, password, opts)
return rest.getJson(data)
class BucketNodeStats:
def __init__(self, bucket_name, stat_name, scale):
self.debug = False
self.rest_cmd = rest_cmds['bucket-node-stats'].format(bucket_name, stat_name, scale)
self.method = 'GET'
#print self.rest_cmd
def runCmd(self, cmd, server, port,
user, password, opts):
opts = {}
opts['error_msg'] = "unable to %s" % cmd
opts['success_msg'] = "%s" % cmd
#print server, port, cmd, self.rest_cmd
rest = restclient.RestClient(server, port, {'debug':self.debug})
data = rest.restCmd(methods[cmd], self.rest_cmd,
user, password, opts)
return rest.getJson(data)