mirror of
https://github.com/ansible/awx.git
synced 2026-01-11 18:09:57 -03:30
Update projects when a new primary is set.
This commit is contained in:
parent
acb061f0be
commit
00a38fd75f
@ -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'))
|
||||
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()
|
||||
|
||||
@ -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))
|
||||
|
||||
@ -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))
|
||||
print('Successfully updated instance role %s' % instance_str(instance))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user