Debian Codegraph @

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

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