quota_notifier.disk_utils

Utilities for fetching disk quota information.

Different quota objects (classes) are provided for different file system structures. The GenericQuota is generally applicable to any file system whose quota can be determined using the df commandline utility.

Quota classes may provide factory methods to facilitate creating instances based on simple user data. In all cases, these methods will return None if a quota is not found for the user.

Using QuotaFactory class is recommended when dynamically creating quota objects for varying paths, users, or filesystem types.

Module Contents

class quota_notifier.disk_utils.AbstractQuota(name: str, path: Path, user: User, size_used: int, size_limit: int)[source]

Base class for building object-oriented representations of file system quotas.

__init__(name: str, path: Path, user: User, size_used: int, size_limit: int) None[source]

Create a new quota from known system metrics

Parameters:
  • name – Human readable name of the file system

  • path – Mounted file system path

  • user – User that the quota is tied to

  • size_used – Disk space used by the user/group

  • size_limit – Maximum disk space allowed by the allocation

Raises:

ValueError – For a blank/empty name argument

property percentage: int

Return the current quota utilization as an integer percentage

abstract classmethod get_quota(name: str, path: Path, user: User) AbstractQuota | None[source]

Return a quota object for a given user and file path

Parameters:
  • name – Name of the file system

  • path – The file path for create a quota for

  • user – User that the quota is tied to

Returns:

An instance of the parent class or None if the allocation does not exist

static bytes_to_str(size: int) str[source]

Convert the given number of bytes to a human-readable string

Parameters:

size – An integer number of bytes

Returns:

A string representation of the given size with units

class quota_notifier.disk_utils.GenericQuota(name: str, path: Path, user: User, size_used: int, size_limit: int)[source]

The default quota object for most file system types

classmethod get_quota(name: str, path: Path, user: User) GenericQuota | None[source]

Return a quota object for a given user and file path

Parameters:
  • name – Name of the file system

  • path – The file path for create a quota for

  • user – User that the quota is tied to

Returns:

An instance of the parent class or None if the allocation does not exist

Raises:

RuntimeError – If something goes wrong communicating with the file system

class quota_notifier.disk_utils.BeeGFSQuota(name: str, path: Path, user: User, size_used: int, size_limit: int)[source]

Disk storage quota for a BeeGFS file system

classmethod get_quota(name: str, path: Path, user: User, storage_pool: int = 1) BeeGFSQuota | None[source]

Return a quota object for a given user and file path

Parameters:
  • name – Name of the file system

  • path – The mount location for the BeeGFS system

  • user – User that the quota is tied to

  • storage_pool – BeeGFS storagepoolid to create a quota for

Returns:

An instance of the parent class or None if the allocation does not exist

Raises:
  • FileNotFoundError – If the given file path does not exist

  • RuntimeError – If something goes wrong communicating with the file system

classmethod cache_quotas(name: str, path: Path, users: Iterable[User], storage_pool: int = 1) None[source]

Cache quota information for multiple users

Fetch and cache quota information for multiple users with a bulk BeeGFS query. Cached information is used to speed up future calls to the get_quota method.

Parameters:
  • name – Name of the file system

  • path – The mount location for the BeeGFS system

  • users – List of users to query for

  • storage_pool – BeeGFS storagepoolid to create a quota for

Yields:

Quota objects for each user having a quota

class quota_notifier.disk_utils.IhomeQuota(name: str, path: Path, user: User, size_used: int, size_limit: int)[source]

Disk storage quota for the ihome file system

classmethod get_quota(name: str, path: Path, user: User) IhomeQuota | None[source]

Return a quota object for a given user and file path

Parameters:
  • name – Name of the file system

  • path – The file path for create a quota for

  • user – User that the quota is tied to

Returns:

An instance of the parent class or None if the allocation does not exist

class quota_notifier.disk_utils.QuotaFactory(quota_type: str, name: str, path: Path, user: User, **kwargs)[source]

Factory object for dynamically creating quota instances of different types

class QuotaType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Map file system types to quota objects

generic = <class 'quota_notifier.disk_utils.GenericQuota'>
beegfs = <class 'quota_notifier.disk_utils.BeeGFSQuota'>
ihome = <class 'quota_notifier.disk_utils.IhomeQuota'>