Move the resolve_execution_environment method to the mixin class

so that it can be used with AdHocCommands as well.
This commit is contained in:
Jeff Bradberry
2020-11-20 14:08:11 -05:00
committed by Shane McDonald
parent 8562c378c0
commit 4993a9e6ec
4 changed files with 24 additions and 20 deletions

View File

@@ -455,6 +455,25 @@ class ExecutionEnvironmentMixin(models.Model):
help_text=_('The container image to be used for execution.'),
)
def resolve_execution_environment(self):
"""
Return the execution environment that should be used when creating a new job.
"""
from awx.main.models.execution_environments import ExecutionEnvironment
if self.execution_environment is not None:
return self.execution_environment
if getattr(self, 'project_id', None) and self.project.default_environment is not None:
return self.project.default_environment
if getattr(self, 'organization', None) and self.organization.default_environment is not None:
return self.organization.default_environment
if getattr(self, 'inventory', None) and self.inventory.organization is not None:
if self.inventory.organization.default_environment is not None:
return self.inventory.organization.default_environment
if settings.DEFAULT_EXECUTION_ENVIRONMENT is not None:
return settings.DEFAULT_EXECUTION_ENVIRONMENT
return ExecutionEnvironment.objects.filter(organization=None, managed_by_tower=True).first()
class CustomVirtualEnvMixin(models.Model):
class Meta: