File
This module defines the File class for handling files mounted to Ankaios workloads.
Classes
File:Represents a file that can be mounted to an Ankaios workload.
DataFileContent:Represents text-based file content.
BinaryFileContent:Represents binary file content.
Union Types
FileContent:Union type for file content, which can be either
DataFileContentorBinaryFileContent.
Usage
- Create a File instance from text data:
file = File.from_data( mount_point="/path/to/mount", data="file content")
- Create a File instance from binary data:
file = File.from_binary_data( mount_point="/path/to/mount", binary_data="binary content")
- Convert a File instance to a dictionary:
file_dict = file.to_dict()
- Get the content and check it’s type:
file = File() if isinstance(file.content, DataFileContent): print("Text file content:", file.content.value) elif isinstance(file.content, BinaryFileContent): print("Binary file content:", file.content.value)
File Class
- class ankaios_sdk._components.file.File(mount_point, content)[source]
This class represents a file able to be mounted to an Ankaios workload. It can hold either text-based or binary content.
- Variables:
mount_point (str) – The mount point of the file.
content (FileContent) – The content of the file, which can be either text or binary.
- __init__(mount_point, content)[source]
Initialize a File instance.
- Parameters:
mount_point (str) – The mount point of the file.
content (FileContent) – The content of the file, which can be either text or binary.
- classmethod from_data(mount_point, data)[source]
Create a File instance from text data.
- Parameters:
mount_point (str) – The mount point of the file.
data (str) – The text content of the file.
- Returns:
A File instance with text-based content.
- Return type:
- classmethod from_binary_data(mount_point, binary_data)[source]
Create a File instance from binary data.
- Parameters:
mount_point (str) – The mount point of the file.
binary_data (str) – The binary content of the file.
- Returns:
A File instance with binary content.
- Return type:
FileContent Union Type
- ankaios_sdk._components.file.FileContent
alias of
DataFileContent|BinaryFileContent