mirror of
https://github.com/ansible/awx.git
synced 2026-01-19 21:51:26 -03:30
Adjust usage of is_ha_environment()
Limit it to just instance count and make sure we use it for the mongo check
This commit is contained in:
parent
d5e948890c
commit
5605ec9754
@ -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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user