Skip to content

Commit

Permalink
HACK: update slurm_ops and modify to use latest slurmutils.
Browse files Browse the repository at this point in the history
Done temporarily to get GPU support working. Undo this once
`slurm_ops` is properly updated.
  • Loading branch information
dsloanm committed Dec 20, 2024
1 parent 2c95313 commit a5265ab
Showing 1 changed file with 59 additions and 24 deletions.
83 changes: 59 additions & 24 deletions external/lib/charms/hpc_libs/v0/slurm_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,20 @@ def _on_install(self, _) -> None:
import yaml
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric import rsa
from slurmutils.editors import acctgatherconfig, cgroupconfig, slurmconfig, slurmdbdconfig
from slurmutils.models import AcctGatherConfig, CgroupConfig, SlurmConfig, SlurmdbdConfig
from slurmutils.editors import (
acctgatherconfig,
cgroupconfig,
gresconfig,
slurmconfig,
slurmdbdconfig,
)
from slurmutils.models import (
AcctGatherConfig,
CgroupConfig,
GRESConfig,
SlurmConfig,
SlurmdbdConfig,
)

try:
import charms.operator_libs_linux.v0.apt as apt
Expand All @@ -97,14 +109,14 @@ def _on_install(self, _) -> None:

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 10
LIBPATCH = 11

# Charm library dependencies to fetch during `charmcraft pack`.
PYDEPS = [
"cryptography~=44.0.0",
"pyyaml>=6.0.2",
"python-dotenv~=1.0.1",
"slurmutils~=0.9.0",
"slurmutils~=0.11.0",
"distro~=1.9.0",
]

Expand Down Expand Up @@ -245,26 +257,6 @@ def edit(self):
"""Edit the current configuration file."""


class _SlurmConfigManager(_ConfigManager):
"""Control the `slurm.conf` configuration file."""

def load(self) -> SlurmConfig:
"""Load the current `slurm.conf` configuration file."""
return slurmconfig.load(self._config_path)

def dump(self, config: SlurmConfig) -> None:
"""Dump new configuration into `slurm.conf` configuration file."""
slurmconfig.dump(config, self._config_path, mode=0o644, user=self._user, group=self._group)

@contextmanager
def edit(self) -> SlurmConfig:
"""Edit the current `slurm.conf` configuration file."""
with slurmconfig.edit(
self._config_path, mode=0o644, user=self._user, group=self._group
) as config:
yield config


class _AcctGatherConfigManager(_ConfigManager):
"""Manage the `acct_gather.conf` configuration file."""

Expand Down Expand Up @@ -309,6 +301,46 @@ def edit(self) -> CgroupConfig:
yield config


class _GRESConfigManager(_ConfigManager):
"""Manage the `gres.conf` configuration file."""

def load(self) -> GRESConfig:
"""Load the current `gres.conf` configuration files."""
return gresconfig.load(self._config_path)

def dump(self, config: GRESConfig) -> None:
"""Dump new configuration into `gres.conf` configuration file."""
gresconfig.dump(config, self._config_path, mode=0o644, user=self._user, group=self._group)

@contextmanager
def edit(self) -> GRESConfig:
"""Edit the current `gres.conf` configuration file."""
with gresconfig.edit(
self._config_path, mode=0o644, user=self._user, group=self._group
) as config:
yield config


class _SlurmConfigManager(_ConfigManager):
"""Control the `slurm.conf` configuration file."""

def load(self) -> SlurmConfig:
"""Load the current `slurm.conf` configuration file."""
return slurmconfig.load(self._config_path)

def dump(self, config: SlurmConfig) -> None:
"""Dump new configuration into `slurm.conf` configuration file."""
slurmconfig.dump(config, self._config_path, mode=0o644, user=self._user, group=self._group)

@contextmanager
def edit(self) -> SlurmConfig:
"""Edit the current `slurm.conf` configuration file."""
with slurmconfig.edit(
self._config_path, mode=0o644, user=self._user, group=self._group
) as config:
yield config


class _SlurmdbdConfigManager(_ConfigManager):
"""Control the `slurmdbd.conf` configuration file."""

Expand Down Expand Up @@ -951,6 +983,9 @@ def __init__(self, *args, **kwargs) -> None:
self.cgroup = _CgroupConfigManager(
self._ops_manager.etc_path / "cgroup.conf", self.user, self.group
)
self.gres = _GRESConfigManager(
self._ops_manager.etc_path / "gres.conf", self.user, self.group
)


class SlurmdManager(_SlurmManagerBase):
Expand Down

0 comments on commit a5265ab

Please sign in to comment.