mirror of
https://github.com/ansible/awx.git
synced 2026-03-18 09:27:31 -02:30
Merge pull request #1762 from AlanCoding/1759_launch_fields
Launch endpoints as shortcut to JT data
This commit is contained in:
@@ -38,7 +38,7 @@ from polymorphic import PolymorphicModel
|
|||||||
from awx.main.constants import SCHEDULEABLE_PROVIDERS
|
from awx.main.constants import SCHEDULEABLE_PROVIDERS
|
||||||
from awx.main.models import * # noqa
|
from awx.main.models import * # noqa
|
||||||
from awx.main.fields import ImplicitRoleField
|
from awx.main.fields import ImplicitRoleField
|
||||||
from awx.main.utils import get_type_for_model, get_model_for_type, build_url, timestamp_apiformat, camelcase_to_underscore
|
from awx.main.utils import get_type_for_model, get_model_for_type, build_url, timestamp_apiformat, camelcase_to_underscore, getattrd
|
||||||
from awx.main.redact import REPLACE_STR
|
from awx.main.redact import REPLACE_STR
|
||||||
from awx.main.conf import tower_settings
|
from awx.main.conf import tower_settings
|
||||||
|
|
||||||
@@ -2155,6 +2155,8 @@ class JobLaunchSerializer(BaseSerializer):
|
|||||||
inventory_needed_to_start = serializers.SerializerMethodField()
|
inventory_needed_to_start = serializers.SerializerMethodField()
|
||||||
survey_enabled = serializers.SerializerMethodField()
|
survey_enabled = serializers.SerializerMethodField()
|
||||||
extra_vars = VerbatimField(required=False, write_only=True)
|
extra_vars = VerbatimField(required=False, write_only=True)
|
||||||
|
job_template_data = serializers.SerializerMethodField()
|
||||||
|
defaults = serializers.SerializerMethodField()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = JobTemplate
|
model = JobTemplate
|
||||||
@@ -2164,7 +2166,8 @@ class JobLaunchSerializer(BaseSerializer):
|
|||||||
'ask_job_type_on_launch', 'ask_limit_on_launch',
|
'ask_job_type_on_launch', 'ask_limit_on_launch',
|
||||||
'ask_inventory_on_launch', 'ask_credential_on_launch',
|
'ask_inventory_on_launch', 'ask_credential_on_launch',
|
||||||
'survey_enabled', 'variables_needed_to_start',
|
'survey_enabled', 'variables_needed_to_start',
|
||||||
'credential_needed_to_start', 'inventory_needed_to_start',)
|
'credential_needed_to_start', 'inventory_needed_to_start',
|
||||||
|
'job_template_data', 'defaults')
|
||||||
read_only_fields = ('ask_variables_on_launch', 'ask_limit_on_launch',
|
read_only_fields = ('ask_variables_on_launch', 'ask_limit_on_launch',
|
||||||
'ask_tags_on_launch', 'ask_job_type_on_launch',
|
'ask_tags_on_launch', 'ask_job_type_on_launch',
|
||||||
'ask_inventory_on_launch', 'ask_credential_on_launch')
|
'ask_inventory_on_launch', 'ask_credential_on_launch')
|
||||||
@@ -2188,6 +2191,21 @@ class JobLaunchSerializer(BaseSerializer):
|
|||||||
return obj.survey_enabled and 'spec' in obj.survey_spec
|
return obj.survey_enabled and 'spec' in obj.survey_spec
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def get_defaults(self, obj):
|
||||||
|
ask_for_vars_dict = obj._ask_for_vars_dict()
|
||||||
|
defaults_dict = {}
|
||||||
|
for field in ask_for_vars_dict:
|
||||||
|
if field in ('inventory', 'credential'):
|
||||||
|
defaults_dict[field] = dict(
|
||||||
|
name=getattrd(obj, '%s.name' % field, None),
|
||||||
|
id=getattrd(obj, '%s.pk' % field, None))
|
||||||
|
else:
|
||||||
|
defaults_dict[field] = getattr(obj, field)
|
||||||
|
return defaults_dict
|
||||||
|
|
||||||
|
def get_job_template_data(self, obj):
|
||||||
|
return dict(name=obj.name, id=obj.id, description=obj.description)
|
||||||
|
|
||||||
def validate(self, attrs):
|
def validate(self, attrs):
|
||||||
errors = {}
|
errors = {}
|
||||||
obj = self.context.get('obj')
|
obj = self.context.get('obj')
|
||||||
|
|||||||
Reference in New Issue
Block a user