def nvme_to_nvd_map(self): nvme_to_nvd = {} for disk in self.middleware.call_sync("disk.query", [["devname", "^", "nvd"]]): try: n = int(disk["devname"][len("nvd"):]) except ValueError: continue nvd = f"/dev/{disk['devname']}" if not os.path.exists(nvd): continue nvme = get_nsid(nvd) if nvme is not None: nvme_to_nvd[int(nvme[4:])] = n return nvme_to_nvd
def sed_dev_name(self, disk_name): if disk_name.startswith("nvd"): nvme = get_nsid(f"/dev/{disk_name}") return f"/dev/{nvme}" return f"/dev/{disk_name}"
def m50_plx_enclosures(self): system_product = self.middleware.call_sync("system.info")["system_product"] if system_product is None or not ("TRUENAS-M50" in system_product or "TRUENAS-M60" in system_product): return [] nvme_to_nvd = {} for disk in self.middleware.call_sync("disk.query", [["devname", "^", "nvd"]]): try: n = int(disk["devname"][len("nvd"):]) except ValueError: continue nvd = f"/dev/{disk['devname']}" if not os.path.exists(nvd): continue nvme = get_nsid(nvd) if nvme is not None: nvme_to_nvd[int(nvme[4:])] = n slot_to_nvd = {} for nvme, nvd in nvme_to_nvd.items(): try: pci = sysctl.filter(f"dev.nvme.{nvme}.%parent")[0].value m = re.match(self.RE_PCI, pci) if not m: continue pcib = sysctl.filter(f"dev.pci.{m.group(1)}.%parent")[0].value m = re.match(self.RE_PCIB, pcib) if not m: continue pnpinfo = sysctl.filter(f"dev.pcib.{m.group(1)}.%pnpinfo")[0].value if "vendor=0x10b5 device=0x8717" not in pnpinfo: continue location = sysctl.filter(f"dev.pcib.{m.group(1)}.%location")[0].value m = re.match(self.RE_SLOT, location) if not m: continue slot = int(m.group(1)) except IndexError: continue slot_to_nvd[slot] = f"nvd{nvd}" elements = [] for slot in range(1, 5): device = slot_to_nvd.get(slot, None) if device is not None: status = "OK" value_raw = "0x1000000" else: status = "Not Installed" value_raw = "0x05000000" elements.append({ "slot": slot, "data": { "Descriptor": f"Disk #{slot}", "Status": status, "Value": "None", "Device": device, }, "name": "Array Device Slot", "descriptor": f"Disk #{slot}", "status": status, "value": "None", "value_raw": value_raw, }) return [ { "id": "m50_plx_enclosure", "name": "Rear NVME U.2 Hotswap Bays", "model": "M50/60 Series", "controller": True, "label": "Rear NVME U.2 Hotswap Bays", "elements": [ { "name": "Array Device Slot", "descriptor": "Drive Slots", "header": ["Descriptor", "Status", "Value", "Device"], "elements": elements, "has_slot_status": False, }, ], } ]