mirror of
https://github.com/ansible/awx.git
synced 2026-02-21 13:10:11 -03:30
Update projects when a new primary is set.
This commit is contained in:
@@ -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 optparse import make_option
|
||||||
|
|
||||||
|
from django.core.management.base import BaseCommand, CommandError
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
|
from awx.main.models import Project
|
||||||
|
|
||||||
|
|
||||||
class OptionEnforceError(Exception):
|
class OptionEnforceError(Exception):
|
||||||
def __init__(self, value):
|
def __init__(self, value):
|
||||||
self.value = value
|
self.value = value
|
||||||
@@ -136,4 +143,11 @@ class BaseCommandInstance(BaseCommand):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def instance_str(instance):
|
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 = Instance(uuid=uuid, primary=self.is_option_primary(), hostname=self.get_option_hostname())
|
||||||
instance.save()
|
instance.save()
|
||||||
|
|
||||||
|
# If this is a primary instance, update projects.
|
||||||
|
if instance.primary:
|
||||||
|
self.update_projects(instance)
|
||||||
|
|
||||||
# Done!
|
# Done!
|
||||||
print('Successfully registered instance %s.' % instance_str(instance))
|
print('Successfully registered instance %s.' % instance_str(instance))
|
||||||
|
|||||||
@@ -56,5 +56,8 @@ class Command(BaseCommandInstance):
|
|||||||
instance.primary = self.is_option_primary()
|
instance.primary = self.is_option_primary()
|
||||||
instance.save()
|
instance.save()
|
||||||
|
|
||||||
|
# If this is a primary instance, update projects.
|
||||||
|
self.update_projects_if_primary(instance)
|
||||||
|
|
||||||
# Done!
|
# Done!
|
||||||
print('Successfully updated instance role %s' % instance_str(instance))
|
print('Successfully updated instance role %s' % instance_str(instance))
|
||||||
|
|||||||
Reference in New Issue
Block a user