Skip to content

Commit 017fe92

Browse files
author
Robert Gartman
committed
Automate _cluster_setup
1 parent c73cbfa commit 017fe92

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

mem3_helper.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ def finish_cluster(names):
106106
# The node in <name> is primed
107107
# http://docs.couchdb.org/en/stable/cluster/setup.html
108108

109+
headers = {'Content-type': 'application/json'}
110+
109111
# action: enable_cluster
110112
payload = {}
111113
payload['action'] = 'enable_cluster'
@@ -117,7 +119,9 @@ def finish_cluster(names):
117119
payload['remote_node'] = name
118120
payload['remote_current_user'] = creds[0]
119121
payload['remote_current_password'] = creds[1]
120-
setup_resp=requests.post("http://127.0.0.1:5984/_cluster_setup", json.dumps(payload), auth=creds)
122+
setup_resp=requests.post("http://127.0.0.1:5984/_cluster_setup", json.dumps(payload), auth=creds, headers=headers)
123+
payload['password'] = "**masked**"
124+
payload['remote_current_password'] = "**masked**"
121125
print ("POST to http://127.0.0.1:5984/_cluster_setup returned",setup_resp.status_code,"payload=",json.dumps(payload))
122126

123127
# action: add_node
@@ -127,7 +131,8 @@ def finish_cluster(names):
127131
payload['password'] = creds[1]
128132
payload['port'] = 5984
129133
payload['host'] = name
130-
setup_resp=requests.post("http://127.0.0.1:5984/_cluster_setup", json.dumps(payload), auth=creds)
134+
setup_resp=requests.post("http://127.0.0.1:5984/_cluster_setup", json.dumps(payload), auth=creds, headers=headers)
135+
payload['password'] = "**masked**"
131136
print ("POST to http://127.0.0.1:5984/_cluster_setup returned",setup_resp.status_code,"payload=",json.dumps(payload))
132137

133138
print('CouchDB cluster peer {} added to "setup coordination node"'.format(name))
@@ -145,14 +150,17 @@ def finish_cluster(names):
145150
def enable_cluster(nr_of_peers):
146151
creds = (os.getenv("COUCHDB_USER"), os.getenv("COUCHDB_PASSWORD"))
147152
if creds[0] and creds[1]:
153+
headers = {'Content-type': 'application/json'}
154+
148155
# http://docs.couchdb.org/en/stable/cluster/setup.html
149156
payload = {}
150157
payload['action'] = 'enable_cluster'
151158
payload['bind_address'] = '0.0.0.0'
152159
payload['username'] = creds[0]
153160
payload['password'] = creds[1]
154-
payload['node_count'] = nr_of_peers
155-
setup_resp=requests.post("http://127.0.0.1:5984/_cluster_setup", json.dumps(payload), auth=creds)
161+
payload['node_count'] = '{0}'.format(nr_of_peers)
162+
setup_resp=requests.post("http://127.0.0.1:5984/_cluster_setup", json.dumps(payload), auth=creds, headers=headers)
163+
payload['password'] = "**masked**"
156164
print ("POST to http://127.0.0.1:5984/_cluster_setup returned",setup_resp.status_code,"payload=",json.dumps(payload))
157165

158166
def sleep_forever():

0 commit comments

Comments
 (0)