Debian Codegraph @

ansible_collections/cisco/aci/plugins/modules/aci_switch_policy_leaf_profile.py

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