Created
March 30, 2019 18:46
-
-
Save pranavcode/4301aff00d52c13a49fa8ba6dc893d2a 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 hidden or 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