HostMetric compliance computation

This commit is contained in:
Martin Slemr
2023-02-10 10:29:28 +01:00
committed by John Westcott IV
parent b18ad77035
commit 05f918e666
3 changed files with 11 additions and 3 deletions

View File

@@ -79,6 +79,11 @@ class HostManager(models.Manager):
return qs 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): def get_ig_ig_mapping(ig_instance_mapping, instance_ig_mapping):
# Create IG mapping by union of all groups their instances are members of # Create IG mapping by union of all groups their instances are members of
ig_ig_mapping = {} ig_ig_mapping = {}

View File

@@ -32,7 +32,7 @@ from awx.main.fields import (
SmartFilterField, SmartFilterField,
OrderedManyToManyField, 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.base import BaseModel, CommonModelNameNotUnique, VarsDictProperty, CLOUD_INVENTORY_SOURCES, prevent_search, accepts_json
from awx.main.models.events import InventoryUpdateEvent, UnpartitionedInventoryUpdateEvent from awx.main.models.events import InventoryUpdateEvent, UnpartitionedInventoryUpdateEvent
from awx.main.models.unified_jobs import UnifiedJob, UnifiedJobTemplate 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')) 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): def get_absolute_url(self, request=None):
return reverse('api:host_metric_detail', kwargs={'pk': self.pk}, request=request) return reverse('api:host_metric_detail', kwargs={'pk': self.pk}, request=request)

View File

@@ -382,8 +382,8 @@ class Licenser(object):
current_instances = Host.objects.active_count() current_instances = Host.objects.active_count()
license_date = int(attrs.get('license_date', 0) or 0) license_date = int(attrs.get('license_date', 0) or 0)
automated_instances = HostMetric.objects.count() automated_instances = HostMetric.active_objects.count()
first_host = HostMetric.objects.only('first_automation').order_by('first_automation').first() first_host = HostMetric.active_objects.only('first_automation').order_by('first_automation').first()
if first_host: if first_host:
automated_since = int(first_host.first_automation.timestamp()) automated_since = int(first_host.first_automation.timestamp())
else: else: