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:
FileBackendFileBackend 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:
- Parameters:
path (str) – Path to the file relative to the backend root.
- Raises:
FileNotFoundError – If the file does not exist.
- 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.
- listdir(path)[source]#
List all files and directories at the given path.
- Return type:
- 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:
- 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:
- Parameters:
- Returns:
IO – File-like object supporting read/write operations.
- Raises:
FileNotFoundError – If the file does not exist when opening in read mode.