Skip to content

Commit

Permalink
docker.nvidia_present (#15055)
Browse files Browse the repository at this point in the history
  • Loading branch information
themylogin authored Nov 30, 2024
1 parent d511b7a commit 262ba1b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/middlewared/middlewared/api/v25_04_0/docker.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from ipaddress import IPv4Interface, IPv6Interface
from typing import Annotated, Literal

from pydantic import IPvAnyInterface, Field, field_validator, model_validator
Expand Down Expand Up @@ -68,3 +67,11 @@ class StatusResult(BaseModel):

class DockerStatusResult(BaseModel):
result: StatusResult


class DockerNvidiaPresentArgs(BaseModel):
pass


class DockerNvidiaPresentResult(BaseModel):
result: bool
17 changes: 16 additions & 1 deletion src/middlewared/middlewared/plugins/docker/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 262ba1b

Please sign in to comment.