mirror of
https://github.com/ansible/awx.git
synced 2026-02-22 13:36:02 -03:30
Update how we repopulate the /host/:id/smart_inventories data
This commit is contained in:
@@ -58,7 +58,7 @@ import ansiconv
|
|||||||
from social.backends.utils import load_backends
|
from social.backends.utils import load_backends
|
||||||
|
|
||||||
# AWX
|
# AWX
|
||||||
from awx.main.tasks import send_notifications, update_host_smart_inventory_memberships
|
from awx.main.tasks import send_notifications
|
||||||
from awx.main.access import get_user_queryset
|
from awx.main.access import get_user_queryset
|
||||||
from awx.main.ha import is_ha_environment
|
from awx.main.ha import is_ha_environment
|
||||||
from awx.api.authentication import TaskAuthentication, TokenGetAuthentication
|
from awx.api.authentication import TaskAuthentication, TokenGetAuthentication
|
||||||
@@ -2005,14 +2005,6 @@ class HostSmartInventoriesList(SubListAPIView):
|
|||||||
relationship = 'smart_inventories'
|
relationship = 'smart_inventories'
|
||||||
new_in_320 = True
|
new_in_320 = True
|
||||||
|
|
||||||
def list(self, *args, **kwargs):
|
|
||||||
try:
|
|
||||||
if settings.AWX_REBUILD_SMART_MEMBERSHIP:
|
|
||||||
update_host_smart_inventory_memberships.delay()
|
|
||||||
return super(HostSmartInventoriesList, self).list(*args, **kwargs)
|
|
||||||
except Exception as e:
|
|
||||||
return Response(dict(error=_(unicode(e))), status=status.HTTP_400_BAD_REQUEST)
|
|
||||||
|
|
||||||
|
|
||||||
class HostActivityStreamList(ActivityStreamEnforcementMixin, SubListAPIView):
|
class HostActivityStreamList(ActivityStreamEnforcementMixin, SubListAPIView):
|
||||||
|
|
||||||
|
|||||||
@@ -384,6 +384,21 @@ class Inventory(CommonModelNameNotUnique, ResourceMixin):
|
|||||||
self.websocket_emit_status('pending_deletion')
|
self.websocket_emit_status('pending_deletion')
|
||||||
delete_inventory.delay(self.pk)
|
delete_inventory.delay(self.pk)
|
||||||
|
|
||||||
|
def _update_host_smart_inventory_memeberships(self):
|
||||||
|
if self.kind == 'smart' and settings.AWX_REBUILD_SMART_MEMBERSHIP:
|
||||||
|
def on_commit():
|
||||||
|
from awx.main.tasks import update_host_smart_inventory_memberships
|
||||||
|
update_host_smart_inventory_memberships.delay()
|
||||||
|
connection.on_commit(on_commit)
|
||||||
|
|
||||||
|
def save(self, *args, **kwargs):
|
||||||
|
self._update_host_smart_inventory_memeberships()
|
||||||
|
super(Inventory, self).save(*args, **kwargs)
|
||||||
|
|
||||||
|
def delete(self, *args, **kwargs):
|
||||||
|
self._update_host_smart_inventory_memeberships()
|
||||||
|
super(Inventory, self).delete(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class SmartInventoryMembership(BaseModel):
|
class SmartInventoryMembership(BaseModel):
|
||||||
'''
|
'''
|
||||||
@@ -568,6 +583,21 @@ class Host(CommonModelNameNotUnique):
|
|||||||
host_name = self.variables_dict['ansible_host']
|
host_name = self.variables_dict['ansible_host']
|
||||||
return host_name
|
return host_name
|
||||||
|
|
||||||
|
def _update_host_smart_inventory_memeberships(self):
|
||||||
|
if settings.AWX_REBUILD_SMART_MEMBERSHIP:
|
||||||
|
def on_commit():
|
||||||
|
from awx.main.tasks import update_host_smart_inventory_memberships
|
||||||
|
update_host_smart_inventory_memberships.delay()
|
||||||
|
connection.on_commit(on_commit)
|
||||||
|
|
||||||
|
def save(self, *args, **kwargs):
|
||||||
|
self._update_host_smart_inventory_memeberships()
|
||||||
|
super(Host, self).save(*args, **kwargs)
|
||||||
|
|
||||||
|
def delete(self, *args, **kwargs):
|
||||||
|
self._update_host_smart_inventory_memeberships()
|
||||||
|
super(Host, self).delete(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class Group(CommonModelNameNotUnique):
|
class Group(CommonModelNameNotUnique):
|
||||||
'''
|
'''
|
||||||
|
|||||||
@@ -347,7 +347,7 @@ def update_inventory_computed_fields(inventory_id, should_update_hosts=True):
|
|||||||
def update_host_smart_inventory_memberships():
|
def update_host_smart_inventory_memberships():
|
||||||
try:
|
try:
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
smart_inventories = Inventory.objects.filter(kind='smart', host_filter__isnull=False)
|
smart_inventories = Inventory.objects.filter(kind='smart', host_filter__isnull=False, pending_deletion=False)
|
||||||
SmartInventoryMembership.objects.all().delete()
|
SmartInventoryMembership.objects.all().delete()
|
||||||
memberships = []
|
memberships = []
|
||||||
for smart_inventory in smart_inventories:
|
for smart_inventory in smart_inventories:
|
||||||
|
|||||||
Reference in New Issue
Block a user