Debian Codegraph @

ansible_collections/dellemc/openmanage/plugins/module_utils/idrac_utils/info/memory.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2
3 # Dell OpenManage Ansible Modules
4 # Version 9.12.0
5 # Copyright (C) 2025 Dell Inc. or its subsidiaries. All Rights Reserved.
6
7 # Redistribution and use in source and binary forms, with or without modification,
8 # are permitted provided that the following conditions are met:
9
10 # * Redistributions of source code must retain the above copyright notice,
11 # this list of conditions and the following disclaimer.
12
13 # * Redistributions in binary form must reproduce the above copyright notice,
14 # this list of conditions and the following disclaimer in the documentation
15 # and/or other materials provided with the distribution.
16
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 # IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
25 # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27
28 GET_IDRAC_MEMORY_DETAILS_URI = "/redfish/v1/Systems/System.Embedded.1/Memory"
29 NA = "Not Available"
30 MAPPING_DICT_FOR_RANK = {
31 0: "Unknown",
32 1: "Single Rank",
33 2: "Double Rank",
34 4: "Quad Rank"
35 }
36 MAPPING_MEMORY_TYPE_DICT = {
37 "Other": "1",
38 "Unknown": "2",
39 "DRAM": "3",
40 "EDRAM": "4",
41 "VRAM": "5",
42 "SRAM": "6",
43 "RAM": "7",
44 "ROM": "8",
45 "Flash": "9",
46 "EEPROM": "10",
47 "FEPROM": "11",
48 "EPROM": "12",
49 "CDRAM": "13",
50 "3DRAM": "14",
51 "SDRAM": "15",
52 "SGRAM": "16",
53 "RDRAM": "17",
54 "DDR": "18",
55 "DDR-2": "19",
56 "DDR-2-FB-DIMM": "20",
57 "DDR-3": "24",
58 "FBD2": "25"
59 }
60
61
62 class IDRACMemoryInfo(object):
63 def __init__(self, idrac):
64 self.idrac = idrac
65
66 def get_memory_links(self):
67 response = self.idrac.invoke_request(method='GET', uri=GET_IDRAC_MEMORY_DETAILS_URI)
68 memory_links_list = []
69 if response.status_code == 200:
70 members = response.json_data.get("Members")
71 for each in members:
72 memory_links_list.append(each.get("@odata.id"))
73 return memory_links_list
74
75 def get_parameters_with_units(self, response, output):
76 if output["CurrentOperatingSpeed"] is not None:
77 output["CurrentOperatingSpeed"] = \
78 str(float(response.json_data.get("OperatingSpeedMhz"))) \
79 + " MHz"
80 else:
81 output["CurrentOperatingSpeed"] = NA
82 if output["Speed"]:
83 output["Speed"] = \
84 str(response.json_data.get("AllowedSpeedsMHz")[0] / 1000)\
85 + " GHz"
86 else:
87 output["Speed"] = NA
88 if output["Size"] is not None:
89 output["Size"] = \
90 str(response.json_data.get("CapacityMiB") / 1024) + " GB"
91 else:
92 output["Size"] = NA
93 return output
94
95 def get_memory_details(self, memory_link):
96 response = self.idrac.invoke_request(method='GET', uri=memory_link)
97 output = {}
98 if response.status_code == 200:
99 output["BankLabel"] = response.json_data.get("Oem", {})\
100 .get("Dell", {}).get("DellMemory", {}).get("BankLabel", NA)
101 output["CurrentOperatingSpeed"] = \
102 response.json_data.get("OperatingSpeedMhz")
103 output["DeviceDescription"] = \
104 response.json_data.get("Description", NA)
105 output["FQDD"] = response.json_data.get("Id", NA)
106 output["Key"] = response.json_data.get("Id", NA)
107 output["ManufactureDate"] = response.json_data.get("Oem", {})\
108 .get("Dell", {}).get("DellMemory", {}).\
109 get("ManufactureDate", NA)
110 output["Manufacturer"] = response.json_data.\
111 get("Manufacturer", NA)
112 output["MemoryType"] = \
113 MAPPING_MEMORY_TYPE_DICT.get(
114 response.json_data.get("MemoryDeviceType"),
115 NA)
116 output["MemoryType_API"] = response.json_data.\
117 get("MemoryDeviceType", NA)
118 output["Model"] = response.json_data.get("Oem", {})\
119 .get("Dell", {}).get("DellMemory", {}).\
120 get("Model", NA)
121 output["PartNumber"] = response.json_data.get("PartNumber", NA)
122 output["PrimaryStatus"] = \
123 response.json_data.get("Status", {}).get("Health", NA)
124 output["Rank"] = \
125 MAPPING_DICT_FOR_RANK.get(response.json_data.get("RankCount"),
126 NA)
127 output["SerialNumber"] = response.json_data.\
128 get("SerialNumber", NA)
129 output["Size"] = response.json_data.get("CapacityMiB")
130 output["Speed"] = response.json_data.get("AllowedSpeedsMHz")
131 output["memoryDeviceStateSettings"] = \
132 response.json_data.get("Status", {}).get("State", NA)
133 if response.json_data.get("Status", {}).get("Health") == "OK":
134 output["PrimaryStatus"] = "Healthy"
135 else:
136 output["PrimaryStatus"] = response.json_data.\
137 get("Status", {}).get("Health", NA)
138 self.get_parameters_with_units(response, output)
139 return output
140
141 def get_memory_info(self):
142 memory_output = []
143 memory_links_list = self.get_memory_links()
144 for each_link in memory_links_list:
145 memory_output.append(self.get_memory_details(each_link))
146 return memory_output