@@ -58,7 +58,7 @@ def enable_cluster(nr_of_peers):
58
58
creds = (os .getenv ("COUCHDB_USER" ), os .getenv ("COUCHDB_PASSWORD" ))
59
59
if creds [0 ] and creds [1 ]:
60
60
headers = {'Content-type' : 'application/json' }
61
- print ("== Enabling cluster mode ===" )
61
+ print ("=== Enabling cluster mode ===" )
62
62
# http://docs.couchdb.org/en/stable/cluster/setup.html
63
63
payload = {}
64
64
payload ['action' ] = 'enable_cluster'
@@ -68,8 +68,8 @@ def enable_cluster(nr_of_peers):
68
68
payload ['node_count' ] = nr_of_peers
69
69
setup_resp = requests .post ("http://127.0.0.1:5984/_cluster_setup" , json .dumps (payload ), auth = creds , headers = headers )
70
70
payload ['password' ] = "**masked**"
71
- print ("\t Request: http://127.0.0.1:5984/_cluster_setup , payload:" ,json .dumps (payload ))
72
- print ("\t Response:" , setup_resp )
71
+ print ("\t Request: POST http://127.0.0.1:5984/_cluster_setup , payload:" ,json .dumps (payload ))
72
+ print ("\t Response:" , setup_resp . status_code , setup_resp . json () )
73
73
74
74
# Compare (json) objects - order does not matter. Credits to:
75
75
# https://stackoverflow.com/a/25851972
@@ -91,7 +91,6 @@ def finish_cluster(names):
91
91
# https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#pod-identity
92
92
# we can make sure that this code runs
93
93
# on the "first" pod only with this hack:
94
- print ('HOSTNAME={0}' .format (os .getenv ("HOSTNAME" )))
95
94
if (os .getenv ("HOSTNAME" ).endswith ("-0" )):
96
95
creds = (os .getenv ("COUCHDB_USER" ), os .getenv ("COUCHDB_PASSWORD" ))
97
96
# Make sure that ALL CouchDB cluster peers have been
@@ -124,7 +123,7 @@ def finish_cluster(names):
124
123
print ("Node {0} has all node members in place!" .format (name ))
125
124
# The node in <name> is primed
126
125
# http://docs.couchdb.org/en/stable/cluster/setup.html
127
- print ("== Adding nodes to CouchDB cluster via the “setup coordination node” ===" )
126
+ print ("=== Adding nodes to CouchDB cluster via the “setup coordination node” ===" )
128
127
129
128
headers = {'Content-type' : 'application/json' }
130
129
@@ -142,8 +141,8 @@ def finish_cluster(names):
142
141
setup_resp = requests .post ("http://127.0.0.1:5984/_cluster_setup" , json .dumps (payload ), auth = creds , headers = headers )
143
142
payload ['password' ] = "**masked**"
144
143
payload ['remote_current_password' ] = "**masked**"
145
- print ("\t Request: http://127.0.0.1:5984/_cluster_setup , payload:" ,json .dumps (payload ))
146
- print ("\t Response:" , setup_resp )
144
+ print ("\t Request: POST http://127.0.0.1:5984/_cluster_setup , payload:" ,json .dumps (payload ))
145
+ print ("\t Response:" , setup_resp . status_code , setup_resp . json () )
147
146
148
147
# action: add_node
149
148
payload = {}
@@ -154,15 +153,33 @@ def finish_cluster(names):
154
153
payload ['host' ] = name
155
154
setup_resp = requests .post ("http://127.0.0.1:5984/_cluster_setup" , json .dumps (payload ), auth = creds , headers = headers )
156
155
payload ['password' ] = "**masked**"
157
- print ("\t Request: http://127.0.0.1:5984/_cluster_setup , payload:" ,json .dumps (payload ))
158
- print ("\t Response:" , setup_resp )
156
+ print ("\t Request: POST http://127.0.0.1:5984/_cluster_setup , payload:" ,json .dumps (payload ))
157
+ print ("\t Response:" , setup_resp . status_code , setup_resp . json () )
159
158
160
159
print ('CouchDB cluster peer {} added to "setup coordination node"' .format (name ))
161
160
# At this point ALL peers have _nodes populated. Finish the cluster setup!
162
- if creds [0 ] and creds [1 ]:
163
- setup_resp = requests .post ("http://127.0.0.1:5984/_cluster_setup" , json = {"action" : "finish_cluster" }, auth = creds )
161
+ setup_resp = requests .post ("http://127.0.0.1:5984/_cluster_setup" , json = {"action" : "finish_cluster" }, auth = creds )
164
162
if (setup_resp .status_code == 201 ):
163
+ print ("== CouchDB cluster setup done! ===" )
164
+ setup_resp = requests .post ("http://127.0.0.1:5984/_cluster_setup" )
165
165
print ("CouchDB cluster setup done. Time to relax!" )
166
+ print ("\t Request: GET http://127.0.0.1:5984/_cluster_setup" )
167
+
168
+ print ("== Creating default databases ===" )
169
+
170
+ setup_resp = requests .put ("http://127.0.0.1:5984/_users" , auth = creds , headers = headers )
171
+ print ("\t Request: PUT http://127.0.0.1:5984/_users" )
172
+ print ("\t Response:" , setup_resp .status_code , setup_resp .json ())
173
+
174
+ setup_resp = requests .put ("http://127.0.0.1:5984/_replicator" , auth = creds , headers = headers )
175
+ print ("\t Request: PUT http://127.0.0.1:5984/_replicator" )
176
+ print ("\t Response:" , setup_resp .status_code , setup_resp .json ())
177
+
178
+ setup_resp = requests .put ("http://127.0.0.1:5984/_global_changes" , auth = creds , headers = headers )
179
+ print ("\t Request: PUT http://127.0.0.1:5984/_global_changes" )
180
+ print ("\t Response:" , setup_resp .status_code , setup_resp .json ())
181
+
182
+ print ("\t Response:" , setup_resp .status_code , setup_resp .json ())
166
183
else :
167
184
print ('Ouch! Failed the final step: http://127.0.0.1:5984/_cluster_setup returned {0}' .format (setup_resp .status_code ))
168
185
else :
0 commit comments