Merge pull request #13168 from ArtsiomMusin/feature_13055_add_multiple_assert_export

Add multiple asset export for awx cli
This commit is contained in:
Jeff Bradberry
2022-11-30 15:01:42 -05:00
committed by GitHub
4 changed files with 89 additions and 39 deletions

View File

@@ -213,11 +213,23 @@ class ApiV2(base.Base):
assets = (self._export(asset, post_fields) for asset in endpoint.results)
return [asset for asset in assets if asset is not None]
def _check_for_int(self, value):
return isinstance(value, int) or (isinstance(value, str) and value.isdecimal())
def _filtered_list(self, endpoint, value):
if isinstance(value, int) or value.isdecimal():
if isinstance(value, list) and len(value) == 1:
value = value[0]
if self._check_for_int(value):
return endpoint.get(id=int(value))
options = self._cache.get_options(endpoint)
identifier = next(field for field in options['search_fields'] if field in ('name', 'username', 'hostname'))
if isinstance(value, list):
if all(self._check_for_int(item) for item in value):
identifier = 'or__id'
else:
identifier = 'or__' + identifier
return endpoint.get(**{identifier: value}, all_pages=True)
def export_assets(self, **kwargs):