mirror of
https://github.com/ansible/awx.git
synced 2026-03-01 16:58:46 -03:30
Refactor Tower HA Instance logic and models
* Gut the HA middleware * Purge concept of primary and secondary. * UUID is not the primary host identifier, now it's based mostly on the username. Some work probably still left to do to make sure this is legit. Also removed unique constraint from the uuid field. This might become the cluster ident now... or it may just deprecate * No more secondary -> primary redirection * Initial revision of /api/v1/ping * Revise and gut tower-manage register_instance * Rename awx/main/socket.py to awx/main/socket_queue.py to prevent conflict with the "socket" module from python base * Revist/gut the Instance manager... not sure if this manager is really needed anymore
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
# All Rights Reserved.
|
||||
|
||||
import sys
|
||||
import socket
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import models
|
||||
@@ -28,31 +29,12 @@ class InstanceManager(models.Manager):
|
||||
# If we are running unit tests, return a stub record.
|
||||
if len(sys.argv) >= 2 and sys.argv[1] == 'test':
|
||||
return self.model(id=1, primary=True,
|
||||
hostname='localhost',
|
||||
uuid='00000000-0000-0000-0000-000000000000')
|
||||
|
||||
# Return the appropriate record from the database.
|
||||
return self.get(uuid=settings.SYSTEM_UUID)
|
||||
return self.get(hostname=socket.gethostname())
|
||||
|
||||
def my_role(self):
|
||||
"""Return the role of the currently active instance, as a string
|
||||
('primary' or 'secondary').
|
||||
"""
|
||||
# If we are running unit tests, we are primary, because reasons.
|
||||
if len(sys.argv) >= 2 and sys.argv[1] == 'test':
|
||||
return 'primary'
|
||||
|
||||
# Check if this instance is primary; if so, return "primary", otherwise
|
||||
# "secondary".
|
||||
if self.me().primary:
|
||||
return 'primary'
|
||||
return 'secondary'
|
||||
|
||||
def primary(self):
|
||||
"""Return the primary instance."""
|
||||
# If we are running unit tests, return a stub record.
|
||||
if len(sys.argv) >= 2 and sys.argv[1] == 'test':
|
||||
return self.model(id=1, primary=True,
|
||||
uuid='00000000-0000-0000-0000-000000000000')
|
||||
|
||||
# Return the appropriate record from the database.
|
||||
return self.get(primary=True)
|
||||
# NOTE: TODO: Likely to repurpose this once standalone ramparts are a thing
|
||||
return "tower"
|
||||
|
||||
Reference in New Issue
Block a user