forked from membase/membase-cli
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmembase
More file actions
executable file
·115 lines (97 loc) · 2.97 KB
/
membase
File metadata and controls
executable file
·115 lines (97 loc) · 2.97 KB
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
membase.py
This program is the top level source file for the Membase Command Line Tools
"""
import getopt
import sys
import listservers
import buckets
import node
import info
import mbutil
from membase_info import usage
def main():
debug = False
verbose = False
"""Main CLI entry point."""
(cluster, user, password) = ('', '', '')
try:
(opts, _args) = getopt.getopt(sys.argv[2:],
'a:b:c:dse:gdhlmo:OPp:r:Ssu:vV', [
'help',
'cluster=',
'debug',
'storage',
'password=',
'user=',
'mem',
'output=',
'os',
'ports',
'stats',
'license',
'server-add=',
'server-add-username=',
'server-add-password=',
'server-remove=',
'server-remove-username=',
'server-remove-password=',
'verbose',
'version'
])
cmd = sys.argv[1]
except IndexError:
usage()
except getopt.GetoptError, err:
usage(err)
# check if usage specified
for (opt, arg) in opts:
if opt in ('-c', '--cluster'):
cluster = arg
if opt in ('-h', '--help'):
usage()
if opt in ('-p', '--password'):
password = arg
if opt in ('-u', '--user'):
user = arg
if opt in ('-d', '--debug'):
debug = True
if opt in ('-v', '--verbose'):
verbose = True
if not cluster:
usage("You must specify at least two things: command, "
"and cluster (--cluster)")
server, port = mbutil.hostport(cluster)
# these are the commands which map to the classes
# the contain the implementation of that particular
# command
commands = {
'server-list' : listservers.Listservers,
'bucket-list' : buckets.Buckets,
'bucket-details' : buckets.Buckets,
'bucket-stats' : buckets.Buckets,
'bucket-create' : buckets.Buckets,
'bucket-delete' : buckets.Buckets,
'bucket-flush' : buckets.Buckets,
'server-add' : node.Node,
'rebalance' : node.Node,
'rebalance-stop' : node.Node,
'rebalance-status' : node.Node,
'eject-server' : node.Node,
'failover' : node.Node,
'server-info' : info.Info,
}
# make sure the command is defined
if cmd not in commands:
err_message = "command: '%s' not found" % cmd
usage(err_message)
# instantiate
if verbose:
print "running command: %s" % cmd
taskrunner = commands[cmd]()
# call runCmd method
taskrunner.runCmd(cmd, server, port, user, password, opts)
if __name__ == '__main__':
main()