mirror of
https://github.com/ansible/awx.git
synced 2024-10-31 15:21:13 +03:00
Limit export output to only those fields needed to create the resource
This commit is contained in:
parent
f21d6b1fc4
commit
c1a07ff00b
@ -133,13 +133,16 @@ class Export(CustomCommand):
|
||||
|
||||
def get_resources(self, client, resource, value):
|
||||
api_resource = getattr(client.v2, resource)
|
||||
post_fields = api_resource.options().json['actions']['POST']
|
||||
if value:
|
||||
from .options import pk_or_name
|
||||
|
||||
pk = pk_or_name(client.v2, resource, value)
|
||||
return api_resource.get(id=pk).json['results']
|
||||
results = api_resource.get(id=pk).json['results']
|
||||
else:
|
||||
return api_resource.get(all_pages=True).json['results']
|
||||
results = api_resource.get(all_pages=True).json['results']
|
||||
|
||||
return [{key: r[key] for key in post_fields if key in r} for r in results]
|
||||
|
||||
def handle(self, client, parser):
|
||||
self.extend_parser(parser)
|
||||
@ -156,7 +159,7 @@ class Export(CustomCommand):
|
||||
value = getattr(parsed, resource, None)
|
||||
if value is None:
|
||||
continue
|
||||
resources = self.get_resources(client, resource, value) or []
|
||||
resources = self.get_resources(client, resource, value)
|
||||
|
||||
data[resource] = resources
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user