Merge pull request #5194 from AlanCoding/inventory_organization

Add organization parameter to tower_inventory_source (and add test logging)

Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
softwarefactory-project-zuul[bot]
2019-11-20 18:23:27 +00:00
committed by GitHub
3 changed files with 102 additions and 5 deletions

View File

@@ -37,6 +37,10 @@ options:
- The inventory the source is linked to.
required: True
type: str
organization:
description:
- Organization the inventory belongs to.
type: str
source:
description:
- Types of inventory source.
@@ -163,6 +167,7 @@ EXAMPLES = '''
name: Inventory source
description: My Inventory source
inventory: My inventory
organization: My organization
credential: Devstack_credential
source: openstack
update_on_launch: true
@@ -224,6 +229,7 @@ def main():
overwrite_vars=dict(type='bool', required=False),
update_on_launch=dict(type='bool', required=False),
update_cache_timeout=dict(type='int', required=False),
organization=dict(type='str'),
state=dict(choices=['present', 'absent'], default='present'),
)
@@ -233,6 +239,7 @@ def main():
inventory = module.params.get('inventory')
source = module.params.get('source')
state = module.params.get('state')
organization = module.params.get('organization')
json_output = {'inventory_source': name, 'state': state}
@@ -248,11 +255,25 @@ def main():
if module.params.get('description'):
params['description'] = module.params.get('description')
if organization:
try:
org_res = tower_cli.get_resource('organization')
org = org_res.get(name=organization)
except (exc.NotFound) as excinfo:
module.fail_json(
msg='Failed to get organization,'
'organization not found: {0}'.format(excinfo),
changed=False
)
org_id = org['id']
else:
org_id = None # interpreted as not provided
if module.params.get('credential'):
credential_res = tower_cli.get_resource('credential')
try:
credential = credential_res.get(
name=module.params.get('credential'))
name=module.params.get('credential'), organization=org_id)
params['credential'] = credential['id']
except (exc.NotFound) as excinfo:
module.fail_json(
@@ -265,7 +286,7 @@ def main():
source_project_res = tower_cli.get_resource('project')
try:
source_project = source_project_res.get(
name=module.params.get('source_project'))
name=module.params.get('source_project'), organization=org_id)
params['source_project'] = source_project['id']
except (exc.NotFound) as excinfo:
module.fail_json(
@@ -278,7 +299,7 @@ def main():
source_script_res = tower_cli.get_resource('inventory_script')
try:
script = source_script_res.get(
name=module.params.get('source_script'))
name=module.params.get('source_script'), organization=org_id)
params['source_script'] = script['id']
except (exc.NotFound) as excinfo:
module.fail_json(
@@ -289,7 +310,7 @@ def main():
try:
inventory_res = tower_cli.get_resource('inventory')
params['inventory'] = inventory_res.get(name=inventory)['id']
params['inventory'] = inventory_res.get(name=inventory, organization=org_id)['id']
except (exc.NotFound) as excinfo:
module.fail_json(
msg='Failed to update inventory source, '