Project

General

Profile

Actions

Module quota

This is a simple wrapper for the quotactl system call, allowing getting and setting quota directly from python (no need to call an external program and parse its output).

It's still extremely primordial, providing limited functionality and working only with Linux quota version 2. It has been tested on Debian Etch and Lenny. As my first attempt to write a module it is also very far from elegance (and no pythonic at all).

Installation

To install the module you need the following steps (provided you have standard development tools installed):

svn co https://labs.truelite.it/svn/packages/quotamodule
cd quotamodule/
python setup.py build

then you can copy the quota.so module (look inside the created build directory) to its destination (if you want to just check it with python you can use your current working directory).

Use

The module provides the following functions (interface is preliminar, it will be probably changed in future releases):

Function Arguments Description
get_user_quota uid (integer), device (string) get user quota
get_group_quota gid (integer), device (string) get group quota
set_user_block_quota uid (integer), device (string), (soft,hard) *tuple of two int set block user quota
set_user_inode_quota uid (integer), device (string), (soft,hard) *tuple of two int set inode user quota
set_group_block_quota gid (integer), device (string), (soft,hard) *tuple of two int set block group quota
set_group_inode_quota gid (integer), device (string), (soft,hard) *tuple of two int set inode group quota
get_user_info device (string) get user quota info (grace time and flags)
get_group_info device (string) get group quota info (grace time and flags)
set_user_block_grace device (string), grace (integer) set user block grace
set_group_block_grace device (string), grace (integer) set group block grace
set_user_inode_grace device (string), grace (integer) set user inode grace
set_group_inode_grace device (string), grace (integer) set group inode grace

User or group can be only specified by numeric ID (uid or gid). The device string must be the device pathname for the filesystem on which we want to operate. Grace time must be specified in seconds.

When setting quotas they must be provided as a tuple of two integer values (first for soft limit, second for hard limit). They will be applied to inode/block, user/group according to the chosen function.

Reading quota data will give back a tuple of two dictionaries. First dictionary is for block quota data, second for inode quota data. Both dictionaries will have the same string keys according to the following table:

Key Desctiption
used integer with the actual usage of the resource (blocks or inodes number)
quota a two integers tuple with the current value of the quota (soft limit, hard limit)
grace an integer with the time_t value of the grace expiration (if active)

Reading quota info give back a tuple of three element, first is grace time for block in seconds, second is grace time for inode and third is the flags value.

Error handling

All error in calling the quotactl function will raise an OSError exception passing the error value in errno.

Updated by Simone Piccardi over 12 years ago ยท 2 revisions