Merge pull request #4268 from fosterseth/fix-ip_conflict_cluster

Unset IP address of old instance if conflicting with new instance IP
This commit is contained in:
Ryan Petrello 2020-04-28 10:59:27 -04:00 committed by GitHub
commit 29abe35799
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -121,6 +121,17 @@ class InstanceManager(models.Manager):
if not hostname:
hostname = settings.CLUSTER_HOST_ID
with advisory_lock('instance_registration_%s' % hostname):
if settings.AWX_AUTO_DEPROVISION_INSTANCES:
# detect any instances with the same IP address.
# if one exists, set it to None
inst_conflicting_ip = self.filter(ip_address=ip_address).exclude(hostname=hostname)
if inst_conflicting_ip.exists():
for other_inst in inst_conflicting_ip:
other_hostname = other_inst.hostname
other_inst.ip_address = None
other_inst.save(update_fields=['ip_address'])
logger.warning("IP address {0} conflict detected, ip address unset for host {1}.".format(ip_address, other_hostname))
instance = self.filter(hostname=hostname)
if instance.exists():
instance = instance.get()