Skip to content

Commit 031309e

Browse files
author
Tim Vaillancourt
committed
default tweaks, method rename, passing force boolean properly to refresh rs_status
1 parent 5be6468 commit 031309e

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

MongoBackup/Replset.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
class Replset:
10-
def __init__(self, db, user, password, authdb, max_lag_secs):
10+
def __init__(self, db, user=None, password=None, authdb='admin', max_lag_secs=5):
1111
self.db = db
1212
self.user = user
1313
self.password = password
@@ -49,8 +49,8 @@ def get_rs_config(self):
4949
except Exception, e:
5050
raise Exception, "Error getting replica set config! Error: %s" % e, None
5151

52-
def find_primary(self):
53-
rs_status = self.get_rs_status()
52+
def find_primary(self, force=False):
53+
rs_status = self.get_rs_status(force)
5454
rs_name = rs_status['set']
5555
for member in rs_status['members']:
5656
if member['stateStr'] == 'PRIMARY' and member['health'] > 0:
@@ -130,14 +130,13 @@ def find_secondary(self):
130130
return self.secondary
131131

132132
def primary_optime(self):
133-
rs_status = self.get_rs_status()
134-
rs_primary = self.find_primary()
133+
rs_primary = self.find_primary(True)
135134
if 'optime' in rs_primary:
136135
return rs_primary['optime']
137136

138137

139138
class ReplsetSharded:
140-
def __init__(self, sharding, db, user, password, authdb, max_lag_secs):
139+
def __init__(self, sharding, db, user=None, password=None, authdb='admin', max_lag_secs=5):
141140
self.sharding = sharding
142141
self.db = db
143142
self.user = user
@@ -195,7 +194,7 @@ def find_secondaries(self):
195194
shard_secondaries[rs_name] = replset.find_secondary()
196195
return shard_secondaries
197196

198-
def get_primary_optimes(self):
197+
def primary_optimes(self):
199198
primary_optimes = {}
200199
for rs_name in self.get_replsets():
201200
replset = self.replsets[rs_name]

0 commit comments

Comments
 (0)