quotactl的capi的简单python包装器

PyQuota的Python项目详细描述


pyquota

pyquota是一个简单的python包装器,用于quotactl的c api。

支持的内核版本:>=2.4.22, <5

C API中支持的命令:

  • Q_QUOTAON
  • Q_QUOTAOFF
  • Q_GETQUOTA
  • Q_GETNEXTQUOTA(需要内核>;=4.6)
  • Q_SETQUOTA
  • Q_GETINFO
  • Q_SETINFO
  • Q_GETFMT
  • Q_SYNC

目前,由于缺少文档和测试环境,不支持任何用于xfs文件系统的命令,例如Q_XQUOTAON

安装

pip install pyquota

用法

对于上面列出的每个受支持的命令,此包提供3个python方法,对应于用户配额、组配额和项目配额的操作。项目配额方法要求内核>;=4.1。

为了便于说明,这里只提供用户配额方法的示例。若要使用组/项目配额方法,只需将方法名称中的“user”替换为“group”或“project”。

# Import packageimportpyquotaaspq# Turn on user quota for a filesystempq.user_quota_on("/dev/sda1",pq.QFMT_VFS_V0,"/aquota.user")# device path, quota format, quota file path # quota format can be either pq.QFMT_VFS_OLD, pq.QFMT_VFS_V0 or pq.QFMT_VFS_V1.# Turn off user quota for a filesystempq.user_quota_off("/dev/sda1")# Get quota of a user on a filesystemquota=pq.get_user_quota("/dev/sda1",1000)# 1000 is the uid, returns a tuple of 8 integersblock_hard_limit=quota[0]# unit: disk quota block (1024 Bytes)block_soft_limit=quota[1]# unit: disk quota block (1024 Bytes)block_current=quota[2]# unit: block (1 Byte)inode_hard_limit=quota[3]inode_soft_limit=quota[4]inode_current=quota[5]block_time=quota[6]# time limit for excessive disk useinode_time=quota[7]# time limit for excessive files# Get quota of the next user, whose ID is greater than or equal to the specified ID, on a filesystemquota=pq.get_next_user_quota("/dev/sda1",1000)# returns a tuple of 9 integers. # The first 8 integers are the same as the result of pg.get_user_quota while the last integer is the user id. uid=quota[8]# Set quota of a user on a filesystempq.set_user_quota("/dev/sda1",1000,102400,92160,0,0)# hard block limit 100MB, soft block limit 90MB, no inode limits # Get information about the user quotafile for a filesysteminfo=pq.get_user_quota_info("/dev/sda1")# returns a tuple of 3 integersblock_grace=info[0]# time before block soft limit becomes hard limit. (unit: second)inode_grace=info[1]# time before inode soft limit becomes hard limit. (unit: second)flags=info[2]# flags for quotafileis_root_squash_enabled=bool(flags&pq.DQF_ROOT_SQUASH)is_stored_in_system_file=bool(flags&pq.DQF_SYS_FILE)# Set information about the user quotafile for a filesystempq.set_user_quota_info("/dev/sda1",604800,604800,0)# set both block grace and inode grace to 1 week (7*24*60*60), set flags as empty # Get quota format used for user quotas on a filesystemfmt=pq.get_user_quota_format("/dev/sda1")# returns an integer # fmt should be either pq.QFMT_VFS_OLD, pq.QFMT_VFS_V0 or pq.QFMT_VFS_V1# Update the on-disk copy of user quota usages for a filesystempq.sync_user_quotas("/dev/sda1")# Update the on-disk copy of user quota usages for all filesystems with active quotaspq.sync_user_quotas(None)

由于这个包只是C API的包装,它几乎保持了原始的风格和输入/输出格式。因此,如果您想了解这些命令的具体功能、参数的含义和返回值的含义,请阅读man page

错误消息

来自C API的任何内部错误都将转换为一个pyquota.APIError实例,该实例具有符合ERRORS section in the man page的文本描述。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
泛型Java将参数约束到公共超类   java Spring引导:在构造函数中加载属性文件并用作autowire注释   java中的优先级队列顺序错误。util。优先级队列和特定比较器   带有Java Sprint引导REST的Google应用程序引擎标准在GCLOUD服务器中不起作用   安卓从Java代码中检索变量并将其作为参数分配给TestNG   用于读取列表值的Java JSON对象   java Hibernate映射:实体映射中的重复列   多线程。start()不从Java中的父线程分派   java Android facebook webdialog网络错误(netstack:lib_mgr错误)   http使用Java阻止网站   java DynamicAsper:访问连接报表中动态列的值   java如何分离文件中的每个单词,并在表中显示每个单词和每个单词的编号?   如何打包和部署EclipseJava应用程序?   java使用Mule Anypoint,我想实现没有flowref的功能   java Kafka consumer ClassNotFoundException   java错误捕获帮助;消息不断重复   javaspring,Thymeleaf和CSS如何给错误着色   javascript如何在java中实现反向ajax   如何通过UDP连接从java数据包中读取序列号?