Skip to content

Commit

Permalink
Add the driver-package config option (#1)
Browse files Browse the repository at this point in the history
Add the driver-package option to set
the package to be installed.
  • Loading branch information
jaimesouza authored Feb 27, 2023
1 parent e3a6684 commit 62d1758
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
6 changes: 6 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
options:
driver-package:
type: string
default: "nvidia-driver-latest-dkms"
description: |
Driver package to be installed.
4 changes: 3 additions & 1 deletion src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ def __init__(self, *args):
"""Initialize the charm."""
super().__init__(*args)

self._nvidia_ops_manager = NvidiaOpsManager()
driver_package = self.config.get("driver-package")

self._nvidia_ops_manager = NvidiaOpsManager(driver_package)

event_handler_bindings = {
self.on.install: self._on_install,
Expand Down
14 changes: 7 additions & 7 deletions src/nvidia_ops_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self, message: str):
class NvidiaOpsManager:
"""NvidiaOpsManager."""

def __init__(self):
def __init__(self, driver_package):
"""Initialize class level variables."""
self.PACKAGE_DEPS = [
"tar",
Expand All @@ -39,7 +39,7 @@ def __init__(self):
self.EPEL_RELEASE_REPO = (
"https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm"
)
self.NVIDIA_DRIVER_PACKAGE = "nvidia-driver-latest-dkms"
self.NVIDIA_DRIVER_PACKAGE = driver_package
self.NVIDIA_DRIVER_REPO_FILEPATH = Path("/etc/yum.repos.d/cuda-rhel7.repo")

@property
Expand Down Expand Up @@ -89,7 +89,7 @@ def install(self) -> None:
req = requests.get(self._nvidia_developer_repo)
except requests.exceptions.HTTPError:
raise NvidiaDriverOpsError(
"Error getting nvidia_developer_repository from {self._nvidia_developer_repo}."
f"Error getting nvidia_developer_repository from {self._nvidia_developer_repo}."
)
self.NVIDIA_DRIVER_REPO_FILEPATH.write_text(req.text)
# Add the devel kernel and kernel headers.
Expand All @@ -102,19 +102,19 @@ def install(self) -> None:
run(["yum", "clean", "expire-cache"])
except CalledProcessError:
raise NvidiaDriverOpsError("Error flushing the cache.")
# Install nvidia-driver-latest-dkms..
# Install nvidia-driver package..
try:
run(["yum", "install", "-y", self.NVIDIA_DRIVER_PACKAGE])
except CalledProcessError:
raise NvidiaDriverOpsError("Error installing nvidia-driver-latest-dkms.")
raise NvidiaDriverOpsError("Error installing nvidia drivers.")

def remove(self) -> None:
"""Remove nvidia drivers from the system."""
# Remove nvidia-driver-latest-dkms..
# Remove nvidia-driver package..
try:
run(["yum", "erase", "-y", self.NVIDIA_DRIVER_PACKAGE])
except CalledProcessError:
raise NvidiaDriverOpsError("Error removing nvidia-driver-latest-dkms from the system.")
raise NvidiaDriverOpsError("Error removing nvidia drivers from the system.")
# Remove the drivers repo
if self.NVIDIA_DRIVER_REPO_FILEPATH.exists():
self.NVIDIA_DRIVER_REPO_FILEPATH.unlink()
Expand Down

0 comments on commit 62d1758

Please sign in to comment.