Progetto

Generale

Profilo

Actions

EnQuotaModule » Cronologia » Versione 3

« Precedente | Versione 3/7 (diff) | Successivo »
Amministratore Truelite, 10-06-2010 17:14


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/cyrcus/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

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.

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 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)

=== Error handling ===

All error in calling the {{{quotactl}}} function will raise a {{{OSError}}} exception passing the error value in {{{errno}}}.

Aggiornato da Amministratore Truelite quasi 14 anni fa · 3 revisions