mirror of
https://github.com/ansible/awx.git
synced 2026-01-09 23:12:08 -03:30
Serialize Workflow Job Template inventories by natural key - related #7798
This changeset introduces two changes: 1. Update the API representation of Workflow Job Templates to use the natural key of the Inventory type instead of its id; 2. Override the related property of the CLI's WorkflowJobTemplate page type to patch the related references during the export process, allowing the resource to be serialised using the natural key of the Inventory type instead of the id. Change n.2 is a workaround that is used when exporting resources from AWX/Tower instances that don't have change n.1. It can be removed in the future.
This commit is contained in:
parent
a1700404cd
commit
32c08a09c3
@ -3438,6 +3438,12 @@ class WorkflowJobTemplateSerializer(JobTemplateMixin, LabelsListMixin, UnifiedJo
|
||||
res['organization'] = self.reverse('api:organization_detail', kwargs={'pk': obj.organization.pk})
|
||||
if obj.webhook_credential_id:
|
||||
res['webhook_credential'] = self.reverse('api:credential_detail', kwargs={'pk': obj.webhook_credential_id})
|
||||
if obj.inventory:
|
||||
res['inventory'] = self.reverse(
|
||||
'api:inventory_detail', kwargs={
|
||||
'pk': obj.inventory.pk
|
||||
}
|
||||
)
|
||||
return res
|
||||
|
||||
def validate_extra_vars(self, value):
|
||||
|
||||
@ -15,6 +15,27 @@ class WorkflowJobTemplate(HasCopy, HasCreate, HasNotifications, HasSurvey, Unifi
|
||||
optional_dependencies = [Organization]
|
||||
NATURAL_KEY = ('organization', 'name')
|
||||
|
||||
@property
|
||||
def related(self):
|
||||
"""Augment the related namespace with the inventory.
|
||||
|
||||
This provides a workaround for API instances that do not provide
|
||||
a reference to this workflow's associated inventory, if defined,
|
||||
in the related namespace.
|
||||
|
||||
See issue #7798.
|
||||
"""
|
||||
related_data = self.__getattr__('related')
|
||||
if 'inventory' not in related_data:
|
||||
inventory_id = self.json['inventory']
|
||||
if inventory_id:
|
||||
endpoint_url = '/api/v2/inventories/{}/'.format(inventory_id)
|
||||
related_data['inventory'] = page.TentativePage(
|
||||
endpoint_url,
|
||||
self.connection
|
||||
)
|
||||
return related_data
|
||||
|
||||
def launch(self, payload={}):
|
||||
"""Launch using related->launch endpoint."""
|
||||
# get related->launch
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user