diff --git a/awx/main/management/commands/_base_instance.py b/awx/main/management/commands/_base_instance.py index 8731744e8b..3eaf20f2e7 100644 --- a/awx/main/management/commands/_base_instance.py +++ b/awx/main/management/commands/_base_instance.py @@ -1,7 +1,14 @@ -from django.core.management.base import BaseCommand, CommandError +# Copyright (c) 2014 Ansible, Inc. +# All Rights Reserved. + from optparse import make_option + +from django.core.management.base import BaseCommand, CommandError from django.conf import settings +from awx.main.models import Project + + class OptionEnforceError(Exception): def __init__(self, value): self.value = value @@ -136,4 +143,11 @@ class BaseCommandInstance(BaseCommand): @staticmethod def instance_str(instance): - return BaseCommandInstance.__instance_str(instance, ('uuid', 'hostname', 'role')) \ No newline at end of file + return BaseCommandInstance.__instance_str(instance, ('uuid', 'hostname', 'role')) + + def update_projects(self, instance): + """Update all projects, ensuring the job runs against this instance, + which is the primary instance. + """ + for project in Project.objects.all(): + project.update() diff --git a/awx/main/management/commands/register_instance.py b/awx/main/management/commands/register_instance.py index 179846624e..adb07a9b79 100644 --- a/awx/main/management/commands/register_instance.py +++ b/awx/main/management/commands/register_instance.py @@ -57,5 +57,9 @@ class Command(BaseCommandInstance): instance = Instance(uuid=uuid, primary=self.is_option_primary(), hostname=self.get_option_hostname()) instance.save() + # If this is a primary instance, update projects. + if instance.primary: + self.update_projects(instance) + # Done! print('Successfully registered instance %s.' % instance_str(instance)) diff --git a/awx/main/management/commands/update_instance.py b/awx/main/management/commands/update_instance.py index dd7b114d2f..a0bb3fec51 100644 --- a/awx/main/management/commands/update_instance.py +++ b/awx/main/management/commands/update_instance.py @@ -56,5 +56,8 @@ class Command(BaseCommandInstance): instance.primary = self.is_option_primary() instance.save() + # If this is a primary instance, update projects. + self.update_projects_if_primary(instance) + # Done! - print('Successfully updated instance role %s' % instance_str(instance)) \ No newline at end of file + print('Successfully updated instance role %s' % instance_str(instance))