mirror of
https://github.com/ansible/awx.git
synced 2026-05-13 04:17:36 -02:30
Update the inventory_import management command
to respect the new Organization.max_hosts limit.
This commit is contained in:
@@ -904,10 +904,27 @@ class Command(BaseCommand):
|
|||||||
logger.error(LICENSE_MESSAGE % d)
|
logger.error(LICENSE_MESSAGE % d)
|
||||||
raise CommandError('License count exceeded!')
|
raise CommandError('License count exceeded!')
|
||||||
|
|
||||||
|
def check_org_host_limit(self):
|
||||||
|
license_info = get_licenser().validate()
|
||||||
|
if license_info.get('license_type', 'UNLICENSED') == 'open':
|
||||||
|
return
|
||||||
|
|
||||||
|
org = self.inventory.organization
|
||||||
|
if org is None or org.max_hosts == 0:
|
||||||
|
return
|
||||||
|
|
||||||
|
active_count = Host.objects.org_active_count(org.id)
|
||||||
|
if active_count > org.max_hosts:
|
||||||
|
raise CommandError('Host limit for organization exceeded!')
|
||||||
|
|
||||||
def mark_license_failure(self, save=True):
|
def mark_license_failure(self, save=True):
|
||||||
self.inventory_update.license_error = True
|
self.inventory_update.license_error = True
|
||||||
self.inventory_update.save(update_fields=['license_error'])
|
self.inventory_update.save(update_fields=['license_error'])
|
||||||
|
|
||||||
|
def mark_org_limits_failure(self, save=True):
|
||||||
|
self.inventory_update.org_host_limit_error = True
|
||||||
|
self.inventory_update.save(update_fields=['org_host_limit_error'])
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
self.verbosity = int(options.get('verbosity', 1))
|
self.verbosity = int(options.get('verbosity', 1))
|
||||||
self.set_logging_level()
|
self.set_logging_level()
|
||||||
@@ -961,6 +978,13 @@ class Command(BaseCommand):
|
|||||||
self.mark_license_failure(save=True)
|
self.mark_license_failure(save=True)
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Check the per-org host limits
|
||||||
|
self.check_org_host_limit()
|
||||||
|
except CommandError as e:
|
||||||
|
self.mark_org_limits_failure(save=True)
|
||||||
|
raise e
|
||||||
|
|
||||||
status, tb, exc = 'error', '', None
|
status, tb, exc = 'error', '', None
|
||||||
try:
|
try:
|
||||||
if settings.SQL_DEBUG:
|
if settings.SQL_DEBUG:
|
||||||
@@ -1032,9 +1056,17 @@ class Command(BaseCommand):
|
|||||||
# If the license is not valid, a CommandError will be thrown,
|
# If the license is not valid, a CommandError will be thrown,
|
||||||
# and inventory update will be marked as invalid.
|
# and inventory update will be marked as invalid.
|
||||||
# with transaction.atomic() will roll back the changes.
|
# with transaction.atomic() will roll back the changes.
|
||||||
|
license_fail = True
|
||||||
self.check_license()
|
self.check_license()
|
||||||
|
|
||||||
|
# Check the per-org host limits
|
||||||
|
license_fail = False
|
||||||
|
self.check_org_host_limit()
|
||||||
except CommandError as e:
|
except CommandError as e:
|
||||||
self.mark_license_failure()
|
if license_fail:
|
||||||
|
self.mark_license_failure()
|
||||||
|
else:
|
||||||
|
self.mark_org_limits_failure()
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
if settings.SQL_DEBUG:
|
if settings.SQL_DEBUG:
|
||||||
@@ -1062,7 +1094,6 @@ class Command(BaseCommand):
|
|||||||
else:
|
else:
|
||||||
tb = traceback.format_exc()
|
tb = traceback.format_exc()
|
||||||
exc = e
|
exc = e
|
||||||
transaction.rollback()
|
|
||||||
|
|
||||||
if self.invoked_from_dispatcher is False:
|
if self.invoked_from_dispatcher is False:
|
||||||
with ignore_inventory_computed_fields():
|
with ignore_inventory_computed_fields():
|
||||||
|
|||||||
@@ -1653,6 +1653,10 @@ class InventoryUpdate(UnifiedJob, InventorySourceOptions, JobNotificationMixin,
|
|||||||
default=False,
|
default=False,
|
||||||
editable=False,
|
editable=False,
|
||||||
)
|
)
|
||||||
|
org_host_limit_error = models.BooleanField(
|
||||||
|
default=False,
|
||||||
|
editable=False,
|
||||||
|
)
|
||||||
source_project_update = models.ForeignKey(
|
source_project_update = models.ForeignKey(
|
||||||
'ProjectUpdate',
|
'ProjectUpdate',
|
||||||
related_name='scm_inventory_updates',
|
related_name='scm_inventory_updates',
|
||||||
|
|||||||
Reference in New Issue
Block a user