diff --git a/lib/ansible/modules/network/aci/mso_label.py b/lib/ansible/modules/network/aci/mso_label.py index 842294ec381..f5c7f6e03b1 100644 --- a/lib/ansible/modules/network/aci/mso_label.py +++ b/lib/ansible/modules/network/aci/mso_label.py @@ -21,14 +21,9 @@ author: - Dag Wieers (@dagwieers) version_added: '2.8' options: - label_id: - description: - - The ID of the label. - type: str label: description: - The name of the label. - - Alternative to the name, you can use C(label_id). type: str required: yes aliases: [ name ] @@ -99,7 +94,6 @@ def main(): argument_spec = mso_argument_spec() argument_spec.update( label=dict(type='str', aliases=['name']), - label_id=dict(type='str'), type=dict(type='str', default='site', choices=['site']), state=dict(type='str', default='present', choices=['absent', 'present', 'query']), ) @@ -114,32 +108,23 @@ def main(): ) label = module.params['label'] - label_id = module.params['label_id'] label_type = module.params['type'] state = module.params['state'] mso = MSOModule(module) + label_id = None path = 'labels' # Query for existing object(s) - if label_id is None and label is None: - mso.existing = mso.query_objs(path) - elif label_id is None: + if label: mso.existing = mso.get_obj(path, displayName=label) if mso.existing: label_id = mso.existing['id'] - elif label is None: - mso.existing = mso.get_obj(path, id=label_id) + # If we found an existing object, continue with it + path = 'labels/{id}'.format(id=label_id) else: - mso.existing = mso.get_obj(path, id=label_id) - existing_by_name = mso.get_obj(path, displayName=label) - if existing_by_name and label_id != existing_by_name['id']: - mso.fail_json(msg="Provided label '{0}' with id '{1}' does not match existing id '{2}'.".format(label, label_id, existing_by_name['id'])) - - # If we found an existing object, continue with it - if label_id: - path = 'labels/{id}'.format(id=label_id) + mso.existing = mso.query_objs(path) if state == 'query': pass diff --git a/lib/ansible/modules/network/aci/mso_role.py b/lib/ansible/modules/network/aci/mso_role.py index d7a1ebac263..f29ef168d97 100644 --- a/lib/ansible/modules/network/aci/mso_role.py +++ b/lib/ansible/modules/network/aci/mso_role.py @@ -21,14 +21,9 @@ author: - Dag Wieers (@dagwieers) version_added: '2.8' options: - role_id: - description: - - The ID of the role. - type: str role: description: - The name of the role. - - Alternative to the name, you can use C(role_id). type: str required: yes aliases: [ name ] @@ -132,7 +127,6 @@ def main(): argument_spec = mso_argument_spec() argument_spec.update( role=dict(type='str', aliases=['name']), - role_id=dict(type='str'), display_name=dict(type='str'), description=dict(type='str'), permissions=dict(type='list', choices=[ @@ -168,33 +162,24 @@ def main(): ) role = module.params['role'] - role_id = module.params['role_id'] description = module.params['description'] permissions = module.params['permissions'] state = module.params['state'] mso = MSOModule(module) + role_id = None path = 'roles' # Query for existing object(s) - if role_id is None and role is None: - mso.existing = mso.query_objs(path) - elif role_id is None: + if role: mso.existing = mso.get_obj(path, name=role) if mso.existing: role_id = mso.existing['id'] - elif role is None: - mso.existing = mso.get_obj(path, id=role_id) + # If we found an existing object, continue with it + path = 'roles/{id}'.format(id=role_id) else: - mso.existing = mso.get_obj(path, id=role_id) - existing_by_name = mso.get_obj(path, name=role) - if existing_by_name and role_id != existing_by_name['id']: - mso.fail_json(msg="Provided role '{0}' with id '{1}' does not match existing id '{2}'.".format(role, role_id, existing_by_name['id'])) - - # If we found an existing object, continue with it - if role_id: - path = 'roles/{id}'.format(id=role_id) + mso.existing = mso.query_objs(path) if state == 'query': pass diff --git a/lib/ansible/modules/network/aci/mso_schema.py b/lib/ansible/modules/network/aci/mso_schema.py index 9c12fe39181..50eadfd5fa4 100644 --- a/lib/ansible/modules/network/aci/mso_schema.py +++ b/lib/ansible/modules/network/aci/mso_schema.py @@ -21,11 +21,6 @@ author: - Dag Wieers (@dagwieers) version_added: '2.8' options: - schema_id: - description: - - The ID of the schema. - type: str - required: yes schema: description: - The name of the schema. @@ -117,7 +112,6 @@ def main(): argument_spec = mso_argument_spec() argument_spec.update( schema=dict(type='str', aliases=['name']), - schema_id=dict(type='str'), templates=dict(type='list'), sites=dict(type='list'), # messages=dict(type='dict'), @@ -138,32 +132,23 @@ def main(): ) schema = module.params['schema'] - schema_id = module.params['schema_id'] templates = module.params['templates'] sites = module.params['sites'] state = module.params['state'] mso = MSOModule(module) + schema_id = None path = 'schemas' # Query for existing object(s) - if schema_id is None and schema is None: - mso.existing = mso.query_objs(path) - elif schema_id is None: + if schema: mso.existing = mso.get_obj(path, displayName=schema) if mso.existing: schema_id = mso.existing['id'] - elif schema is None: - mso.existing = mso.get_obj(path, id=schema_id) + path = 'schemas/{id}'.format(id=schema_id) else: - mso.existing = mso.get_obj(path, id=schema_id) - existing_by_name = mso.get_obj(path, displayName=schema) - if existing_by_name and schema_id != existing_by_name['id']: - mso.fail_json(msg="Provided schema '{1}' with id '{2}' does not match existing id '{3}'.".format(schema, schema_id, existing_by_name['id'])) - - if schema_id: - path = 'schemas/{id}'.format(id=schema_id) + mso.existing = mso.query_objs(path) if state == 'query': pass diff --git a/lib/ansible/modules/network/aci/mso_site.py b/lib/ansible/modules/network/aci/mso_site.py index b1f4c4eda50..d6c2c1a3a21 100644 --- a/lib/ansible/modules/network/aci/mso_site.py +++ b/lib/ansible/modules/network/aci/mso_site.py @@ -37,14 +37,9 @@ options: type: str required: yes default: admin - site_id: - description: - - The ID of the site. - type: str site: description: - The name of the site. - - Alternative to the name, you can use C(site_id). type: str required: yes aliases: [ name ] @@ -63,7 +58,7 @@ options: type: float longitude: description: - - The longititude of the location of the site. + - The longitude of the location of the site. type: float urls: description: @@ -154,7 +149,6 @@ def main(): labels=dict(type='list'), location=dict(type='dict', options=location_arg_spec), site=dict(type='str', aliases=['name']), - site_id=dict(type='str'), state=dict(type='str', default='present', choices=['absent', 'present', 'query']), urls=dict(type='list'), ) @@ -172,7 +166,6 @@ def main(): apic_password = module.params['apic_password'] apic_site_id = module.params['apic_site_id'] site = module.params['site'] - site_id = module.params['site_id'] location = module.params['location'] if location is not None: latitude = module.params['location']['latitude'] @@ -182,29 +175,21 @@ def main(): mso = MSOModule(module) + site_id = None path = 'sites' # Convert labels labels = mso.lookup_labels(module.params['labels'], 'site') # Query for mso.existing object(s) - if site_id is None and site is None: - mso.existing = mso.query_objs(path) - elif site_id is None: + if site: mso.existing = mso.get_obj(path, name=site) if mso.existing: site_id = mso.existing['id'] - elif site is None: - mso.existing = mso.get_obj(path, id=site_id) + # If we found an existing object, continue with it + path = 'sites/{id}'.format(id=site_id) else: - mso.existing = mso.get_obj(path, id=site_id) - existing_by_name = mso.get_obj(path, name=site) - if existing_by_name and site_id != existing_by_name['id']: - mso.fail_json(msg="Provided site '{0}' with id '{1}' does not match existing id '{2}'.".format(site, site_id, existing_by_name['id'])) - - # If we found an existing object, continue with it - if site_id: - path = 'sites/{id}'.format(id=site_id) + mso.existing = mso.query_objs(path) if state == 'query': pass diff --git a/lib/ansible/modules/network/aci/mso_tenant.py b/lib/ansible/modules/network/aci/mso_tenant.py index 02b1f07483e..f3fcd223b36 100644 --- a/lib/ansible/modules/network/aci/mso_tenant.py +++ b/lib/ansible/modules/network/aci/mso_tenant.py @@ -21,14 +21,9 @@ author: - Dag Wieers (@dagwieers) version_added: '2.8' options: - tenant_id: - description: - - The ID of the tenant. - type: str tenant: description: - The name of the tenant. - - Alternative to the name, you can use C(tenant_id). type: str required: yes aliases: [ name ] @@ -68,7 +63,6 @@ EXAMPLES = r''' username: admin password: SomeSecretPassword tenant: north_europe - tenant_id: 101 display_name: North European Datacenter description: This tenant manages the NEDC environment. state: present @@ -116,7 +110,6 @@ def main(): description=dict(type='str'), display_name=dict(type='str'), tenant=dict(type='str', aliases=['name']), - tenant_id=dict(type='str'), users=dict(type='list'), sites=dict(type='list'), state=dict(type='str', default='present', choices=['absent', 'present', 'query']), @@ -134,7 +127,6 @@ def main(): description = module.params['description'] display_name = module.params['display_name'] tenant = module.params['tenant'] - tenant_id = module.params['tenant_id'] state = module.params['state'] mso = MSOModule(module) @@ -143,26 +135,18 @@ def main(): sites = mso.lookup_sites(module.params['sites']) users = mso.lookup_users(module.params['users']) + tenant_id = None path = 'tenants' # Query for existing object(s) - if tenant_id is None and tenant is None: - mso.existing = mso.query_objs(path) - elif tenant_id is None: + if tenant: mso.existing = mso.get_obj(path, name=tenant) if mso.existing: tenant_id = mso.existing['id'] - elif tenant is None: - mso.existing = mso.get_obj(path, id=tenant_id) + # If we found an existing object, continue with it + path = 'tenants/{id}'.format(id=tenant_id) else: - mso.existing = mso.get_obj(path, id=tenant_id) - existing_by_name = mso.get_obj(path, name=tenant) - if existing_by_name and tenant_id != existing_by_name['id']: - mso.fail_json(msg="Provided tenant '{0}' with id '{1}' does not match existing id '{2}'.".format(tenant, tenant_id, existing_by_name['id'])) - - # If we found an existing object, continue with it - if tenant_id: - path = 'tenants/{id}'.format(id=tenant_id) + mso.existing = mso.query_objs(path) if state == 'query': pass diff --git a/lib/ansible/modules/network/aci/mso_user.py b/lib/ansible/modules/network/aci/mso_user.py index 56fc708c6a3..161e91055b3 100644 --- a/lib/ansible/modules/network/aci/mso_user.py +++ b/lib/ansible/modules/network/aci/mso_user.py @@ -21,14 +21,9 @@ author: - Dag Wieers (@dagwieers) version_added: '2.8' options: - user_id: - description: - - The ID of the user. - type: str user: description: - The name of the user. - - Alternative to the name, you can use C(user_id). type: str required: yes aliases: [ name ] @@ -146,7 +141,6 @@ from ansible.module_utils.network.aci.mso import MSOModule, mso_argument_spec, i def main(): argument_spec = mso_argument_spec() argument_spec.update( - user_id=dict(type='str'), user=dict(type='str', aliases=['name']), user_password=dict(type='str', no_log=True), first_name=dict(type='str'), @@ -169,7 +163,6 @@ def main(): ], ) - user_id = module.params['user_id'] user_name = module.params['user'] user_password = module.params['user_password'] first_name = module.params['first_name'] @@ -184,26 +177,18 @@ def main(): roles = mso.lookup_roles(module.params['roles']) domain = mso.lookup_domain(module.params['domain']) + user_id = None path = 'users' # Query for existing object(s) - if user_id is None and user_name is None: - mso.existing = mso.query_objs(path) - elif user_id is None: + if user_name: mso.existing = mso.get_obj(path, username=user_name) if mso.existing: user_id = mso.existing['id'] - elif user_name is None: - mso.existing = mso.get_obj(path, id=user_id) + # If we found an existing object, continue with it + path = 'users/{id}'.format(id=user_id) else: - mso.existing = mso.get_obj(path, id=user_id) - existing_by_name = mso.get_obj(path, username=user_name) - if existing_by_name and user_id != existing_by_name['id']: - mso.fail_json(msg="Provided user '{0}' with id '{1}' does not match existing id '{2}'.".format(user_name, user_id, existing_by_name['id'])) - - # If we found an existing object, continue with it - if user_id: - path = 'users/{id}'.format(id=user_id) + mso.existing = mso.query_objs(path) if state == 'query': pass