-
Notifications
You must be signed in to change notification settings - Fork 8
/
couchbase-cli
executable file
·131 lines (112 loc) · 3.61 KB
/
couchbase-cli
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
couchbase-cli - command-line cluster administration tool
"""
import getopt
import sys
import listservers
import buckets
import node
import info
import util_cli as util
from usage import usage, short_usage
from timeout import TimeoutException
def main():
for x in sys.argv:
if x in ('-h', '--help', 'help'):
usage()
if len(sys.argv) <= 2:
short_usage()
debug = False
(cluster, user, password) = ('', '', '')
try:
(opts, _args) = getopt.getopt(sys.argv[2:],
'a:b:c:dse:gdlmo:OPp:r:Ssu:vV', [
'cluster=',
'debug',
'storage',
'password=',
'user=',
'mem',
'output=',
'os',
'ports',
'stats',
'license',
'server-add=',
'server-add-username=',
'server-add-password=',
'server-remove=',
'server-failover=',
'cluster-init=',
'cluster-init-username=',
'cluster-init-password=',
'cluster-init-port=',
'cluster-init-ramsize=',
'node-init=',
'node-init-data-path=',
'bucket=',
'bucket-type=',
'bucket-port=',
'bucket-password=',
'bucket-ramsize=',
'bucket-replica=',
'wait',
'version'
])
except getopt.GetoptError, err:
usage(err)
commands = {
'host-list' : listservers.ListServers,
'server-list' : listservers.ListServers,
'server-info' : info.Info,
'server-eshell' : info.Info,
'server-add' : node.Node,
'server-readd' : node.Node,
'rebalance' : node.Node,
'rebalance-stop' : node.Node,
'rebalance-status' : node.Node,
'eject-server' : node.Node,
'failover' : node.Node,
'cluster-init' : node.Node,
'node-init' : node.Node,
'bucket-list' : buckets.Buckets,
'bucket-create' : buckets.Buckets,
'bucket-edit' : buckets.Buckets,
'bucket-delete' : buckets.Buckets,
'bucket-flush' : buckets.Buckets
}
cmd = sys.argv[1]
if cmd not in commands:
err_message = ("'%s' is not a couchbase-cli command;" +
" please see -h for more help.") % cmd
usage(err_message)
for (opt, arg) in opts:
if opt in ('-c', '--cluster'):
cluster = arg
if opt in ('-u', '--user'):
user = arg
if opt in ('-p', '--password'):
password = arg
if opt in ('-d', '--debug'):
debug = True
if not cluster:
usage("please provide a CLUSTER, or use -h for more help.")
server, port = util.hostport(cluster)
if debug:
print "INFO: running command: %s" % cmd
c = commands[cmd]()
try:
c.runCmd(cmd, server, port, user, password, opts)
except TimeoutException, err:
print "TIMED OUT: command: %s: %s:%d, %s" % (cmd, server, port, err)
sys.exit(1)
except KeyboardInterrupt:
print "INTERRUPTED: command: %s: %s:%d" % (cmd, server, port)
sys.exit(1)
except Exception, err:
print "ERROR: command: %s: %s:%d, %s" % (cmd, server, port, err)
sys.exit(1)
if __name__ == '__main__':
main()