mirror of
https://github.com/ansible/awx.git
synced 2026-01-11 10:00:01 -03:30
Merge pull request #13168 from ArtsiomMusin/feature_13055_add_multiple_assert_export
Add multiple asset export for awx cli
This commit is contained in:
commit
7fa9dcbc2a
@ -28,52 +28,64 @@ options:
|
|||||||
default: 'False'
|
default: 'False'
|
||||||
organizations:
|
organizations:
|
||||||
description:
|
description:
|
||||||
- organization name to export
|
- organization names to export
|
||||||
type: str
|
type: list
|
||||||
|
elements: str
|
||||||
users:
|
users:
|
||||||
description:
|
description:
|
||||||
- user name to export
|
- user names to export
|
||||||
type: str
|
type: list
|
||||||
|
elements: str
|
||||||
teams:
|
teams:
|
||||||
description:
|
description:
|
||||||
- team name to export
|
- team names to export
|
||||||
type: str
|
type: list
|
||||||
|
elements: str
|
||||||
credential_types:
|
credential_types:
|
||||||
description:
|
description:
|
||||||
- credential type name to export
|
- credential type names to export
|
||||||
type: str
|
type: list
|
||||||
|
elements: str
|
||||||
credentials:
|
credentials:
|
||||||
description:
|
description:
|
||||||
- credential name to export
|
- credential names to export
|
||||||
type: str
|
type: list
|
||||||
|
elements: str
|
||||||
execution_environments:
|
execution_environments:
|
||||||
description:
|
description:
|
||||||
- execution environment name to export
|
- execution environment names to export
|
||||||
type: str
|
type: list
|
||||||
|
elements: str
|
||||||
notification_templates:
|
notification_templates:
|
||||||
description:
|
description:
|
||||||
- notification template name to export
|
- notification template names to export
|
||||||
type: str
|
type: list
|
||||||
|
elements: str
|
||||||
inventory_sources:
|
inventory_sources:
|
||||||
description:
|
description:
|
||||||
- inventory soruce to export
|
- inventory soruces to export
|
||||||
type: str
|
type: list
|
||||||
|
elements: str
|
||||||
inventory:
|
inventory:
|
||||||
description:
|
description:
|
||||||
- inventory name to export
|
- inventory names to export
|
||||||
type: str
|
type: list
|
||||||
|
elements: str
|
||||||
projects:
|
projects:
|
||||||
description:
|
description:
|
||||||
- project name to export
|
- project names to export
|
||||||
type: str
|
type: list
|
||||||
|
elements: str
|
||||||
job_templates:
|
job_templates:
|
||||||
description:
|
description:
|
||||||
- job template name to export
|
- job template names to export
|
||||||
type: str
|
type: list
|
||||||
|
elements: str
|
||||||
workflow_job_templates:
|
workflow_job_templates:
|
||||||
description:
|
description:
|
||||||
- workflow name to export
|
- workflow names to export
|
||||||
type: str
|
type: list
|
||||||
|
elements: str
|
||||||
requirements:
|
requirements:
|
||||||
- "awxkit >= 9.3.0"
|
- "awxkit >= 9.3.0"
|
||||||
notes:
|
notes:
|
||||||
@ -94,6 +106,10 @@ EXAMPLES = '''
|
|||||||
export:
|
export:
|
||||||
job_templates: "My Template"
|
job_templates: "My Template"
|
||||||
credential: 'all'
|
credential: 'all'
|
||||||
|
|
||||||
|
- name: Export a list of inventories
|
||||||
|
export:
|
||||||
|
inventory: ['My Inventory 1', 'My Inventory 2']
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
@ -111,24 +127,12 @@ except ImportError:
|
|||||||
def main():
|
def main():
|
||||||
argument_spec = dict(
|
argument_spec = dict(
|
||||||
all=dict(type='bool', default=False),
|
all=dict(type='bool', default=False),
|
||||||
credential_types=dict(type='str'),
|
|
||||||
credentials=dict(type='str'),
|
|
||||||
execution_environments=dict(type='str'),
|
|
||||||
inventory=dict(type='str'),
|
|
||||||
inventory_sources=dict(type='str'),
|
|
||||||
job_templates=dict(type='str'),
|
|
||||||
notification_templates=dict(type='str'),
|
|
||||||
organizations=dict(type='str'),
|
|
||||||
projects=dict(type='str'),
|
|
||||||
teams=dict(type='str'),
|
|
||||||
users=dict(type='str'),
|
|
||||||
workflow_job_templates=dict(type='str'),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# We are not going to raise an error here because the __init__ method of ControllerAWXKitModule will do that for us
|
# We are not going to raise an error here because the __init__ method of ControllerAWXKitModule will do that for us
|
||||||
if HAS_EXPORTABLE_RESOURCES:
|
if HAS_EXPORTABLE_RESOURCES:
|
||||||
for resource in EXPORTABLE_RESOURCES:
|
for resource in EXPORTABLE_RESOURCES:
|
||||||
argument_spec[resource] = dict(type='str')
|
argument_spec[resource] = dict(type='list', elements='str')
|
||||||
|
|
||||||
module = ControllerAWXKitModule(argument_spec=argument_spec)
|
module = ControllerAWXKitModule(argument_spec=argument_spec)
|
||||||
|
|
||||||
|
|||||||
@ -61,6 +61,40 @@
|
|||||||
- mixed_export['assets']['organizations'] | length() == 1
|
- mixed_export['assets']['organizations'] | length() == 1
|
||||||
- "'workflow_job_templates' not in mixed_export['assets']"
|
- "'workflow_job_templates' not in mixed_export['assets']"
|
||||||
|
|
||||||
|
- name: Export list of organizations
|
||||||
|
export:
|
||||||
|
organizations: "{{[org_name1, org_name2]}}"
|
||||||
|
register: list_asserts
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- list_asserts is not changed
|
||||||
|
- list_asserts is successful
|
||||||
|
- list_asserts['assets']['organizations'] | length() >= 2
|
||||||
|
|
||||||
|
- name: Export list with one organization
|
||||||
|
export:
|
||||||
|
organizations: "{{[org_name1]}}"
|
||||||
|
register: list_asserts
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- list_asserts is not changed
|
||||||
|
- list_asserts is successful
|
||||||
|
- list_asserts['assets']['organizations'] | length() >= 1
|
||||||
|
- "org_name1 in (list_asserts['assets']['organizations'] | map(attribute='name') )"
|
||||||
|
|
||||||
|
- name: Export one organization as string
|
||||||
|
export:
|
||||||
|
organizations: "{{org_name2}}"
|
||||||
|
register: string_asserts
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- string_asserts is not changed
|
||||||
|
- string_asserts is successful
|
||||||
|
- string_asserts['assets']['organizations'] | length() >= 1
|
||||||
|
- "org_name2 in (string_asserts['assets']['organizations'] | map(attribute='name') )"
|
||||||
always:
|
always:
|
||||||
- name: Remove our inventory
|
- name: Remove our inventory
|
||||||
inventory:
|
inventory:
|
||||||
|
|||||||
@ -213,11 +213,23 @@ class ApiV2(base.Base):
|
|||||||
assets = (self._export(asset, post_fields) for asset in endpoint.results)
|
assets = (self._export(asset, post_fields) for asset in endpoint.results)
|
||||||
return [asset for asset in assets if asset is not None]
|
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):
|
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))
|
return endpoint.get(id=int(value))
|
||||||
|
|
||||||
options = self._cache.get_options(endpoint)
|
options = self._cache.get_options(endpoint)
|
||||||
identifier = next(field for field in options['search_fields'] if field in ('name', 'username', 'hostname'))
|
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)
|
return endpoint.get(**{identifier: value}, all_pages=True)
|
||||||
|
|
||||||
def export_assets(self, **kwargs):
|
def export_assets(self, **kwargs):
|
||||||
|
|||||||
@ -161,7 +161,7 @@ class Export(CustomCommand):
|
|||||||
# 1) the resource flag is not used at all, which will result in the attr being None
|
# 1) the resource flag is not used at all, which will result in the attr being None
|
||||||
# 2) the resource flag is used with no argument, which will result in the attr being ''
|
# 2) the resource flag is used with no argument, which will result in the attr being ''
|
||||||
# 3) the resource flag is used with an argument, and the attr will be that argument's value
|
# 3) the resource flag is used with an argument, and the attr will be that argument's value
|
||||||
resources.add_argument('--{}'.format(resource), nargs='?', const='')
|
resources.add_argument('--{}'.format(resource), nargs='*')
|
||||||
|
|
||||||
def handle(self, client, parser):
|
def handle(self, client, parser):
|
||||||
self.extend_parser(parser)
|
self.extend_parser(parser)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user