Debian Codegraph @

ansible_collections/dellemc/openmanage/plugins/modules/ome_smart_fabric_info.py

raw symbols SCIP
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 #
5 # Dell OpenManage Ansible Modules
6 # Version 9.3.0
7 # Copyright (C) 2022-2025 Dell Inc. or its subsidiaries. All Rights Reserved.
8
9 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
10 #
11
12 from __future__ import (absolute_import, division, print_function)
13 __metaclass__ = type
14
15 DOCUMENTATION = r'''
16 ---
17 module: ome_smart_fabric_info
18 short_description: Retrieves the information of smart fabrics inventoried by OpenManage Enterprise Modular
19 version_added: "7.1.0"
20 description:
21 - This module retrieves the list of smart fabrics in the inventory of OpenManage Enterprise Modular.
22 extends_documentation_fragment:
23 - dellemc.openmanage.omem_auth_options
24 options:
25 fabric_id:
26 description:
27 - Unique Id of the fabric.
28 - I(fabric_id) is mutually exclusive with I(fabric_name).
29 type: str
30 fabric_name:
31 description:
32 - Name of the fabric.
33 - I(fabric_name) is mutually exclusive with I(fabric_id).
34 type: str
35 requirements:
36 - "python >= 3.9.6"
37 author:
38 - "Kritika Bhateja(@Kritka-Bhateja)"
39 notes:
40 - Run this module from a system that has direct access to Dell OpenManage Enterprise Modular.
41 - This module supports C(check_mode).
42 '''
43
44 EXAMPLES = """
45 ---
46 - name: Retrieve details of all smart fabrics
47 dellemc.openmanage.ome_smart_fabric_info:
48 hostname: "192.168.0.1"
49 username: "username"
50 password: "password"
51 ca_path: "/path/to/ca_cert.pem"
52
53 - name: Retrieve details of a specific smart fabric identified by its fabric ID
54 dellemc.openmanage.ome_smart_fabric_info:
55 hostname: "192.168.0.1"
56 username: "username"
57 password: "password"
58 ca_path: "/path/to/ca_cert.pem"
59 fabric_id: "61c20a59-9ed5-4ae5-b850-5e5acf42d2f2"
60
61 - name: Retrieve details of a specific smart fabric identified by its fabric name
62 dellemc.openmanage.ome_smart_fabric_info:
63 hostname: "192.168.0.1"
64 username: "username"
65 password: "password"
66 ca_path: "/path/to/ca_cert.pem"
67 fabric_name: "f1"
68 """
69
70 RETURN = '''
71 ---
72 msg:
73 type: str
74 description: Status of smart fabric information retrieval.
75 returned: always
76 sample: "Successfully retrieved the smart fabric information."
77 smart_fabric_info:
78 type: list
79 description: Returns the information about smart fabric.
80 returned: success
81 sample: [
82 {
83 "Description": "Fabric f1",
84 "FabricDesign": [
85 {
86 "Actions": {
87 "#NetworkService.GetApplicableNodes": {
88 "target": "/api/NetworkService/Fabrics('61c20a59-9ed5-4ae5-b850-5e5acf42d2f2')/FabricDesign/NetworkService.GetApplicableNodes"
89 },
90 "Oem": {}
91 },
92 "FabricDesignNode": [
93 {
94 "ChassisName": "Chassis-X",
95 "NodeName": "Switch-B",
96 "Slot": "Slot-A2",
97 "Type": "WeaverSwitch"
98 },
99 {
100 "ChassisName": "Chassis-X",
101 "NodeName": "Switch-A",
102 "Slot": "Slot-A1",
103 "Type": "WeaverSwitch"
104 }
105 ],
106 "Name": "2xMX9116n_Fabric_Switching_Engines_in_same_chassis",
107 "NetworkLink": [
108 {
109 "DestinationInterface": "ethernet1/1/38",
110 "DestinationNode": "Switch-B",
111 "SourceInterface": "ethernet1/1/38",
112 "SourceNode": "Switch-A"
113 },
114 {
115 "DestinationInterface": "ethernet1/1/37",
116 "DestinationNode": "Switch-B",
117 "SourceInterface": "ethernet1/1/37",
118 "SourceNode": "Switch-A"
119 },
120 {
121 "DestinationInterface": "ethernet1/1/39",
122 "DestinationNode": "Switch-B",
123 "SourceInterface": "ethernet1/1/39",
124 "SourceNode": "Switch-A"
125 },
126 {
127 "DestinationInterface": "ethernet1/1/40",
128 "DestinationNode": "Switch-B",
129 "SourceInterface": "ethernet1/1/40",
130 "SourceNode": "Switch-A"
131 }
132 ]
133 }
134 ],
135 "FabricDesignMapping": [
136 {
137 "DesignNode": "Switch-A",
138 "PhysicalNode": "NODEID1"
139 },
140 {
141 "DesignNode": "Switch-B",
142 "PhysicalNode": "NODEID2"
143 }
144 ],
145 "Health": {
146 "Issues": [
147 {
148 "Category": "Audit",
149 "DetailedDescription": "The SmartFabric is not healthy because the interface for an uplink
150 mentioned in the message is not in operational status.",
151 "Message": "The SmartFabric is not healthy because the interface JRWSV43:ethernet1/1/35 for uplink
152 1ad54420-b145-49a1-9779-21a579ef6f2d is not in operational status.",
153 "MessageArgs": [],
154 "MessageId": "NFAB0016",
155 "Resolution": "Make sure that all the uplink interfaces are in operational status.",
156 "Severity": "Warning",
157 "TimeStamp": "2019-09-25T11:50:06Z"
158 },
159 {
160 "Category": "Audit",
161 "DetailedDescription": "The SmartFabric is not healthy because one or more VLTi links are not connected.",
162 "Message": "The SmartFabric is not healthy because all InterSwitch Links are not connected.",
163 "MessageArgs": [],
164 "MessageId": "NFAB0017",
165 "Resolution": "Make sure that the VLTi cables for all ISLs are connected and operational as per the selected fabric design.",
166 "Severity": "Warning",
167 "TimeStamp": "2019-09-25T11:50:06Z"
168 },
169 {
170 "Category": "Audit",
171 "DetailedDescription": "The SmartFabric is not healthy because the interface for an uplink
172 mentioned in the message is not in operational status.",
173 "Message": "The SmartFabric is not healthy because the interface 6H7J6Z2:ethernet1/1/35 for uplink
174 1ad54420-b145-49a1-9779-21a579ef6f2d is not in operational status.",
175 "MessageArgs": [],
176 "MessageId": "NFAB0016",
177 "Resolution": "Make sure that all the uplink interfaces are in operational status.",
178 "Severity": "Warning",
179 "TimeStamp": "2019-09-25T11:50:06Z"
180 },
181 {
182 "Category": "Audit",
183 "DetailedDescription": "The SmartFabric is not healthy because one or more of the uplink interfaces are not bonded.",
184 "Message": "The SmartFabric is not healthy because the uplink 1ad54420-b145-49a1-9779-21a579ef6f2d
185 interface 6H7J6Z2:ethernet1/1/35 is not bonded to the other interfaces in the uplink.",
186 "MessageArgs": [],
187 "MessageId": "NFAB0019",
188 "Resolution": "Make sure that the Link Aggregation Control Protocol (LACP) is enabled on all ports on the remote
189 switch to which the uplink ports from the fabric are connected.",
190 "Severity": "Warning",
191 "TimeStamp": "2019-09-25T11:50:06Z"
192 },
193 {
194 "Category": "Audit",
195 "DetailedDescription": "The SmartFabric is not healthy because one or more of the uplink interfaces are not bonded.",
196 "Message": "The SmartFabric is not healthy because the uplink 1ad54420-b145-49a1-9779-21a579ef6f2d
197 interface JRWSV43:ethernet1/1/35 is not bonded to the other interfaces in the uplink.",
198 "MessageArgs": [],
199 "MessageId": "NFAB0019",
200 "Resolution": "Make sure that the Link Aggregation Control Protocol (LACP) is enabled on all ports
201 on the remote switch to which the uplink ports from the fabric are connected.",
202 "Severity": "Warning",
203 "TimeStamp": "2019-09-25T11:50:06Z"
204 }
205 ],
206 "Status": "4000"
207 },
208 "Id": "61c20a59-9ed5-4ae5-b850-5e5acf42d2f2",
209 "LifeCycleStatus": [
210 {
211 "Activity": "Create",
212 "Status": "2060"
213 }
214 ],
215 "Multicast": [
216 {
217 "FloodRestrict": true,
218 "IgmpVersion": "3",
219 "MldVersion": "2"
220 }
221 ],
222 "Name": "f1",
223 "OverrideLLDPConfiguration": "Disabled",
224 "ScaleVLANProfile": "Enabled",
225 "Servers": [
226 {
227 "ChassisServiceTag": "6H5S6Z2",
228 "ConnectionState": true,
229 "ConnectionStateReason": 101,
230 "DeviceCapabilities": [
231 1,
232 2,
233 3,
234 4,
235 7,
236 8,
237 9,
238 41,
239 10,
240 11,
241 12,
242 13,
243 14,
244 15,
245 208,
246 16,
247 17,
248 18,
249 212,
250 30,
251 31
252 ],
253 "DeviceManagement": [
254 {
255 "DnsName": "iDRAC-6GZK6Z2",
256 "InstrumentationName": "",
257 "MacAddress": "4c:d9:8f:7a:7c:43",
258 "ManagementId": 135185,
259 "ManagementProfile": [
260 {
261 "AgentName": "iDRAC",
262 "HasCreds": 0,
263 "ManagementId": 135185,
264 "ManagementProfileId": 135185,
265 "ManagementURL": "https://[2607:f2b1:f081:9:4ed9:8fff:fe7a:7c43]:443/",
266 "ProfileId": "WSMAN_OOB",
267 "Status": 1000,
268 "StatusDateTime": "2019-10-29 09:30:38.552",
269 "Version": "3.20.21.20"
270 }
271 ],
272 "ManagementType": 2,
273 "NetworkAddress": "100.96.24.28"
274 },
275 {
276 "DnsName": "iDRAC-6GZK6Z2",
277 "InstrumentationName": "",
278 "MacAddress": "4c:d9:8f:7a:7c:43",
279 "ManagementId": 135186,
280 "ManagementProfile": [
281 {
282 "AgentName": "iDRAC",
283 "HasCreds": 0,
284 "ManagementId": 135186,
285 "ManagementProfileId": 135186,
286 "ManagementURL": "https://[2607:f2b1:f081:9:4ed9:8fff:fe7a:7c43]:443/",
287 "ProfileId": "WSMAN_OOB",
288 "Status": 1000,
289 "StatusDateTime": "2019-10-29 09:30:38.552",
290 "Version": "3.20.21.20"
291 }
292 ],
293 "ManagementType": 2,
294 "NetworkAddress": "[2607:f2b1:f081:9:4ed9:8fff:fe7a:7c43]"
295 }
296 ],
297 "DeviceName": "MX-6H5S6Z2:Sled-1",
298 "DeviceServiceTag": "6GZK6Z2",
299 "Enabled": true,
300 "Id": 10071,
301 "Identifier": "6GZK6Z2",
302 "LastInventoryTime": "2019-10-29 09:30:38.552",
303 "LastStatusTime": "2019-10-29 09:41:51.051",
304 "ManagedState": 3000,
305 "Model": "PowerEdge MX840c",
306 "PowerState": 17,
307 "SlotConfiguration": {
308 "ChassisId": "10072",
309 "ChassisName": "MX-6H5S6Z2",
310 "ChassisServiceTag": "6H5S6Z2",
311 "DeviceType": "1000",
312 "SledBlockPowerOn": "None blocking",
313 "SlotId": "10084",
314 "SlotName": "Sled-1",
315 "SlotNumber": "1",
316 "SlotType": "2000"
317 },
318 "Status": 1000,
319 "SystemId": 1894,
320 "Type": 1000
321 }
322 ],
323 "Summary": {
324 "NodeCount": 2,
325 "ServerCount": 1,
326 "UplinkCount": 1
327 },
328 "Switches": [
329 {
330 "ChassisServiceTag": "6H5S6Z2",
331 "ConnectionState": true,
332 "ConnectionStateReason": 101,
333 "DeviceCapabilities": [
334 1,
335 2,
336 3,
337 5,
338 7,
339 8,
340 9,
341 207,
342 18,
343 602,
344 603,
345 604,
346 605,
347 606,
348 607,
349 608,
350 609,
351 610,
352 611,
353 612,
354 613,
355 614,
356 615,
357 616,
358 617,
359 618,
360 619,
361 620,
362 621,
363 622
364 ],
365 "DeviceManagement": [
366 {
367 "DnsName": "",
368 "InstrumentationName": "MX9116n Fabric Engine",
369 "MacAddress": "20:04:0F:4F:4E:04",
370 "ManagementId": 135181,
371 "ManagementProfile": [
372 {
373 "HasCreds": 0,
374 "ManagementId": 135181,
375 "ManagementProfileId": 135181,
376 "ManagementURL": "",
377 "ProfileId": "",
378 "Status": 1000,
379 "StatusDateTime": "2019-10-29 09:30:36.273"
380 }
381 ],
382 "ManagementType": 2,
383 "NetworkAddress": "100.96.24.36"
384 },
385 {
386 "DnsName": "",
387 "InstrumentationName": "MX9116n Fabric Engine",
388 "MacAddress": "20:04:0F:4F:4E:04",
389 "ManagementId": 135182,
390 "ManagementProfile": [
391 {
392 "HasCreds": 0,
393 "ManagementId": 135182,
394 "ManagementProfileId": 135182,
395 "ManagementURL": "",
396 "ProfileId": "",
397 "Status": 1000,
398 "StatusDateTime": "2019-10-29 09:30:36.273"
399 }
400 ],
401 "ManagementType": 2,
402 "NetworkAddress": ""
403 }
404 ],
405 "DeviceName": "MX-6H5S6Z2:IOM-A2",
406 "DeviceServiceTag": "6H7J6Z2",
407 "Enabled": true,
408 "Id": 10074,
409 "Identifier": "6H7J6Z2",
410 "LastInventoryTime": "2019-10-29 09:30:36.332",
411 "LastStatusTime": "2019-10-29 09:31:00.931",
412 "ManagedState": 3000,
413 "Model": "MX9116n Fabric Engine",
414 "PowerState": 17,
415 "SlotConfiguration": {
416 "ChassisId": "10072",
417 "ChassisName": "MX-6H5S6Z2",
418 "ChassisServiceTag": "6H5S6Z2",
419 "DeviceType": "4000",
420 "SledBlockPowerOn": "null",
421 "SlotId": "10079",
422 "SlotName": "IOM-A2",
423 "SlotNumber": "2",
424 "SlotType": "4000"
425 },
426 "Status": 1000,
427 "SystemId": 2031,
428 "Type": 4000
429 },
430 {
431 "ChassisServiceTag": "6H5S6Z2",
432 "ConnectionState": true,
433 "ConnectionStateReason": 101,
434 "DeviceCapabilities": [
435 1,
436 2,
437 3,
438 5,
439 7,
440 8,
441 9,
442 207,
443 18,
444 602,
445 603,
446 604,
447 605,
448 606,
449 607,
450 608,
451 609,
452 610,
453 611,
454 612,
455 613,
456 614,
457 615,
458 616,
459 617,
460 618,
461 619,
462 620,
463 621,
464 622
465 ],
466 "DeviceManagement": [
467 {
468 "DnsName": "",
469 "InstrumentationName": "MX9116n Fabric Engine",
470 "MacAddress": "E8:B5:D0:52:61:46",
471 "ManagementId": 135183,
472 "ManagementProfile": [
473 {
474 "HasCreds": 0,
475 "ManagementId": 135183,
476 "ManagementProfileId": 135183,
477 "ManagementURL": "",
478 "ProfileId": "",
479 "Status": 1000,
480 "StatusDateTime": "2019-10-29 09:30:37.115"
481 }
482 ],
483 "ManagementType": 2,
484 "NetworkAddress": "100.96.24.37"
485 },
486 {
487 "DnsName": "",
488 "InstrumentationName": "MX9116n Fabric Engine",
489 "MacAddress": "E8:B5:D0:52:61:46",
490 "ManagementId": 135184,
491 "ManagementProfile": [
492 {
493 "HasCreds": 0,
494 "ManagementId": 135184,
495 "ManagementProfileId": 135184,
496 "ManagementURL": "",
497 "ProfileId": "",
498 "Status": 1000,
499 "StatusDateTime": "2019-10-29 09:30:37.115"
500 }
501 ],
502 "ManagementType": 2,
503 "NetworkAddress": ""
504 }
505 ],
506 "DeviceName": "MX-6H5S6Z2:IOM-A1",
507 "DeviceServiceTag": "JRWSV43",
508 "Enabled": true,
509 "Id": 20881,
510 "Identifier": "JRWSV43",
511 "LastInventoryTime": "2019-10-29 09:30:37.172",
512 "LastStatusTime": "2019-10-29 09:31:00.244",
513 "ManagedState": 3000,
514 "Model": "MX9116n Fabric Engine",
515 "PowerState": 17,
516 "SlotConfiguration": {
517 "ChassisId": "10072",
518 "ChassisName": "MX-6H5S6Z2",
519 "ChassisServiceTag": "6H5S6Z2",
520 "DeviceType": "4000",
521 "SledBlockPowerOn": "null",
522 "SlotId": "10078",
523 "SlotName": "IOM-A1",
524 "SlotNumber": "1",
525 "SlotType": "4000"
526 },
527 "Status": 1000,
528 "SystemId": 2031,
529 "Type": 4000
530 }
531 ],
532 "Uplinks": [
533 {
534 "Id": "1ad54420-b145-49a1-9779-21a579ef6f2d",
535 "MediaType": "Ethernet",
536 "Name": "u1",
537 "NativeVLAN": 1,
538 "Summary": {
539 "NetworkCount": 1,
540 "PortCount": 2
541 },
542 "UfdEnable": "Disabled"
543 }
544 ]
545 }
546 ]
547
548 error_info:
549 description: Details of the HTTP Error.
550 returned: on HTTP error
551 type: dict
552 sample: {
553 "error": {
554 "code": "Base.1.0.GeneralError",
555 "message": "A general error has occurred. See ExtendedInfo for more information.",
556 "@Message.ExtendedInfo": [
557 {
558 "MessageId": "CGEN1006",
559 "RelatedProperties": [],
560 "Message": "Unable to complete the request because the resource URI does not exist or is not implemented.",
561 "MessageArgs": [],
562 "Severity": "Critical",
563 "Resolution": "Check the request resource URI. Refer to the OpenManage Enterprise-Modular User's Guide
564 for more information about resource URI and its properties."
565 }
566 ]
567 }
568 }
569 '''
570
571 import json
572 from ssl import SSLError
573 from ansible_collections.dellemc.openmanage.plugins.module_utils.ome import RestOME, OmeAnsibleModule
574 from ansible.module_utils.six.moves.urllib.error import URLError, HTTPError
575 from ansible.module_utils.urls import ConnectionError, SSLValidationError
576 from ansible_collections.dellemc.openmanage.plugins.module_utils.utils import strip_substr_dict
577
578
579 FABRIC_URI = "NetworkService/Fabrics"
580 # messages
581 SUCCESS_MSG = "Successfully retrieved the smart fabric information."
582 UNSUCCESS_MSG = "Unable to retrieve smart fabric information."
583 INVALID_FABRIC_ID = "Unable to retrieve smart fabric information with fabric ID {0}."
584 INVALID_FABRIC_NAME = "Unable to retrieve smart fabric information with fabric name {0}."
585
586
587 def get_smart_fabric_details_via_id(module, rest_obj, fabric_id):
588 resp = []
589 try:
590 fabric_path = "{0}('{1}')".format(FABRIC_URI, fabric_id)
591 resp_det = rest_obj.invoke_request("GET", fabric_path)
592 resp = [resp_det.json_data]
593 except HTTPError:
594 module.exit_json(msg=INVALID_FABRIC_ID.format(fabric_id), failed=True)
595 return resp
596
597
598 def fetch_smart_fabric_link_details(module, rest_obj, fabric_details_dict):
599 info_dict = {"Switches": "[email protected]", "Servers": "[email protected]",
600 "ISLLinks": "[email protected]", "Uplinks": "[email protected]",
601 "Multicast": None, "FabricDesign": None}
602 info_list = ["Multicast", "FabricDesign"]
603 details = None
604 try:
605 for key in info_dict:
606 link = info_dict[key]
607 if key in info_list:
608 fabric_info_dict = fabric_details_dict[key]["@odata.id"]
609 uri = fabric_info_dict.strip("/api")
610 response = rest_obj.invoke_request('GET', uri)
611 if response.json_data:
612 details = [response.json_data]
613 else:
614 fabric_info_dict = fabric_details_dict.get(link)
615 uri = fabric_info_dict.strip("/api")
616 response = rest_obj.invoke_request('GET', uri)
617 if response.json_data:
618 details = response.json_data.get("value")
619 for item in details:
620 item = strip_substr_dict(item)
621 item = clean_data(item)
622 fabric_details_dict[key] = details
623 except HTTPError:
624 module.exit_json(msg=UNSUCCESS_MSG, failed=True)
625 return fabric_details_dict
626
627
628 def strip_smart_fabric_info(module, rest_obj, smart_fabric_info):
629 for i in range(len(smart_fabric_info)):
630 fabrics_details = smart_fabric_info[i]
631 fabrics_details = fetch_smart_fabric_link_details(module, rest_obj, fabrics_details)
632 fabrics_details = strip_substr_dict(fabrics_details)
633 fabrics_details = clean_data(fabrics_details)
634 smart_fabric_info[i] = fabrics_details
635 return smart_fabric_info
636
637
638 def clean_data(data):
639 """
640 data: A dictionary.
641 return: A data dictionary after removing items that are not required for end user.
642 """
643 for k in data.copy():
644 if isinstance(data[k], dict):
645 if data[k].get("@odata.id"):
646 del data[k]["@odata.id"]
647 if not data[k]:
648 del data[k]
649 return data
650
651
652 def main():
653
654 specs = {
655 "fabric_id": {"type": 'str', "required": False},
656 "fabric_name": {"type": 'str', "required": False}
657 }
658
659 module = OmeAnsibleModule(
660 argument_spec=specs,
661 mutually_exclusive=[
662 ('fabric_id', 'fabric_name')
663 ],
664 supports_check_mode=True
665 )
666 try:
667 with RestOME(module.params, req_session=True) as rest_obj:
668 if module.params.get("fabric_id") is not None:
669 fabric_id = module.params.get("fabric_id")
670 smart_fabric_info = get_smart_fabric_details_via_id(module, rest_obj, fabric_id)
671 smart_fabric_info = strip_smart_fabric_info(module, rest_obj, smart_fabric_info)
672 module.exit_json(msg=SUCCESS_MSG, smart_fabric_info=smart_fabric_info)
673 else:
674 resp = rest_obj.invoke_request('GET', FABRIC_URI)
675 if resp.json_data:
676 smart_fabric_info = resp.json_data.get("value")
677 if module.params.get("fabric_name") is not None:
678 fabric_name_found = False
679 for fabric in smart_fabric_info:
680 fabric_name = module.params.get("fabric_name")
681 if fabric['Name'] == fabric_name:
682 smart_fabric_info = [fabric]
683 fabric_name_found = True
684 if not fabric_name_found:
685 module.exit_json(msg=INVALID_FABRIC_NAME.format(fabric_name), failed=True)
686 smart_fabric_info = strip_smart_fabric_info(module, rest_obj, smart_fabric_info)
687 module.exit_json(msg=SUCCESS_MSG, smart_fabric_info=smart_fabric_info)
688 else:
689 module.exit_json(msg=UNSUCCESS_MSG, failed=True)
690 except HTTPError as err:
691 module.fail_json(msg=str(err), error_info=json.load(err))
692 except URLError as err:
693 module.exit_json(msg=str(err), unreachable=True)
694 except (SSLValidationError, ConnectionError, TypeError, ValueError, OSError, SSLError) as err:
695 module.fail_json(msg=str(err))
696
697
698 if __name__ == '__main__':
699 main()