NFSBackend Storage Backend#

NFS (POSIX filesystem) implementation of the FileBackend interface for OpenFactory.

This backend allows OpenFactory services to interact with a local or network-mounted filesystem (NFS share) using the standard FileBackend API.

Note

  • This backend is compatible with Docker Swarm and can generate mount specifications via NFSBackend.get_mount_spec().

  • Ensure the NFS server is reachable and that mount options are valid for your environment.

See also

The schema of the NFS Backend is openfactory.schemas.filelayer.nfs_backend.NFSBackendConfig.

class openfactory.filelayer.nfs_backend.NFSBackend(config)[source]#

Bases: FileBackend

FileBackend implementation for POSIX/NFS filesystems.

__init__(config)[source]#

Initialize the NFSBackend.

Parameters:

config (NFSBackendConfig) – Configuration object for the NFS backend.

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:

FileNotFoundError – If the file does not exist.

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.

static from_config(config)[source]#

Create an NFSBackend instance from configuration.

Return type:

openfactory.filelayer.nfs_backend.NFSBackend

Parameters:

config (dict) – Configuration dictionary.

Returns:

NFSBackend – Configured backend instance.

Raises:

pydantic.ValidationError – If the configuration is invalid.

get_mount_spec()[source]#

Build a Docker-compatible mount specification for NFS.

This specification can be used directly in Docker Swarm service creation or container deployment.

Return type:

Dict[str, Any]

Returns:

Dict[str, Any] – A dictionary containing the mount configuration in Docker’s expected format.

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:

FileNotFoundError – If the directory does not exist.

make_volume_name()[source]#

Generate a deterministic NFS volume name for Docker.

The volume name is constructed from the NFS server address and the remote path. If mount options are provided, a short SHA1 hash of the normalized (sorted) options is appended to ensure uniqueness between different configurations (e.g., ro vs rw).

Return type:

str

Format:

nfs_<server>_<remote_path>[_<hash>]

Returns:

str – A deterministic volume name safe to use in Docker Swarm.

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 – File-like object supporting read/write operations.

Raises:

FileNotFoundError – If the file does not exist when opening in read mode.