Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add status cmd

  • Loading branch information...
commit a080b64eb217a5fa56931d74c82927f7b68b088e 1 parent a200f63
Kristina Chodorow authored
Showing with 15 additions and 7 deletions.
  1. +13 −5 handlers.py
  2. +2 −2 httpd.py
View
18 handlers.py
@@ -28,6 +28,8 @@ class MongoHandler:
_cursor_id = 0
def __init__(self, mongos):
+ self.connections = {}
+
for host in mongos:
args = MongoFakeFieldStorage({"server" : host})
@@ -42,9 +44,8 @@ def _get_connection(self, name = None, host = None, port = None):
if name == None:
name = "default"
- connection = getattr(self, name, None)
- if connection != None or host == None:
- return connection
+ if name in self.connections:
+ return self.connections[name]
if port == None:
port = 27107
@@ -54,7 +55,7 @@ def _get_connection(self, name = None, host = None, port = None):
except ConnectionFailure:
return None
- setattr(self, name, connection)
+ self.connections[name] = connection
return connection
@@ -135,6 +136,13 @@ def _hello(self, args, out, name = None, db = None, collection = None):
'all fine here now, thank you. How are you?"}')
return
+ def _status(self, args, out, name = None, db = None, collection = None):
+ result = {"ok" : 1, "connections" : {}}
+
+ for name, conn in self.connections.iteritems():
+ result['connections'][name] = "%s:%d" % (conn.host, conn.port)
+
+ out(json.dumps(result))
def _connect(self, args, out, name = None, db = None, collection = None):
"""
@@ -453,7 +461,7 @@ def _batch(self, args, out, name = None, db = None, collection = None):
func = getattr(MongoHandler.mh, cmd, None)
if callable(func):
- output = MongoFakeStream();
+ output = MongoFakeStream()
func(args, output.ostream, name = name, db = db, collection = collection)
if not first:
out(",")
View
4 httpd.py
@@ -64,7 +64,7 @@ class MongoHTTPRequest(BaseHTTPRequestHandler):
"ico" : "image/vnd.microsoft.icon" }
docroot = "."
- mongos = None
+ mongos = []
def _parse_call(self, uri):
"""
@@ -227,7 +227,7 @@ def setup(self):
def usage():
- print "python httpd.py [-d docroot/dir] [-s certificate.pem]"
+ print "python httpd.py [-d docroot/dir] [-s certificate.pem] [-m list,of,mongods]"
print "\t-d|--docroot\tlocation from which to load files"
print "\t-s|--secure\tlocation of .pem file if ssl is desired"
print "\t-m|--mongos\tcomma-separated list of mongo servers to connect to"
Please sign in to comment.
Something went wrong with that request. Please try again.