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

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.

mount_point

The mount point of the file.

Type:

str

content

The content of the file, which can be either text or binary.

Type:

FileContent

__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:

File

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:

File

__str__()[source]

Return a string representation of the File object.

Returns:

String representation of the File object.

Return type:

str

to_dict()[source]

Convert the File instance to a dictionary representation.

Returns:

The dictionary representation of the File instance.

Return type:

dict

Raises:

ValueError – If the file content type is unsupported.

FileContent Union Type

ankaios_sdk._components.file.FileContent

alias of DataFileContent | BinaryFileContent

DataFileContent Class

class ankaios_sdk._components.file.DataFileContent(value)[source]

This class is used to represent text-based file content.

value

The text content value.

Type:

str

BinaryFileContent Class

class ankaios_sdk._components.file.BinaryFileContent(value)[source]

This class is used to represent binary file content.

value

The binary content value as a Base64 encoded string.

Type:

str