mirror of
https://github.com/ZwareBear/awx.git
synced 2026-03-20 07:43:35 -05:00
AC-982 Added configuration options to disable activity stream logging entirely, or disable only when running inventory import.
This commit is contained in:
@@ -24,7 +24,7 @@ from django.contrib.auth.models import User
|
|||||||
|
|
||||||
# AWX
|
# AWX
|
||||||
from awx.main.models import *
|
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
|
from awx.main.licenses import LicenseReader
|
||||||
|
|
||||||
logger = logging.getLogger('awx.main.commands.inventory_import')
|
logger = logging.getLogger('awx.main.commands.inventory_import')
|
||||||
@@ -755,7 +755,11 @@ class Command(NoArgsCommand):
|
|||||||
|
|
||||||
# Merge/overwrite inventory into database.
|
# Merge/overwrite inventory into database.
|
||||||
with ignore_inventory_computed_fields():
|
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.inventory.update_computed_fields()
|
||||||
self.check_license()
|
self.check_license()
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
from django.db.models.signals import pre_save, post_save, post_delete, m2m_changed
|
from django.db.models.signals import pre_save, post_save, post_delete, m2m_changed
|
||||||
|
|
||||||
logger = logging.getLogger('awx.main.registrar')
|
logger = logging.getLogger('awx.main.registrar')
|
||||||
@@ -13,6 +14,8 @@ class ActivityStreamRegistrar(object):
|
|||||||
self.models = []
|
self.models = []
|
||||||
|
|
||||||
def connect(self, model):
|
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
|
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))
|
#(receiver, sender=model, dispatch_uid=self._dispatch_uid(signal, model))
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import threading
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
# Django
|
# Django
|
||||||
|
from django.conf import settings
|
||||||
from django.db.models.signals import pre_save, post_save, pre_delete, post_delete, m2m_changed
|
from django.db.models.signals import pre_save, post_save, pre_delete, post_delete, m2m_changed
|
||||||
from django.dispatch import receiver
|
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
|
# 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,
|
model_serializer_mapping = {Organization: OrganizationSerializer,
|
||||||
Inventory: InventorySerializer,
|
Inventory: InventorySerializer,
|
||||||
Host: HostSerializer,
|
Host: HostSerializer,
|
||||||
@@ -252,7 +274,7 @@ model_serializer_mapping = {Organization: OrganizationSerializer,
|
|||||||
Job: JobSerializer}
|
Job: JobSerializer}
|
||||||
|
|
||||||
def activity_stream_create(sender, instance, created, **kwargs):
|
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.
|
# Skip recording any inventory source directly associated with a group.
|
||||||
if isinstance(instance, InventorySource) and instance.group:
|
if isinstance(instance, InventorySource) and instance.group:
|
||||||
return
|
return
|
||||||
@@ -268,6 +290,8 @@ def activity_stream_create(sender, instance, created, **kwargs):
|
|||||||
def activity_stream_update(sender, instance, **kwargs):
|
def activity_stream_update(sender, instance, **kwargs):
|
||||||
if instance.id is None:
|
if instance.id is None:
|
||||||
return
|
return
|
||||||
|
if not activity_stream_enabled:
|
||||||
|
return
|
||||||
try:
|
try:
|
||||||
old = sender.objects.get(id=instance.id)
|
old = sender.objects.get(id=instance.id)
|
||||||
except sender.DoesNotExist:
|
except sender.DoesNotExist:
|
||||||
@@ -291,6 +315,8 @@ def activity_stream_update(sender, instance, **kwargs):
|
|||||||
getattr(activity_entry, object1).add(instance)
|
getattr(activity_entry, object1).add(instance)
|
||||||
|
|
||||||
def activity_stream_delete(sender, instance, **kwargs):
|
def activity_stream_delete(sender, instance, **kwargs):
|
||||||
|
if not activity_stream_enabled:
|
||||||
|
return
|
||||||
try:
|
try:
|
||||||
old = sender.objects.get(id=instance.id)
|
old = sender.objects.get(id=instance.id)
|
||||||
except sender.DoesNotExist:
|
except sender.DoesNotExist:
|
||||||
@@ -307,6 +333,8 @@ def activity_stream_delete(sender, instance, **kwargs):
|
|||||||
activity_entry.save()
|
activity_entry.save()
|
||||||
|
|
||||||
def activity_stream_associate(sender, instance, **kwargs):
|
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 'pre_add' in kwargs['action'] or 'pre_remove' in kwargs['action']:
|
||||||
if kwargs['action'] == 'pre_add':
|
if kwargs['action'] == 'pre_add':
|
||||||
action = 'associate'
|
action = 'associate'
|
||||||
|
|||||||
@@ -335,6 +335,10 @@ EC2_REGIONS_BLACKLIST = [
|
|||||||
'cn-north-1',
|
'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.
|
# Internal API URL for use by inventory scripts and callback plugin.
|
||||||
if 'devserver' in INSTALLED_APPS:
|
if 'devserver' in INSTALLED_APPS:
|
||||||
INTERNAL_API_URL = 'http://127.0.0.1:%s' % DEVSERVER_DEFAULT_PORT
|
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['HOME'] = '/var/lib/awx'
|
||||||
AWX_TASK_ENV['USER'] = 'awx'
|
AWX_TASK_ENV['USER'] = 'awx'
|
||||||
|
|
||||||
|
ACTIVITY_STREAM_ENABLED = True
|
||||||
|
ACTIVITY_STREAM_ENABLED_FOR_INVENTORY_SYNC = True
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# EMAIL SETTINGS
|
# EMAIL SETTINGS
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|||||||
@@ -43,6 +43,9 @@ ALLOWED_HOSTS = ['*']
|
|||||||
AWX_TASK_ENV['HOME'] = '/var/lib/awx'
|
AWX_TASK_ENV['HOME'] = '/var/lib/awx'
|
||||||
AWX_TASK_ENV['USER'] = 'awx'
|
AWX_TASK_ENV['USER'] = 'awx'
|
||||||
|
|
||||||
|
ACTIVITY_STREAM_ENABLED = True
|
||||||
|
ACTIVITY_STREAM_ENABLED_FOR_INVENTORY_SYNC = True
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# EMAIL SETTINGS
|
# EMAIL SETTINGS
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|||||||
Reference in New Issue
Block a user