Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NAS-134360 / 25.10 / Add a description for PCI devices #15826

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Qubad786
Copy link
Contributor

Context

It was requested by UI team that we provide PCI devices description as well so users can know more about the PCI device which they have selected.

@Qubad786 Qubad786 requested a review from a team February 24, 2025 12:30
@bugclerk bugclerk changed the title Add a description for PCI devices NAS-134360 / 25.10 / Add a description for PCI devices Feb 24, 2025
@bugclerk
Copy link
Contributor

@@ -14,6 +14,8 @@

class VirtDeviceService(Service):

PCI_CHOICES = None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like class attributes for caching values. Please use the @cache decorator. We have a custom one in middlewared.utils.functools module. Also, is there any way we can return an immutable object here so that this cache doesn't get altered? I'm thinking of using something like dataclasses(frozen=True, slots=True).

Something like this

from dataclasses import dataclass, asdict

@dataclass(slots=True, frozen=True, kw_only=True)
class PciEntry:
    ...


@cache
def get_pci_devs_cache(self) -> tuple[PciEntry]:
     result = list()
     for blah, blah in blah.items():
         result.append(PciEntry(blah, blah, blah))
     return tuple(result)
  
@api_method(...)
 def pci_choices():
     return [asdict(i) for i in self.get_pci_devs_cache()]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants