Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Containerfile.debugpy
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ COPY ../../. .

RUN uv sync --extra prod --extra dev
RUN echo "yes" | uv run manage.py initial_setup
RUN PLUGIN_SLURM=True uv run coldfront slurm_attr_create
RUN uv run manage.py load_test_data

ENV DEBUG=True
Expand Down
59 changes: 59 additions & 0 deletions coldfront/plugins/slurm/management/commands/slurm_attr_create.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import logging

from django.core.management.base import BaseCommand
from coldfront.core.resource.models import (
ResourceAttribute,
ResourceAttributeType,
Resource,
)
from coldfront.plugins.slurm.utils import SLURM_CLUSTER_ATTRIBUTE_NAME
from coldfront.core.utils.common import import_from_settings

GENERAL_RESOURCE_NAME = import_from_settings("GENERAL_RESOURCE_NAME")

logger = logging.getLogger(__name__)


class Command(BaseCommand):
help = "Create ResourceAttribute for default SLURM cluster resousce"

def handle(self, *args, **options):
logger.setLevel(logging.INFO)

clusters = Resource.objects.filter(resource_type__name="Cluster")
if clusters.count() != 1:
logger.warning(
"More than one cluster is present, \
will not set ResourceAttribute"
)
return

cluster = clusters[0]
if cluster.name != GENERAL_RESOURCE_NAME:
logger.warning(
f"Cluster is present, but it is {cluster.name},\
differernt from {GENERAL_RESOURCE_NAME} \
will not set ResourceAttribute"
)
return

_, created = ResourceAttribute.objects.get_or_create(
resource_attribute_type=ResourceAttributeType.objects.filter(
name=SLURM_CLUSTER_ATTRIBUTE_NAME
)[0],
resource=cluster,
value=GENERAL_RESOURCE_NAME,
)

if created:
logger.info(
f"Resource Attribute for {GENERAL_RESOURCE_NAME} \
HPC cluster resource added."
)
else:
logger.info(
f"ResourceAttribute for {GENERAL_RESOURCE_NAME}\
HPC cluster resource already available in DB."
)

return
Loading