mirror of
https://github.com/ansible/awx.git
synced 2026-01-14 03:10:42 -03:30
Add common code for determining active (licensed) hosts with unique names, update licensing code and inventory import to use it. Implements https://trello.com/c/2Q9Mosks
This commit is contained in:
parent
6b91f46082
commit
fcf7398ec6
@ -1125,7 +1125,7 @@ class Command(NoArgsCommand):
|
||||
available_instances = license_info.get('available_instances', 0)
|
||||
free_instances = license_info.get('free_instances', 0)
|
||||
time_remaining = license_info.get('time_remaining', 0)
|
||||
new_count = Host.objects.filter(active=True).count()
|
||||
new_count = Host.objects.active_count()
|
||||
if time_remaining <= 0 and not license_info.get('demo', False):
|
||||
self.logger.error('License has expired')
|
||||
raise CommandError("License has expired!")
|
||||
|
||||
@ -8,6 +8,14 @@ from django.db import models
|
||||
from django.utils.functional import cached_property
|
||||
|
||||
|
||||
class HostManager(models.Manager):
|
||||
"""Custom manager class for Hosts model."""
|
||||
|
||||
def active_count(self):
|
||||
"""Return count of active, unique hosts for licensing."""
|
||||
return self.filter(active=True, inventory__active=True).distinct('name').count()
|
||||
|
||||
|
||||
class InstanceManager(models.Manager):
|
||||
"""A custom manager class for the Instance model.
|
||||
|
||||
|
||||
@ -31,6 +31,7 @@ from django.core.cache import cache
|
||||
# AWX
|
||||
from awx.main.constants import CLOUD_PROVIDERS
|
||||
from awx.main.fields import AutoOneToOneField
|
||||
from awx.main.managers import HostManager
|
||||
from awx.main.models.base import *
|
||||
from awx.main.models.jobs import Job
|
||||
from awx.main.models.unified_jobs import *
|
||||
@ -387,6 +388,8 @@ class Host(CommonModelNameNotUnique):
|
||||
help_text=_('Inventory source(s) that created or modified this host.'),
|
||||
)
|
||||
|
||||
objects = HostManager()
|
||||
|
||||
def __unicode__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user