Disk Types

Whilst Astdiskd is responsible for detecting what disks are attached to the system, it is the responsibility of each individual data component to determine if a disk is relevant to Astoria.

Disks are sorted into one of a few relevant types:

  • Usercode

  • Metadata

  • Update

  • No Action

Disk Identification

A disk can only have one type, the value of which must be a member of astoria.common.disks.DiskType.

Given the mount path for a disk, the type of the disk can be found using astoria.common.disks.DiskTypeCalculator.

The path is compared against a astoria.common.disks.constraints.Constraint for each type. The type that is returned will be the first type for which the constraint matches.

As a disk must always have a type, the last constraint in the list is DiskType.NOACTION, which is matched using a astoria.common.disks.constraints.TrueConstraint.

Constraints

A constraint is a class that implements astoria.common.disks.constraints.Constraint. Given a path, a constaint will determine if the path matches the constraint or not.

Some constraints, such as astoria.common.disks.constraints.AndConstraint take other constraints as parameters in the constructor. This allows us to combine constraints programmatically.

A full list of available constraints, along with their uses is listed in Constraint Definitions.

Disk Type Classes

class astoria.common.disks.DiskType(value)[source]

Type of disk.

METADATA = 'METADATA'
NOACTION = 'NOACTION'
USERCODE = 'USERCODE'
class astoria.common.disks.DiskTypeCalculator(default_usercode_entrypoint)[source]

Helper class to calculate the DiskType of a given disk drive.

Warning

A disk must only rely on itself and not other disks to determine it the type of the disk.

__init__(default_usercode_entrypoint)[source]

Initialise the DiskTypeCalculator.

Parameters:

default_usercode_entrypoint (str) – default entrypoint from astoria config

calculate(path)[source]

Calculate the DiskType of a drive given it’s mount path.

Parameters:

path (Path) – The mount path of the drive.

Return type:

DiskType

Returns:

The type of the disk.

Constraint Definitions

class astoria.common.disks.constraints.Constraint[source]

A constraint that a path can match.

abstract matches(path)[source]

Determine if the disk at the given path matches the constraint.

Parameters:

path (Path) – path to the mount point of the disk

Return type:

bool

class astoria.common.disks.constraints.FilePresentConstraint(filename)[source]

Ensure that a file is present on the disk.

This constraint will check that the path exists and contains the given file.

__init__(filename)[source]

Initialise the constraint class.

Parameters:

filename (str) – name of the file to find on the disk

matches(path)[source]

Determine if the disk at the given path matches the constraint.

Parameters:

path (Path) – path to the mount point of the disk

Return type:

bool

class astoria.common.disks.constraints.NumberOfFilesConstraint(n)[source]

Ensure that a certain number of files are present.

This can be used to ensure that there are no spurious files on the disk.

__init__(n)[source]

Initialise the constraint class.

Parameters:

n (int) – The number of files that should be on the disk.

matches(path)[source]

Determine if the disk at the given path matches the constraint.

Parameters:

path (Path) – path to the mount point of the disk

Return type:

bool

class astoria.common.disks.constraints.OrConstraint(a, b)[source]

Ensure that either of the given constraints match.

__init__(a, b)[source]

Initialise the constraint class.

Parameters:
matches(path)[source]

Determine if the disk at the given path matches the constraint.

Parameters:

path (Path) – path to the mount point of the disk

Return type:

bool

class astoria.common.disks.constraints.AndConstraint(a, b)[source]

Ensure that both of the constraints match.

__init__(a, b)[source]

Initialise the constraint class.

Parameters:
matches(path)[source]

Determine if the disk at the given path matches the constraint.

Parameters:

path (Path) – path to the mount point of the disk

Return type:

bool

class astoria.common.disks.constraints.NotConstraint(a)[source]

Ensure that the constraint does not match.

__init__(a)[source]

Initialise the constraint class.

Parameters:

a (Constraint) – The constraint to negate

matches(path)[source]

Determine if the disk at the given path matches the constraint.

Parameters:

path (Path) – path to the mount point of the disk

Return type:

bool

class astoria.common.disks.constraints.TrueConstraint[source]

A constraint that is always true.

Useful to create a default value when matching disks in order.

matches(_)[source]

Determine if the disk at the given path matches the constraint.

Parameters:

_ – path to the mount point of the disk. Not used.

Return type:

bool

class astoria.common.disks.constraints.FalseConstraint[source]

A constraint that is always false.

matches(_)[source]

Determine if the disk at the given path matches the constraint.

Parameters:

_ – path to the mount point of the disk. Not used.

Return type:

bool