Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2023, Gaspard Micol (@gmicol) <[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_interface_policy_fc
16 short_description: Manage Fibre Channel interface policies (fc:IfPol)
17 description:
18 - Manage ACI Fiber Channel interface policies on Cisco ACI fabrics.
19 options:
20 fc_policy:
21 description:
22 - The name of the Fiber Channel interface policy.
23 type: str
24 aliases: [ name ]
25 description:
26 description:
27 - The description of the Fiber Channel interface policy.
28 type: str
29 aliases: [ descr ]
30 port_mode:
31 description:
32 - The Port Mode to use.
33 - The APIC defaults to C(f) when unset during creation.
34 type: str
35 choices: [ f, np ]
36 auto_max_speed:
37 description:
38 - The maximum automatic CPU or port speed.
39 - The APIC defaults to C(32G) when unset during creation.
40 type: str
41 choices: [ 2G, 4G, 8G, 16G, 32G ]
42 fill_pattern:
43 description:
44 - Fill Pattern for native FC ports.
45 - The APIC defaults to C(IDLE) when unset during creation.
46 type: str
47 choices: [ arbff, idle ]
48 buffer_credits:
49 description:
50 - Receive buffer credits for native FC ports.
51 - The APIC defaults to C(64) when unset during creation.
52 type: int
53 speed:
54 description:
55 - The CPU or port speed.
56 - The APIC defaults to C(auto) when unset during creation.
57 type: str
58 choices: [ auto, unknown, 2G, 4G, 8G, 16G, 32G ]
59 trunk_mode:
60 description:
61 - Trunking on/off for native FC ports.
62 - The APIC defaults to C(trunk-off) when unset during creation.
63 type: str
64 choices: [ auto, trunk-off, trunk-on, un-init ]
65 state:
66 description:
67 - Use C(present) or C(absent) for adding or removing.
68 - Use C(query) for listing an object or multiple objects.
69 type: str
70 choices: [ absent, present, query ]
71 default: present
72 name_alias:
73 description:
74 - The alias for the current object. This relates to the nameAlias field in ACI.
75 type: str
76 extends_documentation_fragment:
77 - cisco.aci.aci
78 - cisco.aci.annotation
79 - cisco.aci.owner
80
81 seealso:
82 - name: APIC Management Information Model reference
83 description: More information about the internal APIC class B(fc:IfPol).
84 link: https://developer.cisco.com/docs/apic-mim-ref/
85 author:
86 - Dag Wieers (@dagwieers)
87 - Gaspard Micol (@gmicol)
88 """
89
90 EXAMPLES = r"""
91 - name: Create a Fibre Channel interface policy
92 cisco.aci.aci_interface_policy_fc:
93 host: apic
94 username: admin
95 password: SomeSecretPassword
96 fc_policy: fcpolicy1
97 state: present
98 delegate_to: localhost
99
100 - name: Delete a Fibre Channel interface policy
101 cisco.aci.aci_interface_policy_fc:
102 host: apic
103 username: admin
104 password: SomeSecretPassword
105 fc_policy: fcpolicy1
106 state: absent
107 delegate_to: localhost
108
109 - name: Query all Fibre Channel interface policies
110 cisco.aci.aci_interface_policy_fc:
111 host: apic
112 username: admin
113 password: SomeSecretPassword
114 state: query
115 delegate_to: localhost
116 register: query_result
117
118 - name: Query a specific Fibre Channel interface policy
119 cisco.aci.aci_interface_policy_fc:
120 host: apic
121 username: admin
122 password: SomeSecretPassword
123 fc_policy: fcpolicy1
124 state: query
125 delegate_to: localhost
126 register: query_result
127 """
128
129 RETURN = r"""
130 current:
131 description: The existing configuration from the APIC after the module has finished
132 returned: success
133 type: list
134 sample:
135 [
136 {
137 "fvTenant": {
138 "attributes": {
139 "descr": "Production environment",
140 "dn": "uni/tn-production",
141 "name": "production",
142 "nameAlias": "",
143 "ownerKey": "",
144 "ownerTag": ""
145 }
146 }
147 }
148 ]
149 error:
150 description: The error information as returned from the APIC
151 returned: failure
152 type: dict
153 sample:
154 {
155 "code": "122",
156 "text": "unknown managed object class foo"
157 }
158 raw:
159 description: The raw output returned by the APIC REST API (xml or json)
160 returned: parse error
161 type: str
162 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
163 sent:
164 description: The actual/minimal configuration pushed to the APIC
165 returned: info
166 type: list
167 sample:
168 {
169 "fvTenant": {
170 "attributes": {
171 "descr": "Production environment"
172 }
173 }
174 }
175 previous:
176 description: The original configuration from the APIC before the module has started
177 returned: info
178 type: list
179 sample:
180 [
181 {
182 "fvTenant": {
183 "attributes": {
184 "descr": "Production",
185 "dn": "uni/tn-production",
186 "name": "production",
187 "nameAlias": "",
188 "ownerKey": "",
189 "ownerTag": ""
190 }
191 }
192 }
193 ]
194 proposed:
195 description: The assembled configuration from the user-provided parameters
196 returned: info
197 type: dict
198 sample:
199 {
200 "fvTenant": {
201 "attributes": {
202 "descr": "Production environment",
203 "name": "production"
204 }
205 }
206 }
207 filter_string:
208 description: The filter string used for the request
209 returned: failure or debug
210 type: str
211 sample: ?rsp-prop-include=config-only
212 method:
213 description: The HTTP method used for the request to the APIC
214 returned: failure or debug
215 type: str
216 sample: POST
217 response:
218 description: The HTTP response from the APIC
219 returned: failure or debug
220 type: str
221 sample: OK (30 bytes)
222 status:
223 description: The HTTP status from the APIC
224 returned: failure or debug
225 type: int
226 sample: 200
227 url:
228 description: The HTTP url used for the request to the APIC
229 returned: failure or debug
230 type: str
231 sample: https://10.11.12.13/api/mo/uni/tn-production.json
232 """
233
234 from ansible.module_utils.basic import AnsibleModule
235 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec
236 from ansible_collections.cisco.aci.plugins.module_utils.constants import MATCH_FC_FILL_PATTERN_MAPPING, INTERFACE_POLICY_FC_SPEED_LIST
237
238
239 def main():
240 argument_spec = aci_argument_spec()
241 argument_spec.update(aci_annotation_spec())
242 argument_spec.update(aci_owner_spec())
243 argument_spec.update(
244 fc_policy=dict(type="str", aliases=["name"]), # Not required for querying all objects
245 description=dict(type="str", aliases=["descr"]),
246 port_mode=dict(type="str", choices=["f", "np"]), # No default provided on purpose
247 auto_max_speed=dict(type="str", choices=INTERFACE_POLICY_FC_SPEED_LIST[2:]),
248 fill_pattern=dict(type="str", choices=list(MATCH_FC_FILL_PATTERN_MAPPING.keys())),
249 buffer_credits=dict(type="int"),
250 speed=dict(type="str", choices=INTERFACE_POLICY_FC_SPEED_LIST),
251 trunk_mode=dict(type="str", choices=["auto", "trunk-off", "trunk-on", "un-init"]),
252 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
253 name_alias=dict(type="str"),
254 )
255
256 module = AnsibleModule(
257 argument_spec=argument_spec,
258 supports_check_mode=True,
259 required_if=[
260 ["state", "absent", ["fc_policy"]],
261 ["state", "present", ["fc_policy"]],
262 ],
263 )
264
265 fc_policy = module.params.get("fc_policy")
266 port_mode = module.params.get("port_mode")
267 auto_max_speed = module.params.get("auto_max_speed")
268 fill_pattern = MATCH_FC_FILL_PATTERN_MAPPING.get(module.params.get("fill_pattern"))
269 buffer_credits = module.params.get("buffer_credits")
270 speed = module.params.get("speed")
271 trunk_mode = module.params.get("trunk_mode")
272 description = module.params.get("description")
273 state = module.params.get("state")
274 name_alias = module.params.get("name_alias")
275
276 aci = ACIModule(module)
277 aci.construct_url(
278 root_class=dict(
279 aci_class="fcIfPol",
280 aci_rn="infra/fcIfPol-{0}".format(fc_policy),
281 module_object=fc_policy,
282 target_filter={"name": fc_policy},
283 ),
284 )
285
286 aci.get_existing()
287
288 if state == "present":
289 aci.payload(
290 aci_class="fcIfPol",
291 class_config=dict(
292 name=fc_policy,
293 descr=description,
294 portMode=port_mode,
295 automaxspeed=auto_max_speed,
296 fillPattern=fill_pattern,
297 rxBBCredit=buffer_credits,
298 speed=speed,
299 trunkMode=trunk_mode,
300 nameAlias=name_alias,
301 ),
302 )
303
304 aci.get_diff(aci_class="fcIfPol")
305
306 aci.post_config()
307
308 elif state == "absent":
309 aci.delete_config()
310
311 aci.exit_json()
312
313
314 if __name__ == "__main__":
315 main()