Files
ubicloud/model/pci_device.rb
Benjamin Satzger 63be63c68c Get name of PCI device
This commit adds new methods to get the name of known PCI devices.

For NVIDIA devices, the mapping of pci ids to names can be found at
https://download.nvidia.com/XFree86/Linux-x86_64/535.98/README/supportedchips.html
2025-03-09 15:47:45 +01:00

55 lines
1.3 KiB
Ruby

# frozen_string_literal: true
require_relative "../model"
class PciDevice < Sequel::Model
many_to_one :vm_host
many_to_one :vm
def self.ubid_type
UBID::TYPE_ETC
end
def self.device_name(device_id)
# https://download.nvidia.com/XFree86/Linux-x86_64/535.98/README/supportedchips.html
case device_id
when "20b5"
"NVIDIA A100 80GB PCIe"
when "27b0"
"NVIDIA RTX 4000 SFF Ada Generation"
else
"PCI device"
end
end
include ResourceMethods
def is_gpu
["0300", "0302"].include? device_class
end
def name
PciDevice.device_name(device)
end
end
# Table: pci_device
# Columns:
# id | uuid | PRIMARY KEY
# slot | text | NOT NULL
# device_class | text | NOT NULL
# vendor | text | NOT NULL
# device | text | NOT NULL
# numa_node | integer |
# iommu_group | integer | NOT NULL
# enabled | boolean | NOT NULL DEFAULT true
# vm_host_id | uuid | NOT NULL
# vm_id | uuid |
# Indexes:
# pci_device_pkey | PRIMARY KEY btree (id)
# pci_device_vm_host_id_slot_key | UNIQUE btree (vm_host_id, slot)
# pci_device_vm_id_index | btree (vm_id)
# Foreign key constraints:
# pci_device_vm_host_id_fkey | (vm_host_id) REFERENCES vm_host(id)
# pci_device_vm_id_fkey | (vm_id) REFERENCES vm(id)