ansible  2.9.27
About: Ansible is an IT Configuration Management, Deployment \
About: Ansible (2.x) is an IT Configuration Management, Deployment & Orchestration tool.
ansible download page.
  Fossies Dox: ansible-2.9.27.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

aci_switch_policy_leaf_profile.py
Go to the documentation of this file.
1#!/usr/bin/python
2# -*- coding: utf-8 -*-
3
4# Copyright: (c) 2017, Bruno Calogero <brunocalogero@hotmail.com>
5# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7from __future__ import absolute_import, division, print_function
8__metaclass__ = type
9
10ANSIBLE_METADATA = {'metadata_version': '1.1',
11 'status': ['preview'],
12 'supported_by': 'certified'}
13
14DOCUMENTATION = r'''
15---
16module: aci_switch_policy_leaf_profile
17short_description: Manage switch policy leaf profiles (infra:NodeP)
18description:
19- Manage switch policy leaf profiles on Cisco ACI fabrics.
20version_added: '2.5'
21options:
22 leaf_profile:
23 description:
24 - The name of the Leaf Profile.
25 type: str
26 aliases: [ leaf_profile_name, name ]
27 description:
28 description:
29 - Description for the Leaf Profile.
30 type: str
31 aliases: [ descr ]
32 state:
33 description:
34 - Use C(present) or C(absent) for adding or removing.
35 - Use C(query) for listing an object or multiple objects.
36 type: str
37 choices: [ absent, present, query ]
38 default: present
39extends_documentation_fragment: aci
40seealso:
41- module: aci_switch_policy_leaf_profile
42- name: APIC Management Information Model reference
43 description: More information about the internal APIC class B(infra:NodeP).
44 link: https://developer.cisco.com/docs/apic-mim-ref/
45author:
46- Bruno Calogero (@brunocalogero)
47'''
48
49EXAMPLES = r'''
50- name: creating a Leaf Profile with description
51 aci_switch_policy_leaf_profile:
52 host: apic
53 username: admin
54 password: SomeSecretPassword
55 leaf_profile: sw_name
56 description: sw_description
57 state: present
58 delegate_to: localhost
59
60- name: Deleting a Leaf Profile
61 aci_switch_policy_leaf_profile:
62 host: apic
63 username: admin
64 password: SomeSecretPassword
65 leaf_profile: sw_name
66 state: absent
67 delegate_to: localhost
68
69- name: Query a Leaf Profile
70 aci_switch_policy_leaf_profile:
71 host: apic
72 username: admin
73 password: SomeSecretPassword
74 leaf_profile: sw_name
75 state: query
76 delegate_to: localhost
77 register: query_result
78'''
79
80RETURN = r'''
81current:
82 description: The existing configuration from the APIC after the module has finished
83 returned: success
84 type: list
85 sample:
86 [
87 {
88 "fvTenant": {
89 "attributes": {
90 "descr": "Production environment",
91 "dn": "uni/tn-production",
92 "name": "production",
93 "nameAlias": "",
94 "ownerKey": "",
95 "ownerTag": ""
96 }
97 }
98 }
99 ]
100error:
101 description: The error information as returned from the APIC
102 returned: failure
103 type: dict
104 sample:
105 {
106 "code": "122",
107 "text": "unknown managed object class foo"
108 }
109raw:
110 description: The raw output returned by the APIC REST API (xml or json)
111 returned: parse error
112 type: str
113 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
114sent:
115 description: The actual/minimal configuration pushed to the APIC
116 returned: info
117 type: list
118 sample:
119 {
120 "fvTenant": {
121 "attributes": {
122 "descr": "Production environment"
123 }
124 }
125 }
126previous:
127 description: The original configuration from the APIC before the module has started
128 returned: info
129 type: list
130 sample:
131 [
132 {
133 "fvTenant": {
134 "attributes": {
135 "descr": "Production",
136 "dn": "uni/tn-production",
137 "name": "production",
138 "nameAlias": "",
139 "ownerKey": "",
140 "ownerTag": ""
141 }
142 }
143 }
144 ]
145proposed:
146 description: The assembled configuration from the user-provided parameters
147 returned: info
148 type: dict
149 sample:
150 {
151 "fvTenant": {
152 "attributes": {
153 "descr": "Production environment",
154 "name": "production"
155 }
156 }
157 }
158filter_string:
159 description: The filter string used for the request
160 returned: failure or debug
161 type: str
162 sample: ?rsp-prop-include=config-only
163method:
164 description: The HTTP method used for the request to the APIC
165 returned: failure or debug
166 type: str
167 sample: POST
168response:
169 description: The HTTP response from the APIC
170 returned: failure or debug
171 type: str
172 sample: OK (30 bytes)
173status:
174 description: The HTTP status from the APIC
175 returned: failure or debug
176 type: int
177 sample: 200
178url:
179 description: The HTTP url used for the request to the APIC
180 returned: failure or debug
181 type: str
182 sample: https://10.11.12.13/api/mo/uni/tn-production.json
183'''
184
185from ansible.module_utils.basic import AnsibleModule
186from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec
187
188
189def main():
190 argument_spec = aci_argument_spec()
191 argument_spec.update(
192 leaf_profile=dict(type='str', aliases=['name', 'leaf_profile_name']), # Not required for querying all objects
193 description=dict(type='str', aliases=['descr']),
194 state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
195 )
196
197 module = AnsibleModule(
198 argument_spec=argument_spec,
199 supports_check_mode=True,
200 required_if=[
201 ['state', 'absent', ['leaf_profile']],
202 ['state', 'present', ['leaf_profile']],
203 ],
204 )
205
206 leaf_profile = module.params['leaf_profile']
207 description = module.params['description']
208 state = module.params['state']
209
210 aci = ACIModule(module)
211 aci.construct_url(
212 root_class=dict(
213 aci_class='infraNodeP',
214 aci_rn='infra/nprof-{0}'.format(leaf_profile),
215 module_object=leaf_profile,
216 target_filter={'name': leaf_profile},
217 ),
218 )
219
220 aci.get_existing()
221
222 if state == 'present':
223 aci.payload(
224 aci_class='infraNodeP',
225 class_config=dict(
226 name=leaf_profile,
227 descr=description,
228 ),
229 )
230
231 aci.get_diff(aci_class='infraNodeP')
232
233 aci.post_config()
234
235 elif state == 'absent':
236 aci.delete_config()
237
238 aci.exit_json()
239
240
241if __name__ == "__main__":
242 main()