From 05f918e666e86b84c2d89d0a47fe60dee1b123a0 Mon Sep 17 00:00:00 2001 From: Martin Slemr Date: Fri, 10 Feb 2023 10:29:28 +0100 Subject: [PATCH] HostMetric compliance computation --- awx/main/managers.py | 5 +++++ awx/main/models/inventory.py | 5 ++++- awx/main/utils/licensing.py | 4 ++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/awx/main/managers.py b/awx/main/managers.py index 32d6ed7f5b..b674049b0e 100644 --- a/awx/main/managers.py +++ b/awx/main/managers.py @@ -79,6 +79,11 @@ class HostManager(models.Manager): return qs +class HostMetricActiveManager(models.Manager): + def get_queryset(self): + return super().get_queryset().filter(deleted=False) + + def get_ig_ig_mapping(ig_instance_mapping, instance_ig_mapping): # Create IG mapping by union of all groups their instances are members of ig_ig_mapping = {} diff --git a/awx/main/models/inventory.py b/awx/main/models/inventory.py index 4ae7ba2adb..41a85b0071 100644 --- a/awx/main/models/inventory.py +++ b/awx/main/models/inventory.py @@ -32,7 +32,7 @@ from awx.main.fields import ( SmartFilterField, OrderedManyToManyField, ) -from awx.main.managers import HostManager +from awx.main.managers import HostManager, HostMetricActiveManager from awx.main.models.base import BaseModel, CommonModelNameNotUnique, VarsDictProperty, CLOUD_INVENTORY_SOURCES, prevent_search, accepts_json from awx.main.models.events import InventoryUpdateEvent, UnpartitionedInventoryUpdateEvent from awx.main.models.unified_jobs import UnifiedJob, UnifiedJobTemplate @@ -831,6 +831,9 @@ class HostMetric(models.Model): ) used_in_inventories = models.BigIntegerField(null=True, help_text=_('How many inventories contain this host')) + objects = models.Manager() + active_objects = HostMetricActiveManager() + def get_absolute_url(self, request=None): return reverse('api:host_metric_detail', kwargs={'pk': self.pk}, request=request) diff --git a/awx/main/utils/licensing.py b/awx/main/utils/licensing.py index bec953f822..3bc5e174e5 100644 --- a/awx/main/utils/licensing.py +++ b/awx/main/utils/licensing.py @@ -382,8 +382,8 @@ class Licenser(object): current_instances = Host.objects.active_count() license_date = int(attrs.get('license_date', 0) or 0) - automated_instances = HostMetric.objects.count() - first_host = HostMetric.objects.only('first_automation').order_by('first_automation').first() + automated_instances = HostMetric.active_objects.count() + first_host = HostMetric.active_objects.only('first_automation').order_by('first_automation').first() if first_host: automated_since = int(first_host.first_automation.timestamp()) else: