From 72f70c3d719971de18f830efc96946193ebd5cba Mon Sep 17 00:00:00 2001 From: themylogin Date: Thu, 28 Nov 2024 12:16:07 +0100 Subject: [PATCH] `docker.nvidia_present` --- .../middlewared/api/v25_04_0/docker.py | 9 ++++++++- .../middlewared/plugins/docker/update.py | 17 ++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/middlewared/middlewared/api/v25_04_0/docker.py b/src/middlewared/middlewared/api/v25_04_0/docker.py index 602f90d3d60b..64b311a49983 100644 --- a/src/middlewared/middlewared/api/v25_04_0/docker.py +++ b/src/middlewared/middlewared/api/v25_04_0/docker.py @@ -1,4 +1,3 @@ -from ipaddress import IPv4Interface, IPv6Interface from typing import Annotated, Literal from pydantic import IPvAnyInterface, Field, field_validator, model_validator @@ -68,3 +67,11 @@ class StatusResult(BaseModel): class DockerStatusResult(BaseModel): result: StatusResult + + +class DockerNvidiaPresentArgs(BaseModel): + pass + + +class DockerNvidiaPresentResult(BaseModel): + result: bool diff --git a/src/middlewared/middlewared/plugins/docker/update.py b/src/middlewared/middlewared/plugins/docker/update.py index cbb761f75007..92ceedba3314 100644 --- a/src/middlewared/middlewared/plugins/docker/update.py +++ b/src/middlewared/middlewared/plugins/docker/update.py @@ -6,10 +6,12 @@ from middlewared.api import api_method from middlewared.api.current import ( - DockerEntry, DockerStatusArgs, DockerStatusResult, DockerUpdateArgs, DockerUpdateResult, + DockerEntry, DockerStatusArgs, DockerStatusResult, DockerUpdateArgs, DockerUpdateResult, DockerNvidiaPresentArgs, + DockerNvidiaPresentResult, ) from middlewared.schema import ValidationErrors from middlewared.service import CallError, ConfigService, job, private +from middlewared.utils.gpu import get_gpus from middlewared.utils.zfs import query_imported_fast_impl from .state_utils import Status @@ -132,6 +134,19 @@ async def status(self): """ return await self.middleware.call('docker.state.get_status_dict') + @api_method(DockerNvidiaPresentArgs, DockerNvidiaPresentResult) + def nvidia_present(self): + adv_config = self.middleware.call_sync("system.advanced.config") + + for gpu in get_gpus(): + if gpu["addr"]["pci_slot"] in adv_config["isolated_gpu_pci_ids"]: + continue + + if gpu["vendor"] == "NVIDIA": + return True + + return False + @private def configure_nvidia(self): config = self.middleware.call_sync('docker.config')