Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 105 lines (86 sloc) 3.471 kb
#!/usr/bin/env python
import os, sys, getopt, urllib2, urllib, json
from urllib2 import HTTPError
valid_bucket_types = ["membase", "memcached"]
def usage():
print "usage: \n\
-n <number of nodes>\n\
-s <memory size (min 256) default: 256\n\
-t <bucket type> (membase, memcached) default: membase\n\
-r <num replicas> (max 3) default: 1 (Only for membase buckets!)\n\
-i (don't index replicas) default: replica index enabled\n\
-S <start index> default: 0"
class PasswordManager(urllib2.HTTPPasswordMgr):
def __init__(self, username, password):
self.auth = (username, password)
def find_user_password(self, realm, authuri):
return self.auth
def main():
try:
opts, args = getopt.getopt(sys.argv[1:], "n:t:s:r:iS:")
except getopt.GetoptError, err:
print str(err)
usage()
sys.exit()
nodes = 0
buckettype = "membase"
memsize = 256
replicas = 1
replica_index = True
start_index = 0
data_base_path = os.getcwd() + "/data"
for o, a in opts:
if o == "-n":
nodes = a
elif o == "-t":
buckettype = a
elif o == "-s":
memsize = a
elif o == "-r":
replicas = a
elif o == "-i":
replica_index = False
elif o == "-S":
start_index = int(a)
else:
usage()
sys.exit()
if nodes == 0 or buckettype not in valid_bucket_types or \
int(memsize) < 256 or int(replicas) > 3:
usage()
sys.exit()
password_mgr = PasswordManager("Administrator", "asdasd")
handler = urllib2.HTTPBasicAuthHandler(password_mgr)
o = urllib2.build_opener(handler)
print "Connecting {0} nodes, bucket type {1}, mem size {2} " \
"with {3} replica copies, start index {4}, " \
"password asdasd\n".format(nodes, buckettype,
memsize, replicas, start_index)
base_port = 9000 + start_index
o.open("http://127.0.0.1:{0}/pools/default".format(base_port),
"memoryQuota=" + str(memsize)).read()
o.open("http://127.0.0.1:{0}/controller/setupDefaultBucket".format(base_port),
"bucketType=" + buckettype +
"&ramQuotaMB=" + str(memsize) +
"&replicaNumber=" + str(replicas) +
"&replicaIndex=" + bool_request_value(replica_index)).read()
o.open("http://127.0.0.1:{0}/settings/web".format(base_port),
"port=SAME&username=Administrator&password=asdasd").read()
for i in range(1, int(nodes)):
port = base_port + i
print "Connecting node {0}".format(i)
o.open("http://127.0.0.1:{0}/node/controller/doJoinCluster".format(port),
"user=Administrator&password=asdasd&" \
"clusterMemberHostIp=127.0.0.1" \
"&clusterMemberPort={0}".format(base_port)).read()
print "Getting node list"
info = json.loads(o.open("http://127.0.0.1:{0}/nodeStatuses".format(base_port)).read())
print "Servers added, triggering rebalance."
o.open("http://127.0.0.1:{0}/controller/rebalance".format(base_port),
urllib.urlencode(
{'knownNodes': ",".join([info[k]['otpNode'] for k in info]),
'ejectedNodes': ''})).read()
def bool_request_value(Value):
return "1" if Value else "0"
if __name__ == '__main__':
main()
Jump to Line
Something went wrong with that request. Please try again.