From 53ae2ea4f736d3397df7ead1fa845c41223fa357 Mon Sep 17 00:00:00 2001 From: Stefano Alberto Russo <stefano.russo@gmail.com> Date: Wed, 10 Apr 2024 13:25:30 +0200 Subject: [PATCH] Added support for the internal storage in the internal computing resource. Minor fixes. --- .../rosetta/core_app/computing_managers.py | 28 ++++++++++++++++++- .../webapp/code/rosetta/core_app/models.py | 6 +++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/services/webapp/code/rosetta/core_app/computing_managers.py b/services/webapp/code/rosetta/core_app/computing_managers.py index 7e916e7..8894ad6 100644 --- a/services/webapp/code/rosetta/core_app/computing_managers.py +++ b/services/webapp/code/rosetta/core_app/computing_managers.py @@ -131,8 +131,30 @@ class InternalStandaloneComputingManager(StandaloneComputingManager): # User data volume #run_command += ' -v {}/user-{}:/data'.format(settings.LOCAL_USER_DATA_DIR, task.user.id) + # Handle storages (binds) + binds = '' + storages = Storage.objects.filter(computing=self.computing) + for storage in storages: + if storage.type == 'generic_posix' and storage.bind_path: + + # Expand the base path + expanded_base_path = storage.base_path + if '$USER' in expanded_base_path: + expanded_base_path = expanded_base_path.replace('$USER', task.user.username) + + # Expand the bind_path + expanded_bind_path = storage.bind_path + if '$USER' in expanded_bind_path: + expanded_bind_path = expanded_bind_path.replace('$USER', task.user.username) + + # Add the bind + if not binds: + binds = '-v{}:{}'.format(expanded_base_path, expanded_bind_path) + else: + binds += ' -v{}:{}'.format(expanded_base_path, expanded_bind_path) + # Host name, image entry command - run_command += ' -h task-{} --name task-{} -d -t {}/{}:{}'.format(task.short_uuid, task.short_uuid, task.container.registry, task.container.image_name, task.container.image_tag) + run_command += ' {} -h task-{} --name task-{} -d -t {}/{}:{}'.format(binds, task.short_uuid, task.short_uuid, task.container.registry, task.container.image_name, task.container.image_tag) # Debug logger.debug('Running new task with command="{}"'.format(run_command)) @@ -166,6 +188,10 @@ class InternalStandaloneComputingManager(StandaloneComputingManager): out = os_shell(stop_command, capture=True) if out.exit_code != 0: if 'No such container' in out.stderr: + # No container was found + pass + elif 'requires at least 1 argument' in out.stderr: + # No container was found pass else: raise Exception(out.stderr) diff --git a/services/webapp/code/rosetta/core_app/models.py b/services/webapp/code/rosetta/core_app/models.py index 29ffa5d..76061c1 100644 --- a/services/webapp/code/rosetta/core_app/models.py +++ b/services/webapp/code/rosetta/core_app/models.py @@ -398,7 +398,11 @@ class Storage(models.Model): # Include as browsable in the file manager? browsable = models.BooleanField('Browsable in the file manager?', default=True) - + def save(self, *args, **kwargs): + if self.access_mode == 'internal' and self.browsable: + raise ValueError('A storage with "internal" access mode cannot be marked as browsable since it is not yet supported by the file manager') + super(Storage, self).save(*args, **kwargs) + class Meta: ordering = ['name'] -- GitLab