MSO: Remove parameters to specify object ids (#55107)

MSO: Remove parameters to specify object ids
pull/55115/head
Dag Wieers 6 years ago committed by GitHub
parent bea397b458
commit 9ac57dff61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -21,14 +21,9 @@ author:
- Dag Wieers (@dagwieers) - Dag Wieers (@dagwieers)
version_added: '2.8' version_added: '2.8'
options: options:
label_id:
description:
- The ID of the label.
type: str
label: label:
description: description:
- The name of the label. - The name of the label.
- Alternative to the name, you can use C(label_id).
type: str type: str
required: yes required: yes
aliases: [ name ] aliases: [ name ]
@ -99,7 +94,6 @@ def main():
argument_spec = mso_argument_spec() argument_spec = mso_argument_spec()
argument_spec.update( argument_spec.update(
label=dict(type='str', aliases=['name']), label=dict(type='str', aliases=['name']),
label_id=dict(type='str'),
type=dict(type='str', default='site', choices=['site']), type=dict(type='str', default='site', choices=['site']),
state=dict(type='str', default='present', choices=['absent', 'present', 'query']), state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
) )
@ -114,32 +108,23 @@ def main():
) )
label = module.params['label'] label = module.params['label']
label_id = module.params['label_id']
label_type = module.params['type'] label_type = module.params['type']
state = module.params['state'] state = module.params['state']
mso = MSOModule(module) mso = MSOModule(module)
label_id = None
path = 'labels' path = 'labels'
# Query for existing object(s) # Query for existing object(s)
if label_id is None and label is None: if label:
mso.existing = mso.query_objs(path)
elif label_id is None:
mso.existing = mso.get_obj(path, displayName=label) mso.existing = mso.get_obj(path, displayName=label)
if mso.existing: if mso.existing:
label_id = mso.existing['id'] label_id = mso.existing['id']
elif label is None: # If we found an existing object, continue with it
mso.existing = mso.get_obj(path, id=label_id) path = 'labels/{id}'.format(id=label_id)
else: else:
mso.existing = mso.get_obj(path, id=label_id) mso.existing = mso.query_objs(path)
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)
if state == 'query': if state == 'query':
pass pass

@ -21,14 +21,9 @@ author:
- Dag Wieers (@dagwieers) - Dag Wieers (@dagwieers)
version_added: '2.8' version_added: '2.8'
options: options:
role_id:
description:
- The ID of the role.
type: str
role: role:
description: description:
- The name of the role. - The name of the role.
- Alternative to the name, you can use C(role_id).
type: str type: str
required: yes required: yes
aliases: [ name ] aliases: [ name ]
@ -132,7 +127,6 @@ def main():
argument_spec = mso_argument_spec() argument_spec = mso_argument_spec()
argument_spec.update( argument_spec.update(
role=dict(type='str', aliases=['name']), role=dict(type='str', aliases=['name']),
role_id=dict(type='str'),
display_name=dict(type='str'), display_name=dict(type='str'),
description=dict(type='str'), description=dict(type='str'),
permissions=dict(type='list', choices=[ permissions=dict(type='list', choices=[
@ -168,33 +162,24 @@ def main():
) )
role = module.params['role'] role = module.params['role']
role_id = module.params['role_id']
description = module.params['description'] description = module.params['description']
permissions = module.params['permissions'] permissions = module.params['permissions']
state = module.params['state'] state = module.params['state']
mso = MSOModule(module) mso = MSOModule(module)
role_id = None
path = 'roles' path = 'roles'
# Query for existing object(s) # Query for existing object(s)
if role_id is None and role is None: if role:
mso.existing = mso.query_objs(path)
elif role_id is None:
mso.existing = mso.get_obj(path, name=role) mso.existing = mso.get_obj(path, name=role)
if mso.existing: if mso.existing:
role_id = mso.existing['id'] role_id = mso.existing['id']
elif role is None: # If we found an existing object, continue with it
mso.existing = mso.get_obj(path, id=role_id) path = 'roles/{id}'.format(id=role_id)
else: else:
mso.existing = mso.get_obj(path, id=role_id) mso.existing = mso.query_objs(path)
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)
if state == 'query': if state == 'query':
pass pass

@ -21,11 +21,6 @@ author:
- Dag Wieers (@dagwieers) - Dag Wieers (@dagwieers)
version_added: '2.8' version_added: '2.8'
options: options:
schema_id:
description:
- The ID of the schema.
type: str
required: yes
schema: schema:
description: description:
- The name of the schema. - The name of the schema.
@ -117,7 +112,6 @@ def main():
argument_spec = mso_argument_spec() argument_spec = mso_argument_spec()
argument_spec.update( argument_spec.update(
schema=dict(type='str', aliases=['name']), schema=dict(type='str', aliases=['name']),
schema_id=dict(type='str'),
templates=dict(type='list'), templates=dict(type='list'),
sites=dict(type='list'), sites=dict(type='list'),
# messages=dict(type='dict'), # messages=dict(type='dict'),
@ -138,32 +132,23 @@ def main():
) )
schema = module.params['schema'] schema = module.params['schema']
schema_id = module.params['schema_id']
templates = module.params['templates'] templates = module.params['templates']
sites = module.params['sites'] sites = module.params['sites']
state = module.params['state'] state = module.params['state']
mso = MSOModule(module) mso = MSOModule(module)
schema_id = None
path = 'schemas' path = 'schemas'
# Query for existing object(s) # Query for existing object(s)
if schema_id is None and schema is None: if schema:
mso.existing = mso.query_objs(path)
elif schema_id is None:
mso.existing = mso.get_obj(path, displayName=schema) mso.existing = mso.get_obj(path, displayName=schema)
if mso.existing: if mso.existing:
schema_id = mso.existing['id'] schema_id = mso.existing['id']
elif schema is None: path = 'schemas/{id}'.format(id=schema_id)
mso.existing = mso.get_obj(path, id=schema_id)
else: else:
mso.existing = mso.get_obj(path, id=schema_id) mso.existing = mso.query_objs(path)
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)
if state == 'query': if state == 'query':
pass pass

@ -37,14 +37,9 @@ options:
type: str type: str
required: yes required: yes
default: admin default: admin
site_id:
description:
- The ID of the site.
type: str
site: site:
description: description:
- The name of the site. - The name of the site.
- Alternative to the name, you can use C(site_id).
type: str type: str
required: yes required: yes
aliases: [ name ] aliases: [ name ]
@ -63,7 +58,7 @@ options:
type: float type: float
longitude: longitude:
description: description:
- The longititude of the location of the site. - The longitude of the location of the site.
type: float type: float
urls: urls:
description: description:
@ -154,7 +149,6 @@ def main():
labels=dict(type='list'), labels=dict(type='list'),
location=dict(type='dict', options=location_arg_spec), location=dict(type='dict', options=location_arg_spec),
site=dict(type='str', aliases=['name']), site=dict(type='str', aliases=['name']),
site_id=dict(type='str'),
state=dict(type='str', default='present', choices=['absent', 'present', 'query']), state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
urls=dict(type='list'), urls=dict(type='list'),
) )
@ -172,7 +166,6 @@ def main():
apic_password = module.params['apic_password'] apic_password = module.params['apic_password']
apic_site_id = module.params['apic_site_id'] apic_site_id = module.params['apic_site_id']
site = module.params['site'] site = module.params['site']
site_id = module.params['site_id']
location = module.params['location'] location = module.params['location']
if location is not None: if location is not None:
latitude = module.params['location']['latitude'] latitude = module.params['location']['latitude']
@ -182,29 +175,21 @@ def main():
mso = MSOModule(module) mso = MSOModule(module)
site_id = None
path = 'sites' path = 'sites'
# Convert labels # Convert labels
labels = mso.lookup_labels(module.params['labels'], 'site') labels = mso.lookup_labels(module.params['labels'], 'site')
# Query for mso.existing object(s) # Query for mso.existing object(s)
if site_id is None and site is None: if site:
mso.existing = mso.query_objs(path)
elif site_id is None:
mso.existing = mso.get_obj(path, name=site) mso.existing = mso.get_obj(path, name=site)
if mso.existing: if mso.existing:
site_id = mso.existing['id'] site_id = mso.existing['id']
elif site is None: # If we found an existing object, continue with it
mso.existing = mso.get_obj(path, id=site_id) path = 'sites/{id}'.format(id=site_id)
else: else:
mso.existing = mso.get_obj(path, id=site_id) mso.existing = mso.query_objs(path)
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)
if state == 'query': if state == 'query':
pass pass

@ -21,14 +21,9 @@ author:
- Dag Wieers (@dagwieers) - Dag Wieers (@dagwieers)
version_added: '2.8' version_added: '2.8'
options: options:
tenant_id:
description:
- The ID of the tenant.
type: str
tenant: tenant:
description: description:
- The name of the tenant. - The name of the tenant.
- Alternative to the name, you can use C(tenant_id).
type: str type: str
required: yes required: yes
aliases: [ name ] aliases: [ name ]
@ -68,7 +63,6 @@ EXAMPLES = r'''
username: admin username: admin
password: SomeSecretPassword password: SomeSecretPassword
tenant: north_europe tenant: north_europe
tenant_id: 101
display_name: North European Datacenter display_name: North European Datacenter
description: This tenant manages the NEDC environment. description: This tenant manages the NEDC environment.
state: present state: present
@ -116,7 +110,6 @@ def main():
description=dict(type='str'), description=dict(type='str'),
display_name=dict(type='str'), display_name=dict(type='str'),
tenant=dict(type='str', aliases=['name']), tenant=dict(type='str', aliases=['name']),
tenant_id=dict(type='str'),
users=dict(type='list'), users=dict(type='list'),
sites=dict(type='list'), sites=dict(type='list'),
state=dict(type='str', default='present', choices=['absent', 'present', 'query']), state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
@ -134,7 +127,6 @@ def main():
description = module.params['description'] description = module.params['description']
display_name = module.params['display_name'] display_name = module.params['display_name']
tenant = module.params['tenant'] tenant = module.params['tenant']
tenant_id = module.params['tenant_id']
state = module.params['state'] state = module.params['state']
mso = MSOModule(module) mso = MSOModule(module)
@ -143,26 +135,18 @@ def main():
sites = mso.lookup_sites(module.params['sites']) sites = mso.lookup_sites(module.params['sites'])
users = mso.lookup_users(module.params['users']) users = mso.lookup_users(module.params['users'])
tenant_id = None
path = 'tenants' path = 'tenants'
# Query for existing object(s) # Query for existing object(s)
if tenant_id is None and tenant is None: if tenant:
mso.existing = mso.query_objs(path)
elif tenant_id is None:
mso.existing = mso.get_obj(path, name=tenant) mso.existing = mso.get_obj(path, name=tenant)
if mso.existing: if mso.existing:
tenant_id = mso.existing['id'] tenant_id = mso.existing['id']
elif tenant is None: # If we found an existing object, continue with it
mso.existing = mso.get_obj(path, id=tenant_id) path = 'tenants/{id}'.format(id=tenant_id)
else: else:
mso.existing = mso.get_obj(path, id=tenant_id) mso.existing = mso.query_objs(path)
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)
if state == 'query': if state == 'query':
pass pass

@ -21,14 +21,9 @@ author:
- Dag Wieers (@dagwieers) - Dag Wieers (@dagwieers)
version_added: '2.8' version_added: '2.8'
options: options:
user_id:
description:
- The ID of the user.
type: str
user: user:
description: description:
- The name of the user. - The name of the user.
- Alternative to the name, you can use C(user_id).
type: str type: str
required: yes required: yes
aliases: [ name ] aliases: [ name ]
@ -146,7 +141,6 @@ from ansible.module_utils.network.aci.mso import MSOModule, mso_argument_spec, i
def main(): def main():
argument_spec = mso_argument_spec() argument_spec = mso_argument_spec()
argument_spec.update( argument_spec.update(
user_id=dict(type='str'),
user=dict(type='str', aliases=['name']), user=dict(type='str', aliases=['name']),
user_password=dict(type='str', no_log=True), user_password=dict(type='str', no_log=True),
first_name=dict(type='str'), first_name=dict(type='str'),
@ -169,7 +163,6 @@ def main():
], ],
) )
user_id = module.params['user_id']
user_name = module.params['user'] user_name = module.params['user']
user_password = module.params['user_password'] user_password = module.params['user_password']
first_name = module.params['first_name'] first_name = module.params['first_name']
@ -184,26 +177,18 @@ def main():
roles = mso.lookup_roles(module.params['roles']) roles = mso.lookup_roles(module.params['roles'])
domain = mso.lookup_domain(module.params['domain']) domain = mso.lookup_domain(module.params['domain'])
user_id = None
path = 'users' path = 'users'
# Query for existing object(s) # Query for existing object(s)
if user_id is None and user_name is None: if user_name:
mso.existing = mso.query_objs(path)
elif user_id is None:
mso.existing = mso.get_obj(path, username=user_name) mso.existing = mso.get_obj(path, username=user_name)
if mso.existing: if mso.existing:
user_id = mso.existing['id'] user_id = mso.existing['id']
elif user_name is None: # If we found an existing object, continue with it
mso.existing = mso.get_obj(path, id=user_id) path = 'users/{id}'.format(id=user_id)
else: else:
mso.existing = mso.get_obj(path, id=user_id) mso.existing = mso.query_objs(path)
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)
if state == 'query': if state == 'query':
pass pass

Loading…
Cancel
Save