Skip to content
This repository was archived by the owner on Dec 10, 2018. It is now read-only.

Commit a080b64

Browse files
author
Kristina Chodorow
committed
add status cmd
1 parent a200f63 commit a080b64

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

handlers.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class MongoHandler:
2828
_cursor_id = 0
2929

3030
def __init__(self, mongos):
31+
self.connections = {}
32+
3133
for host in mongos:
3234
args = MongoFakeFieldStorage({"server" : host})
3335

@@ -42,9 +44,8 @@ def _get_connection(self, name = None, host = None, port = None):
4244
if name == None:
4345
name = "default"
4446

45-
connection = getattr(self, name, None)
46-
if connection != None or host == None:
47-
return connection
47+
if name in self.connections:
48+
return self.connections[name]
4849

4950
if port == None:
5051
port = 27107
@@ -54,7 +55,7 @@ def _get_connection(self, name = None, host = None, port = None):
5455
except ConnectionFailure:
5556
return None
5657

57-
setattr(self, name, connection)
58+
self.connections[name] = connection
5859
return connection
5960

6061

@@ -135,6 +136,13 @@ def _hello(self, args, out, name = None, db = None, collection = None):
135136
'all fine here now, thank you. How are you?"}')
136137
return
137138

139+
def _status(self, args, out, name = None, db = None, collection = None):
140+
result = {"ok" : 1, "connections" : {}}
141+
142+
for name, conn in self.connections.iteritems():
143+
result['connections'][name] = "%s:%d" % (conn.host, conn.port)
144+
145+
out(json.dumps(result))
138146

139147
def _connect(self, args, out, name = None, db = None, collection = None):
140148
"""
@@ -453,7 +461,7 @@ def _batch(self, args, out, name = None, db = None, collection = None):
453461

454462
func = getattr(MongoHandler.mh, cmd, None)
455463
if callable(func):
456-
output = MongoFakeStream();
464+
output = MongoFakeStream()
457465
func(args, output.ostream, name = name, db = db, collection = collection)
458466
if not first:
459467
out(",")

httpd.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class MongoHTTPRequest(BaseHTTPRequestHandler):
6464
"ico" : "image/vnd.microsoft.icon" }
6565

6666
docroot = "."
67-
mongos = None
67+
mongos = []
6868

6969
def _parse_call(self, uri):
7070
"""
@@ -227,7 +227,7 @@ def setup(self):
227227

228228

229229
def usage():
230-
print "python httpd.py [-d docroot/dir] [-s certificate.pem]"
230+
print "python httpd.py [-d docroot/dir] [-s certificate.pem] [-m list,of,mongods]"
231231
print "\t-d|--docroot\tlocation from which to load files"
232232
print "\t-s|--secure\tlocation of .pem file if ssl is desired"
233233
print "\t-m|--mongos\tcomma-separated list of mongo servers to connect to"

0 commit comments

Comments
 (0)