FileBackend Storage#

Abstract base class for file storage backends in OpenFactory.

This module defines the FileBackend interface, which provides a uniform API for reading, writing, listing, and deleting files across different storage backends (e.g., NFS, MinIO, WebDAV). Specific backends should implement this abstract class.

The from_config static method provides a factory for instantiating the appropriate backend based on a configuration dictionary.

Warning

The FileBackend class is an abstract class not intented to be used.

class openfactory.filelayer.backend.FileBackend[source]#

Bases: ABC

Abstract base class defining the interface for all file storage backends.

compatible_with_swarm()[source]#

Returns whether this backend can be safely used with SwarmDeploymentStrategy.

By default, backends are assumed compatible. Override in subclasses that cannot be used with Swarm.

Return type:

bool

Returns:

bool – True if compatible with Swarm, False otherwise.

abstractmethod delete(path)[source]#

Delete the file at the given path.

Return type:

None

Parameters:

path (str) – Path to the file relative to the backend root.

Raises:
abstractmethod exists(path)[source]#

Check whether a file exists at the given path.

Return type:

bool

Parameters:

path (str) – Path to the file relative to the backend root.

Returns:

bool – True if the file exists, False otherwise.

Raises:

NotImplementedError – Must be implemented in a subclass.

static from_config(config)[source]#

Factory method to create a FileBackend instance from a configuration dictionary.

Return type:

FileBackend

Parameters:

config (dict) – Configuration dictionary specifying the backend type and options.

Returns:

FileBackend – An instance of a concrete FileBackend subclass.

Raises:

NotImplementedError – Must be implemented in a subclass or factory function.

abstractmethod get_mount_spec()[source]#

Return the mount specification for Docker, if applicable.

Return type:

dict | None

Returns:

dict – Docker mount spec (source, target, type, options) or None if not mountable.

abstractmethod listdir(path)[source]#

List all files and directories at the given path.

Return type:

List[str]

Parameters:

path (str) – Path to the directory relative to the backend root.

Returns:

List[str] – List of file and directory names.

Raises:

NotImplementedError – Must be implemented in a subclass.

abstractmethod open(path, mode='r')[source]#

Open a file at the given path.

Return type:

IO

Parameters:
  • path (str) – Path to the file relative to the backend root.

  • mode (str) – File mode (‘r’, ‘w’, ‘rb’, ‘wb’, etc.). Defaults to ‘r’.

Returns:

IO – A file-like object supporting read/write operations.

Raises:

NotImplementedError – Must be implemented in a subclass.