Debian Codegraph @

ansible_collections/cisco/aci/plugins/modules/aci_access_spine_interface_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_interface_profile
21 short_description: Manage fabric interface policy spine profiles (infra:SpAccPortP)
22 description:
23 - Manage fabric interface policy spine profiles on Cisco ACI fabrics.
24 options:
25 interface_profile:
26 description:
27 - The name of the Fabric access policy spine interface profile.
28 type: str
29 aliases: [ name, spine_interface_profile_name, spine_interface_profile, interface_profile_name ]
30 description:
31 description:
32 - The description for the Fabric access policy spine interface 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:SpAccPortP).
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 spine_interface_profile
62 cisco.aci.aci_access_spine_interface_profile:
63 host: apic
64 username: admin
65 password: SomeSecretPassword
66 interface_profile: spineintprfname
67 description: spineintprfname description
68 state: present
69 delegate_to: localhost
70
71 - name: Query a spine_interface_profile
72 cisco.aci.aci_access_spine_interface_profile:
73 host: apic
74 username: admin
75 password: SomeSecretPassword
76 interface_profile: spineintprfname
77 state: query
78 delegate_to: localhost
79 register: query_result
80
81 - name: Query all spine_interface_profiles
82 cisco.aci.aci_access_spine_interface_profile:
83 host: apic
84 username: admin
85 password: SomeSecretPassword
86 state: query
87 delegate_to: localhost
88
89 - name: Remove a spine_interface_profile
90 cisco.aci.aci_access_spine_interface_profile:
91 host: apic
92 username: admin
93 password: SomeSecretPassword
94 interface_profile: spineintprfname
95 state: absent
96 delegate_to: localhost
97 """
98
99 RETURN = r"""
100 current:
101 description: The existing configuration from the APIC after the module has finished
102 returned: success
103 type: list
104 sample:
105 [
106 {
107 "fvTenant": {
108 "attributes": {
109 "descr": "Production environment",
110 "dn": "uni/tn-production",
111 "name": "production",
112 "nameAlias": "",
113 "ownerKey": "",
114 "ownerTag": ""
115 }
116 }
117 }
118 ]
119 error:
120 description: The error information as returned from the APIC
121 returned: failure
122 type: dict
123 sample:
124 {
125 "code": "122",
126 "text": "unknown managed object class foo"
127 }
128 raw:
129 description: The raw output returned by the APIC REST API (xml or json)
130 returned: parse error
131 type: str
132 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
133 sent:
134 description: The actual/minimal configuration pushed to the APIC
135 returned: info
136 type: list
137 sample:
138 {
139 "fvTenant": {
140 "attributes": {
141 "descr": "Production environment"
142 }
143 }
144 }
145 previous:
146 description: The original configuration from the APIC before the module has started
147 returned: info
148 type: list
149 sample:
150 [
151 {
152 "fvTenant": {
153 "attributes": {
154 "descr": "Production",
155 "dn": "uni/tn-production",
156 "name": "production",
157 "nameAlias": "",
158 "ownerKey": "",
159 "ownerTag": ""
160 }
161 }
162 }
163 ]
164 proposed:
165 description: The assembled configuration from the user-provided parameters
166 returned: info
167 type: dict
168 sample:
169 {
170 "fvTenant": {
171 "attributes": {
172 "descr": "Production environment",
173 "name": "production"
174 }
175 }
176 }
177 filter_string:
178 description: The filter string used for the request
179 returned: failure or debug
180 type: str
181 sample: ?rsp-prop-include=config-only
182 method:
183 description: The HTTP method used for the request to the APIC
184 returned: failure or debug
185 type: str
186 sample: POST
187 response:
188 description: The HTTP response from the APIC
189 returned: failure or debug
190 type: str
191 sample: OK (30 bytes)
192 status:
193 description: The HTTP status from the APIC
194 returned: failure or debug
195 type: int
196 sample: 200
197 url:
198 description: The HTTP url used for the request to the APIC
199 returned: failure or debug
200 type: str
201 sample: https://10.11.12.13/api/mo/uni/tn-production.json
202 """
203
204 from ansible.module_utils.basic import AnsibleModule
205 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec
206
207
208 def main():
209 argument_spec = aci_argument_spec()
210 argument_spec.update(aci_annotation_spec())
211 argument_spec.update(aci_owner_spec())
212 argument_spec.update(
213 interface_profile=dict(
214 type="str",
215 aliases=[
216 "name",
217 "spine_interface_profile_name",
218 "spine_interface_profile",
219 "interface_profile_name",
220 ],
221 ),
222 description=dict(type="str", aliases=["descr"]),
223 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
224 name_alias=dict(type="str"),
225 )
226
227 module = AnsibleModule(
228 argument_spec=argument_spec,
229 supports_check_mode=True,
230 required_if=[
231 ["state", "absent", ["interface_profile"]],
232 ["state", "present", ["interface_profile"]],
233 ],
234 )
235
236 interface_profile = module.params.get("interface_profile")
237 description = module.params.get("description")
238 state = module.params.get("state")
239 name_alias = module.params.get("name_alias")
240
241 aci = ACIModule(module)
242
243 aci.construct_url(
244 root_class=dict(
245 aci_class="infraInfra",
246 aci_rn="infra",
247 ),
248 subclass_1=dict(
249 aci_class="infraSpAccPortP",
250 aci_rn="spaccportprof-{0}".format(interface_profile),
251 module_object=interface_profile,
252 target_filter={"name": interface_profile},
253 ),
254 )
255
256 aci.get_existing()
257
258 if state == "present":
259 aci.payload(
260 aci_class="infraSpAccPortP",
261 class_config=dict(
262 name=interface_profile,
263 descr=description,
264 nameAlias=name_alias,
265 ),
266 )
267
268 aci.get_diff(aci_class="infraSpAccPortP")
269
270 aci.post_config()
271
272 elif state == "absent":
273 aci.delete_config()
274
275 aci.exit_json()
276
277
278 if __name__ == "__main__":
279 main()