Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSO: Remove parameters to specify object ids #55107

Merged
merged 2 commits into from
Apr 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 5 additions & 20 deletions lib/ansible/modules/network/aci/mso_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,9 @@
- 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 ]
Expand Down Expand Up @@ -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']),
)
Expand All @@ -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
Expand Down
25 changes: 5 additions & 20 deletions lib/ansible/modules/network/aci/mso_role.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,9 @@
- 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 ]
Expand Down Expand Up @@ -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=[
Expand Down Expand Up @@ -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
Expand Down
23 changes: 4 additions & 19 deletions lib/ansible/modules/network/aci/mso_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@
- 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.
Expand Down Expand Up @@ -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'),
Expand All @@ -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
Expand Down
27 changes: 6 additions & 21 deletions lib/ansible/modules/network/aci/mso_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,9 @@
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 ]
Expand All @@ -63,7 +58,7 @@
type: float
longitude:
description:
- The longititude of the location of the site.
- The longitude of the location of the site.
type: float
urls:
description:
Expand Down Expand Up @@ -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'),
)
Expand All @@ -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']
Expand All @@ -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
Expand Down
26 changes: 5 additions & 21 deletions lib/ansible/modules/network/aci/mso_tenant.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,9 @@
- 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 ]
Expand Down Expand Up @@ -68,7 +63,6 @@
username: admin
password: SomeSecretPassword
tenant: north_europe
tenant_id: 101
display_name: North European Datacenter
description: This tenant manages the NEDC environment.
state: present
Expand Down Expand Up @@ -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']),
Expand All @@ -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)
Expand All @@ -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
Expand Down
25 changes: 5 additions & 20 deletions lib/ansible/modules/network/aci/mso_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,9 @@
- 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 ]
Expand Down Expand Up @@ -146,7 +141,6 @@
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'),
Expand All @@ -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']
Expand All @@ -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
Expand Down