From f02099e8b74474b4a21a0f92859f4e515aadd01b Mon Sep 17 00:00:00 2001 From: Jim Ladd Date: Tue, 31 Aug 2021 16:42:44 -0700 Subject: [PATCH] provision_instance should create new uuid if needed .. instead of default to current system's UUID related: #10990 --- awx/main/management/commands/provision_instance.py | 9 ++++----- awx/main/managers.py | 3 ++- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/awx/main/management/commands/provision_instance.py b/awx/main/management/commands/provision_instance.py index 6e145a9baf..3056a09b9c 100644 --- a/awx/main/management/commands/provision_instance.py +++ b/awx/main/management/commands/provision_instance.py @@ -1,7 +1,6 @@ # Copyright (c) 2015 Ansible, Inc. # All Rights Reserved -from django.conf import settings from django.core.management.base import BaseCommand, CommandError from django.db import transaction @@ -19,11 +18,12 @@ class Command(BaseCommand): def add_arguments(self, parser): parser.add_argument('--hostname', dest='hostname', type=str, help='Hostname used during provisioning') parser.add_argument('--node_type', type=str, default="hybrid", choices=["control", "execution", "hybrid"], help='Instance Node type') + parser.add_argument('--uuid', type=str, help='Instance UUID') - def _register_hostname(self, hostname, node_type): + def _register_hostname(self, hostname, node_type, uuid): if not hostname: return - (changed, instance) = Instance.objects.register(uuid=self.uuid, hostname=hostname, node_type=node_type) + (changed, instance) = Instance.objects.register(hostname=hostname, node_type=node_type, uuid=uuid) if changed: print('Successfully registered instance {}'.format(hostname)) else: @@ -34,8 +34,7 @@ class Command(BaseCommand): def handle(self, **options): if not options.get('hostname'): raise CommandError("Specify `--hostname` to use this command.") - self.uuid = settings.SYSTEM_UUID self.changed = False - self._register_hostname(options.get('hostname'), options.get('node_type')) + self._register_hostname(options.get('hostname'), options.get('node_type'), options.get('uuid')) if self.changed: print('(changed: True)') diff --git a/awx/main/managers.py b/awx/main/managers.py index eaee03ed7e..60a1d77ac4 100644 --- a/awx/main/managers.py +++ b/awx/main/managers.py @@ -4,6 +4,7 @@ import sys import logging import os +from uuid import uuid4 from django.db import models from django.conf import settings @@ -115,7 +116,7 @@ class InstanceManager(models.Manager): def register(self, uuid=None, hostname=None, ip_address=None, node_type='hybrid', defaults=None): if not uuid: - uuid = settings.SYSTEM_UUID + uuid = str(uuid4()) if not hostname: hostname = settings.CLUSTER_HOST_ID with advisory_lock('instance_registration_%s' % hostname):