注意
本文档适用于 Ceph 开发版本。
LibCephFS (Python)
The cephfs该 Python 模块提供对 CephFS 服务的访问。
API调用
该模块是围绕 libcephfs 的一个轻量级封装。
- class cephfs.DirEntry(d_ino, d_off, d_reclen, d_type, d_name, d_snapid)
- class cephfs.LibCephFS
libcephfs Python 封装
- abort_conn()
终止 mds 连接。
- chdir(path)
更改当前工作目录。
- 参数:
path-- 要切换到的当前工作目录的路径。
- chmod(path, 输出中所示)。)
更改目录模式。
- 参数:
path-- 要创建的目录的路径。这必须是一个绝对路径或相对于当前工作目录的相对路径。
输出中所示)。-- 目录创建后应具有的权限。
- 返回类型:
None
- chown(path, uid, gid, follow_symlink=True)
更改目录所有权
- 参数:
path-- 要更改的目录的路径。
uid-- 要设置的 uid
gid-- 要设置的 gid
follow_symlink-- 如果 @path 是一个符号链接,则对目标文件执行操作(默认)
- close(fd)
关闭已打开的文件。
- 参数:
fd-- 指向已打开文件的文件描述符。
- closedir(handle)
关闭已打开的目录。
- 参数:
handle-- 打开目录流句柄
- conf_get(选项)
将配置值作为字符串获取。
- 参数:
选项-- 要获取的配置选项
- conf_parse_argv(argv)
解析命令行参数并加载配置参数。
- 参数:
argv-- 参数列表
- conf_read_file(conffile=无)
从指定的配置文件加载 ceph 配置。
- 参数:
opt (conffile str) -- 要覆盖默认设置的 ceph.conf 的路径
- conf_set(选项, val)
从字符串设置配置值。
- 参数:
选项-- 要设置的配置选项
值-- 要设置的配置选项的值
- 创建(conf=无, conffile=-1, auth_id=无)
创建一个用于与 Ceph 交互的挂载句柄。所有 libcephfs 函数都在挂载信息句柄上操作。
- 参数:
opt (conf dict) -- 覆盖默认设置和 conffile
optional (conffile Union[int,字符串],) -- 要覆盖默认设置的 ceph.conf 的路径
- Auth_id str opt:
用于客户端实体的身份验证的 id
- debug_get_fd_caps(fd)
根据文件描述符获取当前分配给客户端的权限。
- 参数:
fd-- 要获取权限的文件描述符
- debug_get_file_caps(path)
根据路径获取当前分配给客户端的权限。
- 参数:
path-- 要获取权限的文件/目录的路径
- fallocate(fd, offset, length, 输出中所示)。=0)
为文件预分配或释放磁盘空间,用于字节范围。
- 参数:
fd-- 文件描述符的文件要 fallocate。
输出中所示)。-- 模式决定在给定的范围内执行的操作。默认操作(0)是返回 -EOPNOTSUPP,因为 cephfs 不会分配磁盘块来提供写保证。如果在模式中指定了 FALLOC_FL_KEEP_SIZE 标志,则文件大小不会改变。如果在模式中指定了 FALLOC_FL_PUNCH_HOLE 标志,则操作是释放空间并将字节范围清零。
offset-- 起始的字节范围。
length-- 范围的长度。
- fchmod(fd, 输出中所示)。)
根据文件描述符更改文件模式。
- 参数:
fd-- 要更改文件模式的文件描述符
输出中所示)。-- 要设置的权限。
- fchown(fd, uid, gid)
更改文件所有权
- 参数:
fd-- 要更改所有权的文件描述符
uid-- 要设置的 uid
gid-- 要设置的 gid
- fgetxattr(fd, name, size定位特定驱动器容量:=255)
根据文件的文件描述符获取扩展属性。
- 参数:
fd-- 指向文件的打开文件描述符
name-- 要获取的扩展属性名称
size定位特定驱动器容量:-- 预分配缓冲区的大小
- flistxattr(fd, size定位特定驱动器容量:=65536)
列出文件上设置的扩展属性键。
- 参数:
fd-- 指向文件的打开文件描述符。
size定位特定驱动器容量:-- 要填充扩展属性键的列表缓冲区的大小。
- flock(fd, operation, owner)
应用或移除建议锁。
- 参数:
fd-- 要更改建议锁的打开文件描述符。
operation-- 要在文件上执行的建议锁操作
owner-- 用户提供的所有者标识符(任意整数)
- fremovexattr(fd, name)
移除文件的扩展属性。
- 参数:
fd-- 指向文件的打开文件描述符。
name-- 要移除的扩展属性名称。
- fsetattrx(fd, dict_stx, mask)
设置文件的属性。
- 参数:
path-- 要设置属性的文件/目录的路径。
mask-- 所有已设置在 statx 结构中的 CEPH_SETATTR_* 值的掩码。
stx-- 一个必须包含要设置在文件上的属性值的 statx 结构的字典。
- fsetxattr(fd, name, 值, flags)
在文件上设置扩展属性。
- 参数:
fd-- 指向文件的打开文件描述符。
name-- 要设置的扩展属性名称。
值-- 扩展属性值的字节
- fstat(fd)
获取打开文件的扩展统计信息和属性。
- 参数:
fd-- 要获取统计信息的文件描述符。
- fsync(fd, syncdataonly)
将打开文件同步到持久媒体。
- 参数:
fd-- 要同步的文件描述符。
syncdataonly-- 一个布尔值,指示是否同步元数据和数据(0)或仅数据(1)。
- ftruncate(fd, size定位特定驱动器容量:)
将文件截断到给定大小。如果此操作导致文件扩展,则空字节将被填充为零。
- 参数:
path-- 要截断的文件的路径。
size定位特定驱动器容量:-- 文件的新大小。
- futime(fd, times=无)
为由描述符指向的文件设置访问和修改时间。
- 参数:
fd-- 打开文件的文件描述符
times-- 如果 times 不是 None,它必须是一个元组 (atime, mtime)
- futimens(fd, times=无)
为由描述符指向的文件设置访问和修改时间。
- 参数:
fd-- 打开文件的文件描述符
times-- 如果 times 不是 None,它必须是一个元组 (atime, mtime)
- futimes(fd, times=无)
为由描述符指向的文件设置访问和修改时间。
- 参数:
fd-- 打开文件的文件描述符
times-- 如果 times 不是 None,它必须是一个元组 (atime, mtime)
- get_addrs()
Get associated client addresses with this RADOS session.
- get_cap_return_timeout()
Get the amount of time that the client has to return caps
In the event that a client does not return its caps, the MDS may blocklist it after this timeout. Applications should check this value and ensure that they set the delegation timeout to a value lower than this.
- get_default_pool()
Get the default pool name and id of cephfs. This returns dict{pool_name, pool_id}.
- get_file_replication(fd)
Get the file replication information from an open file descriptor.
- 参数:
fd -- the open file descriptor referring to the file to get the replication information of.
- get_fscid()
Return the file system id for this fs client.
- get_instance_id()
Get a global id for current instance
- get_layout(fd)
Get the file layout from an open file descriptor.
- 参数:
fd -- the open file descriptor referring to the file to get the layout of.
- get_path_replication(path)
Get the file replication information given the path.
- 参数:
path -- the path of the file/directory to get the replication information of.
- get_pool_id(pool_name)
Get the id of the named pool.
- 参数:
pool_name -- the name of the pool.
- get_pool_replication(pool_id)
Get the pool replication factor.
- 参数:
pool_id -- the pool id to look up
- getcwd()
Get the current working directory.
- 返回类型:
bytes
- 返回:
the path to the current working directory
- getxattr(path, name, size定位特定驱动器容量:=255, follow_symlink=True)
Get an extended attribute.
- 参数:
path -- the path to the file
name-- 要获取的扩展属性名称
size定位特定驱动器容量:-- 预分配缓冲区的大小
- init()
Initialize the filesystem client (but do not mount the filesystem yet)
- lazyio(fd, enable)
Enable/disable lazyio for the file.
- 参数:
fd -- the file descriptor of the file for which to enable lazio.
enable -- a boolean to enable lazyio or disable lazyio.
- lazyio_propagate(fd, offset, count)
Flushes the write buffer for the file thereby propogating the buffered write to the file.
- 参数:
fd-- 要同步的文件描述符。
offset-- 起始的字节范围。
count -- the number of bytes starting from offset.
- lazyio_synchronize(fd, offset, count)
Flushes the write buffer for the file and invalidate the read cache. This allows a subsequent read operation to read and cache data directly from the file and hence everyone’s propagated writes would be visible.
- 参数:
fd-- 要同步的文件描述符。
offset-- 起始的字节范围。
count -- the number of bytes starting from offset.
- lchmod(path, 输出中所示)。)
Change file mode. If the path is a symbolic link, it won’t be dereferenced.
- 参数:
path -- the path of the file. This must be either an absolute path or a relative path off of the current working directory.
输出中所示)。 -- the permissions to be set .
- 返回类型:
None
- lchown(path, uid, gid)
Change ownership of a symbolic link
- 参数:
path -- the path of the symbolic link to change.
uid-- 要设置的 uid
gid-- 要设置的 gid
- lgetxattr(path, name, size定位特定驱动器容量:=255)
Get an extended attribute without following symbolic links. This function is identical to ceph_getxattr, but if the path refers to a symbolic link, we get the extended attributes of the symlink rather than the attributes of the file it points to.
- 参数:
path -- the path to the file
name-- 要获取的扩展属性名称
size定位特定驱动器容量:-- 预分配缓冲区的大小
- link(existing, newname)
Create a link.
- 参数:
existing-- 要链接到的现有文件/目录的路径。
newname-- 要链接到的新的文件/目录的路径。
- listxattr(path, size定位特定驱动器容量:=65536, follow_symlink=True)
列出文件上设置的扩展属性键。
- 参数:
path-- 文件的路径。
size定位特定驱动器容量:-- 要填充扩展属性键的列表缓冲区的大小。
- llistxattr(path, size定位特定驱动器容量:=65536)
List the extended attribute keys set on a file but do not follow symbolic link.
- 参数:
path-- 文件的路径。
size定位特定驱动器容量:-- 要填充扩展属性键的列表缓冲区的大小。
- lremovexattr(path, name)
Remove an extended attribute of a file but do not follow symbolic link.
- 参数:
path-- 文件的路径。
name-- 要移除的扩展属性名称。
- lseek(fd, offset, whence)
Set the file’s current position.
- 参数:
fd-- 要从中读取的已打开文件的文件描述符。
offset-- 文件中读取的偏移量。如果此值是负数,则函数从文件描述符的当前偏移量读取。
whence -- the flag to indicate what type of seeking to performs:SEEK_SET, SEEK_CUR, SEEK_END
- lsetxattr(path, name, 值, flags)
Set an extended attribute on a file but do not follow symbolic link.
- 参数:
path-- 文件的路径。
name-- 要设置的扩展属性名称。
值-- 扩展属性值的字节
- lstat(path)
Get a file’s extended statistics and attributes. If the file is a symbolic link, return the information of the link itself rather than the information of the file it points to.
- 参数:
path-- 要获取统计信息的文件或目录。
- lutimes(path, times=无)
Set access and modification time for a file. If the file is a symbolic link do not follow to the target.
- 参数:
path-- 要更改时间戳的文件路径
times-- 如果 times 不是 None,它必须是一个元组 (atime, mtime)
- mds_command(mds_spec, args, input_data)
- 返回:
3 元组输出状态 int,输出状态字符串,输出数据
- mds_command2(result, mds_spec, args, input_data=无, one_shot=False)
- Param:
result: 一个完成对象,其 complete 方法接受一个整数 rc,字节数组输出,和字节数组错误输出
- Param:
mds_spec: 发送命令到一个或多个 MDS 的身份(例如。“*”或“fsname:0”)
- Param:
args: JSON 编码的 MDS 命令
- Param:
input_data: 命令的可选输入数据
- Param:
one_shot: 可选布尔值,指示是否只尝试/发送一次命令
- 返回:
0 如果命令被发送或将要发送或引发异常
- mkdir(path, 输出中所示)。)
创建目录。
- 参数:
path-- 要创建的目录的路径。这必须是一个绝对路径或相对于当前工作目录的相对路径。
输出中所示)。-- 目录创建后应具有的权限。
- mkdirs(path, 输出中所示)。)
一口气创建多个目录。
- 参数:
path-- 应该创建的目录和子目录的完整路径。
输出中所示)。-- 目录创建后应具有的权限
- mknod(path, 输出中所示)。, rdev=0)
创建块设备或字符特殊文件。
- 参数:
path-- 特殊文件的路径。
输出中所示)。-- 要使用的权限和特殊文件的类型。类型可以是 stat.S_IFREG、stat.S_IFCHR、stat.S_IFBLK、stat.S_IFIFO。两者都应使用按位或组合。
rdev-- 如果文件类型是 stat.S_IFCHR 或 stat.S_IFBLK,则此参数指定新创建的设备特殊文件的主号和次号。否则,它被忽略。
- mksnap(path, name, 输出中所示)。, metadata={})
创建快照。
- 参数:
path-- 要快照的目录的路径。
name-- 快照名称
输出中所示)。-- 快照的权限
metadata-- 与快照一起存储的元数据键/值
- Raises:
- class:
TypeError
- Raises:
- class:
错误
- 返回类型:
int
- 返回:
成功为 0
- mount(mount_root=无, filesystem_name=无)
使用挂载的根路径的路径执行挂载。
- open(path, flags, 输出中所示)。=0)
创建和/或打开文件。
- 参数:
path-- 要打开的文件的路径。如果 flags 参数包括 O_CREAT,则文件将首先被创建然后再打开。
flags-- 控制文件创建/打开方式的一组选项掩码。
输出中所示)。-- 如果文件不存在并且 flags 中指定了 O_CREAT,则应放置在文件上的权限。
- opendir(path)
打开给定目录。
- 参数:
path-- 要打开的目录的路径名。必须是一个绝对路径或相对于当前工作目录的路径。
- 返回类型:
DirResult
- 返回:
打开目录流句柄
- opensnapdiff(root_path, rel_path, snap1name, snap2name)
打开给定目录。
- 参数:
path-- 要打开的目录的路径名。必须是一个绝对路径或相对于当前工作目录的路径。
- 返回类型:
SnapDiffHandle
- 返回:
打开目录流句柄
- preadv(fd, buffers, offset)
将数据写入文件。
- 参数:
fd-- 要从中读取的已打开文件的文件描述符
buffers-- 要从文件中读取的字节对象列表
offset-- 文件读取的偏移量。如果此值是负数,则函数从文件描述符的当前偏移量读取。
- pwritev(fd, buffers, offset)
将数据写入文件。
- 参数:
fd-- 要写入的已打开文件的文件描述符
buffers-- 要写入文件的字节对象列表
offset-- 文件写入的偏移量。如果此值是负数,则函数写入到文件描述符的当前偏移量。
- 读取(fd, offset, l)
从文件中读取数据。
- 参数:
fd-- 要从中读取的已打开文件的文件描述符。
offset-- 文件中读取的偏移量。如果此值是负数,则函数从文件描述符的当前偏移量读取。
l-- 指示读取类型的标志
- readdir(handle)
获取打开目录中的下一个条目。
- 参数:
handle-- 打开目录流句柄
- 返回类型:
Optional
[DirEntry
]- 返回:
下一个目录条目或 None 如果在目录末尾(或目录为空)。这个指针不应由调用者释放,并且仅在返回和下一次调用 readdir 或 closedir 之间安全访问。
- readlink(path, size定位特定驱动器容量:)
读取符号链接。
- 参数:
path-- 要读取的符号链接的路径
size定位特定驱动器容量:-- 缓冲区长度
- 返回类型:
bytes
- 返回:
缓冲区用于存储符号链接指向的文件的路径。
- removexattr(path, name, follow_symlink=True)
移除文件的扩展属性。
- 参数:
path-- 文件的路径。
name-- 要移除的扩展属性名称。
- rename(src, dst)
重命名文件或目录。
- 参数:
src-- 现有文件或目录的路径。
dst-- 新的文件或目录名称。
- rewinddir(handle)
将目录流回目录的开头。
- 参数:
handle-- 打开目录流句柄
- rmdir(path)
移除目录。
- 参数:
path-- 要移除的目录的路径。
- rmsnap(path, name)
移除快照。
- 参数:
path-- 要移除快照的目录的路径
name-- 快照名称
- Raises:
- class:
错误
- 返回类型:
int
- 返回:
成功为 0
- seekdir(handle, offset)
将目录流移动到由给定偏移量指定的位置。
- 参数:
handle-- 打开目录流句柄
offset-- 要移动目录流到的位置。这个偏移量应该是 telldir 返回的值。请注意,这个值不指目录中的第 n 个条目,并且不能使用加减操作来操作。
- set_mount_timeout(timeout)
设置挂载超时
- 参数:
timeout-- 挂载超时
- set_session_timeout(timeout)
设置 ceph 客户端会话超时。必须在挂载之前调用。
- 参数:
timeout-- 要设置的超时
- set_uuid(uuid)
设置 ceph 客户端 uuid。必须在挂载之前调用。
- 参数:
uuid-- 要设置的 uuid
- setattrx(path, dict_stx, mask, flags)
设置文件的属性。
- 参数:
path-- 要设置属性的文件/目录的路径。
mask-- 所有已设置在 statx 结构中的 CEPH_SETATTR_* 值的掩码。
stx-- 一个必须包含要设置在文件上的属性值的 statx 结构的字典。
flags-- AT_* 标志的掩码(目前仅尊重 AT_ATTR_NOFOLLOW)
- setxattr(path, name, 值, flags, follow_symlink=True)
在文件上设置扩展属性。
- 参数:
path-- 文件的路径。
name-- 要设置的扩展属性名称。
值-- 扩展属性值的字节
- shutdown()
卸载并销毁 ceph 挂载句柄。
- snap_info(path)
获取快照信息
- 参数:
path-- 快照路径
- Raises:
- class:
错误
- 返回类型:
Dict
[str
,Any
]- 返回:
快照元数据
- stat(path, follow_symlink=True)
获取文件的扩展统计信息和属性。
- 参数:
path-- 要获取统计信息的文件或目录。
- statfs(path)
对 ceph 文件系统执行 statfs。此调用将文件系统范围的统计信息填充到传入的缓冲区中。
- 参数:
path-- 挂载文件系统中任何路径
- statx(path, mask, flag)
获取文件的扩展统计信息和属性。
- 参数:
path-- 要获取统计信息的文件或目录。
mask-- 显示设计的属性 CEPH_STATX_* 标志的 want 位字段。
flag-- 可以用来设置 AT_* 修饰符标志(AT_STATX_SYNC_AS_STAT、AT_STATX_FORCE_SYNC、AT_STATX_DONT_SYNC 和 AT_SYMLINK_NOFOLLOW)
- symlink(existing, newname)
创建符号链接。
- 参数:
existing-- 要链接到的现有文件/目录的路径。
newname-- 要链接到的新的文件/目录的路径。
- sync_fs()
将所有文件系统数据同步到持久媒体
- telldir(handle)
获取目录流的当前位置。
- 参数:
handle-- 打开目录流句柄
- 返回值:
目录流的当前位置。注意,ceph_telldir 返回的偏移量没有特定的顺序(不能与不等式比较)。
- truncate(path, size定位特定驱动器容量:)
将文件截断到给定大小。如果此操作导致文件扩展,则空字节将被填充为零。
- 参数:
path-- 要截断的文件的路径。
size定位特定驱动器容量:-- 文件的新大小。
- unlink(path)
删除文件、链接或符号链接。如果文件/链接指向它的链接有多个,则文件不会从命名空间中消失,直到所有引用都被移除。
- 参数:
path-- 要删除的文件或链接的路径。
- unmount()
卸载挂载句柄。
- utime(path, times=无)
为路径设置访问和修改时间
- 参数:
path-- 要更改时间戳的文件路径
times-- 如果 times 不是 None,它必须是一个元组 (atime, mtime)
- utimes(path, times=无, follow_symlink=True)
为路径设置访问和修改时间
- 参数:
path-- 要更改时间戳的文件路径
times-- 如果 times 不是 None,它必须是一个元组 (atime, mtime)
follow_symlink-- 如果 @path 是一个符号链接,则对目标文件执行操作(默认)
- version()
获取 C 库的版本号。
libcephfs
a元组- 返回:
libcephfs 版本的组件
(major, minor, extra)
components of the libcephfs version
- write(fd, buf, offset)
将数据写入文件。
- 参数:
fd-- 要写入的已打开文件的文件描述符
buf-- 要写入文件的数据
offset-- 文件写入的偏移量。如果此值是负数,则函数写入到文件描述符的当前偏移量。
由 Ceph 基金会带给您
Ceph 文档是一个社区资源,由非盈利的 Ceph 基金会资助和托管Ceph Foundation. 如果您想支持这一点和我们的其他工作,请考虑加入现在加入.