mirror of
https://github.com/ansible/awx.git
synced 2026-03-21 19:07:39 -02:30
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:
committed by
Shane McDonald
parent
8562c378c0
commit
4993a9e6ec
@@ -198,8 +198,8 @@ class AdHocCommand(UnifiedJob, JobNotificationMixin):
|
|||||||
def copy(self):
|
def copy(self):
|
||||||
data = {}
|
data = {}
|
||||||
for field in ('job_type', 'inventory_id', 'limit', 'credential_id',
|
for field in ('job_type', 'inventory_id', 'limit', 'credential_id',
|
||||||
'module_name', 'module_args', 'forks', 'verbosity',
|
'execution_environment_id', 'module_name', 'module_args',
|
||||||
'extra_vars', 'become_enabled', 'diff_mode'):
|
'forks', 'verbosity', 'extra_vars', 'become_enabled', 'diff_mode'):
|
||||||
data[field] = getattr(self, field)
|
data[field] = getattr(self, field)
|
||||||
return AdHocCommand.objects.create(**data)
|
return AdHocCommand.objects.create(**data)
|
||||||
|
|
||||||
|
|||||||
@@ -455,6 +455,25 @@ class ExecutionEnvironmentMixin(models.Model):
|
|||||||
help_text=_('The container image to be used for execution.'),
|
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 CustomVirtualEnvMixin(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ from awx.main.dispatch import get_local_queuename
|
|||||||
from awx.main.dispatch.control import Control as ControlDispatcher
|
from awx.main.dispatch.control import Control as ControlDispatcher
|
||||||
from awx.main.registrar import activity_stream_registrar
|
from awx.main.registrar import activity_stream_registrar
|
||||||
from awx.main.models.mixins import ResourceMixin, TaskManagerUnifiedJobMixin, ExecutionEnvironmentMixin
|
from awx.main.models.mixins import ResourceMixin, TaskManagerUnifiedJobMixin, ExecutionEnvironmentMixin
|
||||||
from awx.main.models.execution_environments import ExecutionEnvironment
|
|
||||||
from awx.main.utils import (
|
from awx.main.utils import (
|
||||||
camelcase_to_underscore, get_model_for_type,
|
camelcase_to_underscore, get_model_for_type,
|
||||||
encrypt_dict, decrypt_field, _inventory_updates,
|
encrypt_dict, decrypt_field, _inventory_updates,
|
||||||
@@ -339,23 +338,6 @@ class UnifiedJobTemplate(PolymorphicModel, CommonModelNameNotUnique, ExecutionEn
|
|||||||
from awx.main.models.notifications import NotificationTemplate
|
from awx.main.models.notifications import NotificationTemplate
|
||||||
return NotificationTemplate.objects.none()
|
return NotificationTemplate.objects.none()
|
||||||
|
|
||||||
def resolve_execution_environment(self):
|
|
||||||
"""
|
|
||||||
Return the execution environment that should be used when creating a new job.
|
|
||||||
"""
|
|
||||||
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()
|
|
||||||
|
|
||||||
def create_unified_job(self, **kwargs):
|
def create_unified_job(self, **kwargs):
|
||||||
'''
|
'''
|
||||||
Create a new unified job based on this unified job template.
|
Create a new unified job based on this unified job template.
|
||||||
|
|||||||
@@ -887,6 +887,9 @@ class BaseTask(object):
|
|||||||
return os.path.abspath(os.path.join(os.path.dirname(__file__), *args))
|
return os.path.abspath(os.path.join(os.path.dirname(__file__), *args))
|
||||||
|
|
||||||
def build_execution_environment_params(self, instance):
|
def build_execution_environment_params(self, instance):
|
||||||
|
if instance.execution_environment_id is None:
|
||||||
|
self.update_model(instance.pk, execution_environment=instance.resolve_execution_environment())
|
||||||
|
|
||||||
image = instance.execution_environment.image
|
image = instance.execution_environment.image
|
||||||
params = {
|
params = {
|
||||||
"container_image": image,
|
"container_image": image,
|
||||||
|
|||||||
Reference in New Issue
Block a user