def on_change():
'''
called when there is a change in the list of IPs and ports for this backend
'''
hostname = socket.gethostname()
ip = get_ip()
local_mongo = MongoClient(ip, connect=False)
try:
repl_status = local_mongo.admin.command('replSetGetStatus')
is_mongo_primary = repl_status['myState'] == 1
# ref https://docs.mongodb.com/manual/reference/replica-states/
except Exception as e:
log.error(e, 'unable to get primary status')
return False
if is_mongo_primary:
return mongo_update_replset_config(local_mongo, ip)
else:
return True
# ---------------------------------------------------------
评论列表
文章目录