Progetto

Generale

Profilo

EnQuotaModule » Cronologia » Versione 5

Simone Piccardi, 22-12-2010 19:10

1 5 Simone Piccardi
h1. Module quota
2 1 Amministratore Truelite
3 5 Simone Piccardi
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). 
4 4 Amministratore Truelite
5
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). 
6 1 Amministratore Truelite
7 5 Simone Piccardi
h2. Installation
8 4 Amministratore Truelite
9
To install the module you need the following steps (provided you have standard development tools installed):
10 5 Simone Piccardi
11 1 Amministratore Truelite
<pre>
12 4 Amministratore Truelite
svn co https://labs.truelite.it/svn/cyrcus/quotamodule
13 1 Amministratore Truelite
cd quotamodule/
14
python setup.py build
15
</pre>
16
17 5 Simone Piccardi
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). 
18 4 Amministratore Truelite
19 5 Simone Piccardi
h2. Use
20 1 Amministratore Truelite
21
The module provides the following functions (interface is preliminar, it will be probably changed in future releases):
22
23 5 Simone Piccardi
|_.Function |_.Arguments |._Description|
24
|@get_user_quota@|@uid@ (integer), @device@ (string)| get user quota|
25
|@get_group_quota@|@gid@ (integer), @device@ (string)| get group quota|
26
|@set_user_block_quota@|@uid@ (integer), @device@ (string), @(soft,hard)@ *tuple of two int | set block user quota|
27
|@set_user_inode_quota@|@uid@ (integer), @device@ (string), @(soft,hard)@ *tuple of two int | set inode user quota|
28
|@set_group_block_quota@|@gid@ (integer), @device@ (string), @(soft,hard)@ *tuple of two int | set block group quota|
29
|@set_group_inode_quota@|@gid@ (integer), @device@ (string), @(soft,hard)@ *tuple of two int | set inode group quota|
30 4 Amministratore Truelite
31 5 Simone Piccardi
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. 
32 1 Amministratore Truelite
33
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. 
34
 
35
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:
36 4 Amministratore Truelite
37 5 Simone Piccardi
|_.Key|_.Desctiption|
38
|used| integer with the actual usage of the resource (blocks or inodes number)||
39
|quota| a two integers tuple with the current value of the quota (soft limit, hard limit) ||
40
|grace| an integer with the @time_t@ value of the grace expiration (if active)||
41 1 Amministratore Truelite
42 4 Amministratore Truelite
43 5 Simone Piccardi
h2. Error handling
44 4 Amministratore Truelite
45 5 Simone Piccardi
All error in calling the @quotactl@ function will raise an @OSError@ exception passing the error value in @errno@.