Commit 10839ec9 authored by Daniele Venzano's avatar Daniele Venzano

Fix volume description and update docs

parent 9c4cda74
......@@ -82,13 +82,13 @@ A number of special values can be used, these will be substituted by Zoe when th
volumes
^^^^^^^
array
object
A list of additional volumes to be mounted in this service container. Each volume is described by an array with three elements:
A list of additional volumes to be mounted in this service container. Each volume is described by an object with three elements:
* host path: the path on the host to mounted
* container path: the path inside the container where host path should be mounted
* read only: a boolean, if true the mountpoint will be read only
* name: the name for this volume. In the container the volume will be mounted as ``/mnt/<name>``
* path: the path on the host (usually on a shared filasystem) that should be mounted in this service container
* read_only: a boolean, if true the volume will be read only
Zoe will always mount the user workspace directory in ``$ZOE_WORKSPACE``.
......
......@@ -63,11 +63,17 @@ class ResourceReservation:
class VolumeDescription:
"""A generic description for container volumes."""
def __init__(self, data):
self.type = "host_directory"
self.path = data[0]
self.mount_point = data[1]
self.readonly = data[2]
def __init__(self, vtype: str):
self.type = vtype
class VolumeDescriptionHostPath(VolumeDescription):
"""Host-based volumes."""
def __init__(self, name: str, path: str, readonly: bool):
super().__init__("host-directory")
self.path = path
self.mount_point = '/mnt/' + name
self.readonly = readonly
class Service:
......@@ -113,7 +119,7 @@ class Service:
self.environment = self.description['environment']
self.command = self.description['command']
self.resource_reservation = ResourceReservation(self.description['resources'])
self.volumes = [VolumeDescription(v) for v in self.description['volumes']]
self.volumes = [VolumeDescriptionHostPath(v['path'], v['name'], v['read_only']) for v in self.description['volumes']]
self.replicas = self.description['replicas']
def serialize(self):
......
......@@ -15,10 +15,10 @@
"""The high-level interface that Zoe uses to talk to the configured container backend."""
from typing import Dict
from typing import Dict, List
from zoe_lib.config import get_conf
from zoe_lib.state import Service, Execution
from zoe_lib.state import Service, Execution, VolumeDescription
from zoe_master.exceptions import ZoeStartExecutionFatalException
from zoe_master.workspace.filesystem import ZoeFSWorkspace
......@@ -48,9 +48,10 @@ def gen_environment(execution: Execution, service: Service, env_subst_dict: Dict
return env_list
def gen_volumes(service_: Service, execution: Execution):
def gen_volumes(service: Service, execution: Execution) -> List[VolumeDescription]:
"""Return the list of default volumes to be added to all containers."""
vol_list = []
vol_list = service.volumes
fswk = ZoeFSWorkspace()
wk_vol = fswk.get(execution.user_id)
......
......@@ -56,7 +56,7 @@ class ServiceInstance:
self.labels = zoe_master.backends.common.gen_labels(service, execution)
self.environment = service.environment + zoe_master.backends.common.gen_environment(execution, service, env_subst_dict)
self.volumes = service.volumes + zoe_master.backends.common.gen_volumes(service, execution)
self.volumes = zoe_master.backends.common.gen_volumes(service, execution)
self.command = service.command
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment