Skip to content

Commit 065dfeb

Browse files
committed
Refactor External volumes check
1 parent 96b9286 commit 065dfeb

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

src/dstack/_internal/server/services/volumes.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -400,23 +400,19 @@ def _validate_volume_configuration(configuration: VolumeConfiguration):
400400
)
401401
if configuration.name is not None:
402402
validate_dstack_resource_name(configuration.name)
403-
# External volumes (with volume_id) cannot have auto_cleanup_duration
403+
404404
if configuration.volume_id is not None and configuration.auto_cleanup_duration is not None:
405405
if (
406406
isinstance(configuration.auto_cleanup_duration, int)
407-
and configuration.auto_cleanup_duration >= 0
407+
and configuration.auto_cleanup_duration > 0
408+
) or (
409+
isinstance(configuration.auto_cleanup_duration, str)
410+
and configuration.auto_cleanup_duration not in ("off", "-1")
408411
):
409412
raise ServerClientError(
410413
"External volumes (with volume_id) do not support auto_cleanup_duration. "
411414
"Auto-cleanup only works for volumes created and managed by dstack."
412415
)
413-
elif isinstance(
414-
configuration.auto_cleanup_duration, str
415-
) and configuration.auto_cleanup_duration not in ("off", "-1"):
416-
raise ServerClientError(
417-
"External volumes (with volume_id) do not support auto_cleanup_duration. "
418-
"Auto-cleanup only works for volumes created and managed by dstack."
419-
)
420416

421417

422418
async def _delete_volume(session: AsyncSession, project: ProjectModel, volume_model: VolumeModel):

0 commit comments

Comments
 (0)