aci_interface_policy_leaf_profile module (#34364)

* added aci_switch_leaf_policy_profile module WIP

* fixed pep8 errors for PR

* fixed unwanted modifications and fixed pep8 errors

* fixed suggested errors for PR

* adding WIP aci_switch_leaf_selector module

* fixed for pull request

* fixing pep8 errors, bad indents

* improved initial description

* fixed pep8 doc errors

* updated module to include infra:NodeBlk and infra:RsAccNodePGrp instead of having seperate modules for the latter

* fixing pep8

* adding 'name' alias to leaf_selector

* updating example

* updating aliases, forgot 'name' again

* adding aci_interface_policy_leaf_profile module

* removing unwanted module.. man I always make this mistake

* added examples

* Fix pylint errors
This commit is contained in:
Bruno 2018-01-12 02:57:44 -08:00 committed by Dag Wieers
parent d7d13b48e5
commit 007c19095d

View file

@ -0,0 +1,140 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright: (c) 2017, Bruno Calogero <brunocalogero@hotmail.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = r'''
---
module: aci_interface_policy_leaf_profile
short_description: Manage Fabric interface policy leaf profiles on Cisco ACI fabrics (infra:AccPortP)
description:
- Manage Fabric interface policy leaf profiles on Cisco ACI fabrics.
- More information from the internal APIC class
I(infra:AccPortP) at U(https://developer.cisco.com/media/mim-ref).
author:
- Bruno Calogero (@brunocalogero)
version_added: '2.5'
options:
leaf_interface_profile:
description:
- The name of the Fabric access policy leaf interface profile.
required: yes
aliases: [ name, leaf_interface_profile_name ]
description:
description:
- Description for the Fabric access policy leaf interface profile.
aliases: [ descr ]
state:
description:
- Use C(present) or C(absent) for adding or removing.
- Use C(query) for listing an object or multiple objects.
choices: [ absent, present, query ]
default: present
'''
EXAMPLES = r'''
- name: Add a new leaf_interface_profile
aci_interface_policy_leaf_profile:
hostname: apic
username: admin
password: SomeSecretPassword
leaf_interface_profile: leafintprfname
description: leafintprfname description
state: present
- name: Remove a leaf_interface_profile
aci_interface_policy_leaf_profile:
hostname: apic
username: admin
password: SomeSecretPassword
leaf_interface_profile: leafintprfname
state: absent
- name: Remove all leaf_interface_profiles
aci_interface_policy_leaf_profile:
hostname: apic
username: admin
password: SomeSecretPassword
state: absent
- name: Query a leaf_interface_profile
aci_interface_policy_leaf_profile:
hostname: apic
username: admin
password: SomeSecretPassword
leaf_interface_profile: leafintprfname
state: query
'''
RETURN = r'''
#
'''
from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec
from ansible.module_utils.basic import AnsibleModule
def main():
argument_spec = aci_argument_spec
argument_spec.update(
leaf_interface_profile=dict(type='str', aliases=['name', 'leaf_interface_profile_name']), # Not required for querying all objects
description=dict(type='str', aliases=['descr']),
state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
)
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
required_if=[
['state', 'absent', ['leaf_interface_profile']],
['state', 'present', ['leaf_interface_profile']],
],
)
leaf_interface_profile = module.params['leaf_interface_profile']
description = module.params['description']
state = module.params['state']
aci = ACIModule(module)
aci.construct_url(
root_class=dict(
aci_class='infraAccPortP',
aci_rn='infra/accportprof-{0}'.format(leaf_interface_profile),
filter_target='eq(infraAccPortP.name, "{0}")'.format(leaf_interface_profile),
module_object=leaf_interface_profile
),
)
aci.get_existing()
if state == 'present':
# Filter out module parameters with null values
aci.payload(
aci_class='infraAccPortP',
class_config=dict(
name=leaf_interface_profile,
descr=description,
),
)
# Generate config diff which will be used as POST request body
aci.get_diff(aci_class='infraAccPortP')
# Submit changes if module not in check_mode and the proposed is different than existing
aci.post_config()
elif state == 'absent':
aci.delete_config()
module.exit_json(**aci.result)
if __name__ == "__main__":
main()