Created
June 17, 2020 05:12
-
-
Save velotiotech/77a9a9414a1c9b7900649dd2d05fc76b to your computer and use it in GitHub Desktop.
Velotio - HashiCorp Consul Part 2 - Django view to show the current MongoDB connection and setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.shortcuts import render | |
from pymongo import MongoClient | |
def home(request): | |
client = MongoClient("mongo-primary.service.consul") | |
replica_set = client.admin.command('ismaster') | |
return render(request, 'home.html', { | |
'mongo_hosts': replica_set['hosts'], | |
'mongo_primary_host': replica_set['primary'], | |
'mongo_connected_host': replica_set['me'], | |
'mongo_is_primary': replica_set['ismaster'], | |
'mongo_is_secondary': replica_set['secondary'], | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment