mirror of
https://github.com/ansible/awx.git
synced 2026-01-11 01:57:35 -03:30
AC-982 Added configuration options to disable activity stream logging entirely, or disable only when running inventory import.
This commit is contained in:
parent
c52818ecee
commit
ae4743724a
@ -24,7 +24,7 @@ from django.contrib.auth.models import User
|
||||
|
||||
# AWX
|
||||
from awx.main.models import *
|
||||
from awx.main.signals import ignore_inventory_computed_fields
|
||||
from awx.main.signals import ignore_inventory_computed_fields, disable_activity_stream
|
||||
from awx.main.licenses import LicenseReader
|
||||
|
||||
logger = logging.getLogger('awx.main.commands.inventory_import')
|
||||
@ -755,7 +755,11 @@ class Command(NoArgsCommand):
|
||||
|
||||
# Merge/overwrite inventory into database.
|
||||
with ignore_inventory_computed_fields():
|
||||
self.load_into_database()
|
||||
if getattr(settings, 'ACTIVITY_STREAM_ENABLED_FOR_INVENTORY_SYNC', True):
|
||||
self.load_into_database()
|
||||
else:
|
||||
with disable_activity_stream():
|
||||
self.load_into_database()
|
||||
self.inventory.update_computed_fields()
|
||||
self.check_license()
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
|
||||
import logging
|
||||
|
||||
from django.conf import settings
|
||||
from django.db.models.signals import pre_save, post_save, post_delete, m2m_changed
|
||||
|
||||
logger = logging.getLogger('awx.main.registrar')
|
||||
@ -13,6 +14,8 @@ class ActivityStreamRegistrar(object):
|
||||
self.models = []
|
||||
|
||||
def connect(self, model):
|
||||
if not getattr(settings, 'ACTIVITY_STREAM_ENABLED', True):
|
||||
return
|
||||
from awx.main.signals import activity_stream_create, activity_stream_update, activity_stream_delete, activity_stream_associate
|
||||
|
||||
#(receiver, sender=model, dispatch_uid=self._dispatch_uid(signal, model))
|
||||
|
||||
@ -8,6 +8,7 @@ import threading
|
||||
import json
|
||||
|
||||
# Django
|
||||
from django.conf import settings
|
||||
from django.db.models.signals import pre_save, post_save, pre_delete, post_delete, m2m_changed
|
||||
from django.dispatch import receiver
|
||||
|
||||
@ -239,6 +240,27 @@ def update_host_last_job_after_job_deleted(sender, **kwargs):
|
||||
|
||||
# Set via ActivityStreamRegistrar to record activity stream events
|
||||
|
||||
class ActivityStreamEnabled(threading.local):
|
||||
def __init__(self):
|
||||
self.enabled = getattr(settings, 'ACTIVITY_STREAM_ENABLED', True)
|
||||
def __nonzero__(self):
|
||||
return bool(self.enabled)
|
||||
|
||||
activity_stream_enabled = ActivityStreamEnabled()
|
||||
|
||||
@contextlib.contextmanager
|
||||
def disable_activity_stream():
|
||||
'''
|
||||
Context manager to disable capturing activity stream changes.
|
||||
'''
|
||||
try:
|
||||
previous_value = activity_stream_enabled.enabled
|
||||
activity_stream_enabled.enabled = False
|
||||
yield
|
||||
finally:
|
||||
activity_stream_enabled.enabled = previous_value
|
||||
|
||||
|
||||
model_serializer_mapping = {Organization: OrganizationSerializer,
|
||||
Inventory: InventorySerializer,
|
||||
Host: HostSerializer,
|
||||
@ -252,7 +274,7 @@ model_serializer_mapping = {Organization: OrganizationSerializer,
|
||||
Job: JobSerializer}
|
||||
|
||||
def activity_stream_create(sender, instance, created, **kwargs):
|
||||
if created:
|
||||
if created and activity_stream_enabled:
|
||||
# Skip recording any inventory source directly associated with a group.
|
||||
if isinstance(instance, InventorySource) and instance.group:
|
||||
return
|
||||
@ -268,6 +290,8 @@ def activity_stream_create(sender, instance, created, **kwargs):
|
||||
def activity_stream_update(sender, instance, **kwargs):
|
||||
if instance.id is None:
|
||||
return
|
||||
if not activity_stream_enabled:
|
||||
return
|
||||
try:
|
||||
old = sender.objects.get(id=instance.id)
|
||||
except sender.DoesNotExist:
|
||||
@ -291,6 +315,8 @@ def activity_stream_update(sender, instance, **kwargs):
|
||||
getattr(activity_entry, object1).add(instance)
|
||||
|
||||
def activity_stream_delete(sender, instance, **kwargs):
|
||||
if not activity_stream_enabled:
|
||||
return
|
||||
try:
|
||||
old = sender.objects.get(id=instance.id)
|
||||
except sender.DoesNotExist:
|
||||
@ -307,6 +333,8 @@ def activity_stream_delete(sender, instance, **kwargs):
|
||||
activity_entry.save()
|
||||
|
||||
def activity_stream_associate(sender, instance, **kwargs):
|
||||
if not activity_stream_enabled:
|
||||
return
|
||||
if 'pre_add' in kwargs['action'] or 'pre_remove' in kwargs['action']:
|
||||
if kwargs['action'] == 'pre_add':
|
||||
action = 'associate'
|
||||
|
||||
@ -335,6 +335,10 @@ EC2_REGIONS_BLACKLIST = [
|
||||
'cn-north-1',
|
||||
]
|
||||
|
||||
# Defaults for enabling/disabling activity stream.
|
||||
ACTIVITY_STREAM_ENABLED = True
|
||||
ACTIVITY_STREAM_ENABLED_FOR_INVENTORY_SYNC = True
|
||||
|
||||
# Internal API URL for use by inventory scripts and callback plugin.
|
||||
if 'devserver' in INSTALLED_APPS:
|
||||
INTERNAL_API_URL = 'http://127.0.0.1:%s' % DEVSERVER_DEFAULT_PORT
|
||||
|
||||
1
awx/settings/license.json
Normal file
1
awx/settings/license.json
Normal file
@ -0,0 +1 @@
|
||||
{"instance_count": "1000000", "contact_email": "cchurch@ansibleworks.com", "company_name": "TEST", "contact_name": "Chris Church", "license_date": "1422137308", "license_key": "6ccbecf61a5d9ab7606519037b82b21985fcfade8218a50d3476fc83551be64b"}
|
||||
@ -43,6 +43,9 @@ ALLOWED_HOSTS = ['*']
|
||||
AWX_TASK_ENV['HOME'] = '/var/lib/awx'
|
||||
AWX_TASK_ENV['USER'] = 'awx'
|
||||
|
||||
ACTIVITY_STREAM_ENABLED = True
|
||||
ACTIVITY_STREAM_ENABLED_FOR_INVENTORY_SYNC = True
|
||||
|
||||
###############################################################################
|
||||
# EMAIL SETTINGS
|
||||
###############################################################################
|
||||
|
||||
@ -43,6 +43,9 @@ ALLOWED_HOSTS = ['*']
|
||||
AWX_TASK_ENV['HOME'] = '/var/lib/awx'
|
||||
AWX_TASK_ENV['USER'] = 'awx'
|
||||
|
||||
ACTIVITY_STREAM_ENABLED = True
|
||||
ACTIVITY_STREAM_ENABLED_FOR_INVENTORY_SYNC = True
|
||||
|
||||
###############################################################################
|
||||
# EMAIL SETTINGS
|
||||
###############################################################################
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user