Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added SSL options to replication version of simple-setup

  • Loading branch information...
commit c54fb3598749b02097c777d4d8232d93dca6bfbe 1 parent f780c91
Adam Comerford authored April 06, 2012

Showing 1 changed file with 19 additions and 3 deletions. Show diff stats Hide diff stats

  1. 22  replication/simple-setup.py
22  replication/simple-setup.py
@@ -40,6 +40,12 @@
40 40
                   help="First port number to use (%default)", default=27017)
41 41
 parser.add_option("--name",
42 42
                   help="Replica set name (%default)", default="foo")
  43
+parser.add_option("--ssl",
  44
+				  help="SSL enabled (%default)", default="False")
  45
+parser.add_option("--ssl_path",
  46
+				  help="Path to SSL PEM cert/key (%default)", default="/data/db/mongocert.pem")
  47
+parser.add_option("--ssl_pass",
  48
+				  help="Password for SSL PEM cert/key (%default)", default="mongo")
43 49
 (options, args) = parser.parse_args()
44 50
 if args:
45 51
     print("error: no positional arguments accepted")
@@ -63,6 +69,14 @@
63 69
     if not os.path.exists( mongod ):
64 70
         raise Exception( "can't find mongod" )
65 71
 
  72
+# check whether SSL is enabled, if it is then set the SSL variable to True
  73
+# simplifies things later on
  74
+if options.ssl == "True":
  75
+    SSL = True
  76
+else:
  77
+    SSL = False
  78
+
  79
+
66 80
 # Just get a different color code to use based on n.
67 81
 # See http://pueblo.sourceforge.net/doc/manual/ansi_color_codes.html
68 82
 def get_color(n):
@@ -143,10 +157,12 @@ def printer():
143 157
     seed = options.name + "/" + ",".join(nodes)
144 158
 
145 159
     command = [mongod, "--port", port, "--dbpath", path, "--replSet", seed, "--rest"]
  160
+    if SSL:
  161
+        command += ["--sslOnNormalPorts", "--sslPEMKeyFile", str(options.ssl_path), "--sslPEMKeyPassword", str(options.ssl_pass)]
146 162
     if i < options.arbiters:
147 163
         command += ["--oplogSize", "1"]
148 164
         prefix = "A" + str(i)
149  
-    else:
  165
+    else: 
150 166
         command += ["--oplogSize", str(options.oplog_size)]
151 167
         prefix = "R" + str(i - options.arbiters)
152 168
     node = Popen(command, stdout=PIPE, stderr=STDOUT)
@@ -167,10 +183,10 @@ def printer():
167 183
 
168 184
 sleep(10)
169 185
 # Last node won't be an arbiter, so use that for initiate
170  
-Connection(nodes[-1], slave_okay=True).admin.command("replSetInitiate", config)
  186
+Connection(nodes[-1], slave_okay=True, ssl=SSL).admin.command("replSetInitiate", config)
171 187
 while (True):
172 188
     try:
173  
-        print Connection(nodes).admin.command("replSetGetStatus")
  189
+        print Connection(nodes, ssl=SSL).admin.command("replSetGetStatus")
174 190
         break
175 191
     except AutoReconnect:
176 192
         sleep(1)

0 notes on commit c54fb35

Please sign in to comment.
Something went wrong with that request. Please try again.