diff --git a/awx/api/management/commands/uses_mongo.py b/awx/api/management/commands/uses_mongo.py index ab61e7cae4..267c389d62 100644 --- a/awx/api/management/commands/uses_mongo.py +++ b/awx/api/management/commands/uses_mongo.py @@ -5,7 +5,7 @@ import sys from optparse import make_option from django.core.management.base import BaseCommand -from awx.main.models import Instance +from awx.main.ha import is_ha_environment from awx.main.task_engine import TaskSerializer @@ -45,7 +45,7 @@ class Command(BaseCommand): # rules here will grow more complicated over time. uses_mongo = system_tracking # noqa - if Instance.objects.count() > 1 and kwargs['local'] and uses_mongo: + if is_ha_environment() and kwargs['local'] and uses_mongo: print("HA Configuration detected. Database should be remote") uses_mongo = False diff --git a/awx/main/ha.py b/awx/main/ha.py index 9bc14d7434..5341ea32bb 100644 --- a/awx/main/ha.py +++ b/awx/main/ha.py @@ -1,13 +1,6 @@ # Copyright (c) 2015 Ansible, Inc. # All Rights Reserved. -# Python -import os -from IPy import IP - -# Django -from django.conf import settings - # AWX from awx.main.models import Instance @@ -18,27 +11,4 @@ def is_ha_environment(): # If there are two or more instances, then we are in an HA environment. if Instance.objects.count() > 1: return True - - # If the database is not local, then we are in an HA environment. - host = settings.DATABASES['default'].get('HOST', 'localhost') - - # Is host special case 'localhost' ? - if host is 'localhost': - return False - - # Check if host is an absolute file (i.e. named socket) - if os.path.isabs(host): - return False - - # Is host a LOCAL or REMOTE ip address ? - try: - if IP(host).iptype() is 'LOOPBACK': - return False - else: - return True - except ValueError: - pass - - # host may be a domain name like postgres.mycompany.com - # Assume HA Environment - return True + return False