LibCephFS (Python)

The cephfs python module provides access to CephFS service.

API calls

This module is a thin wrapper around libcephfs.

class cephfs.DirEntry
class cephfs.LibCephFS

libcephfs python wrapper

abort_conn()

Abort mds connections.

chdir()

Change the current working directory.

:param path the path to the working directory to change into.

chmod()

Change directory mode.

Parameters
  • path – the path of the directory to create. This must be either an absolute path or a relative path off of the current working directory.

  • mode – the permissions the directory should have once created.

chown()

Change directory ownership

Parameters
  • path – the path of the directory to change.

  • uid – the uid to set

  • gid – the gid to set

  • follow_symlink – perform the operation on the target file if @path is a symbolic link (default)

close()

Close the open file.

Parameters

fd – the file descriptor referring to the open file.

closedir()

Close the open directory.

Parameters

handle – the open directory stream handle

conf_get()

Gets the configuration value as a string.

Parameters

option – the config option to get

conf_parse_argv()

Parse the command line arguments and load the configuration parameters.

Parameters

argv – the argument list

conf_read_file()

Load the ceph configuration from the specified config file.

Parameters

str opt (conffile) – the path to ceph.conf to override the default settings

conf_set()

Sets a configuration value from a string.

Parameters
  • option – the configuration option to set

  • value – the value of the configuration option to set

create()

Create a mount handle for interacting with Ceph. All libcephfs functions operate on a mount info handle.

Parameters
  • dict opt (conf) – settings overriding the default ones and conffile

  • str opt (conffile) – the path to ceph.conf to override the default settings

Auth_id str opt

the id used to authenticate the client entity

flock()

Apply or remove an advisory lock.

Parameters
  • fd – the open file descriptor to change advisory lock.

  • operation – the advisory lock operation to be performed on the file

  • owner – the user-supplied owner identifier (an arbitrary integer)

fstat()

Get an open file’s extended statistics and attributes.

Parameters

fd – the file descriptor of the file to get statistics of.

fsync()

Synchronize an open file to persistent media.

Parameters
  • fd – the file descriptor of the file to sync.

  • syncdataonly – a boolean whether to synchronize metadata and data (0) or just data (1).

futime()

Set access and modification time for a file pointed by descriptor

Parameters
  • fd – file descriptor of the open file

  • times – if times is not None, it must be a tuple (atime, mtime)

futimens()

Set access and modification time for a file pointer by descriptor

Parameters
  • fd – file descriptor of the open file

  • times – if times is not None, it must be a tuple (atime, mtime)

futimes()

Set access and modification time for a file pointer by descriptor

Parameters
  • fd – file descriptor of the open file

  • times – if times is not None, it must be a tuple (atime, mtime)

get_addrs()

Get associated client addresses with this RADOS session.

get_instance_id()

Get a global id for current instance

getcwd()

Get the current working directory.

:rtype the path to the current working directory

getxattr()

Get an extended attribute.

Parameters
  • path – the path to the file

  • name – the name of the extended attribute to get

  • size – the size of the pre-allocated buffer

init()

Initialize the filesystem client (but do not mount the filesystem yet)

lchown()

Change ownership of a symbolic link :param path: the path of the symbolic link to change. :param uid: the uid to set :param gid: the gid to set

Create a link.

Parameters
  • existing – the path to the existing file/directory to link to.

  • newname – the path to the new file/directory to link from.

listxattr()

List the extended attribute keys set on a file.

Parameters
  • path – path of the file.

  • size – the size of list buffer to be filled with extended attribute keys.

lseek()

Set the file’s current position.

Parameters
  • fd – the file descriptor of the open file to read from.

  • offset – the offset in the file to read from. If this value is negative, the function reads from the current offset of the file descriptor.

  • whence – the flag to indicate what type of seeking to performs:SEEK_SET, SEEK_CUR, SEEK_END

lstat()

Get a file’s extended statistics and attributes. When file’s a symbolic link, return the informaion of the link itself rather than that of the file it points too.

Parameters

path – the file or directory to get the statistics of.

lutimes()

Set access and modification time for a file. If the file is a symbolic link do not follow to the target.

Parameters
  • path – file path for which timestamps have to be changed

  • times – if times is not None, it must be a tuple (atime, mtime)

mds_command()

:return 3-tuple of output status int, output status string, output data

mkdir()

Create a directory.

Parameters
  • path – the path of the directory to create. This must be either an absolute path or a relative path off of the current working directory.

  • mode – the permissions the directory should have once created.

mkdirs()

Create multiple directories at once.

Parameters
  • path – the full path of directories and sub-directories that should be created.

  • mode – the permissions the directory should have once created

mount()

Perform a mount using the path for the root of the mount.

open()

Create and/or open a file.

Parameters
  • path – the path of the file to open. If the flags parameter includes O_CREAT, the file will first be created before opening.

  • flags – set of option masks that control how the file is created/opened.

  • mode – the permissions to place on the file if the file does not exist and O_CREAT is specified in the flags.

opendir()

Open the given directory.

Parameters

path – the path name of the directory to open. Must be either an absolute path or a path relative to the current working directory.

Rtype handle

the open directory stream handle

read()

Read data from the file.

Parameters
  • fd – the file descriptor of the open file to read from.

  • offset – the offset in the file to read from. If this value is negative, the function reads from the current offset of the file descriptor.

  • l – the flag to indicate what type of seeking to perform

readdir()

Get the next entry in an open directory.

Parameters

handle – the open directory stream handle

Rtype dentry

the next directory entry or None if at the end of the directory (or the directory is empty. This pointer should not be freed by the caller, and is only safe to access between return and the next call to readdir or closedir.

Read a symbolic link.

Parameters
  • path – the path to the symlink to read

  • size – the length of the buffer

Rtype buf

buffer to hold the path of the file that the symlink points to.

removexattr()

Remove an extended attribute of a file.

Parameters
  • path – path of the file.

  • name – name of the extended attribute to remove.

rename()

Rename a file or directory.

Parameters
  • src – the path to the existing file or directory.

  • dst – the new name of the file or directory.

rmdir()

Remove a directory.

Parameters

path – the path of the directory to remove.

setxattr()

Set an extended attribute on a file.

Parameters
  • path – the path to the file.

  • name – the name of the extended attribute to set.

  • value – the bytes of the extended attribute value

shutdown()

Unmount and destroy the ceph mount handle.

stat()

Get a file’s extended statistics and attributes.

Parameters

path – the file or directory to get the statistics of.

statfs()

Perform a statfs on the ceph file system. This call fills in file system wide statistics into the passed in buffer.

Parameters

path – any path within the mounted filesystem

statx()

Get a file’s extended statistics and attributes.

Parameters
  • path – the file or directory to get the statistics of.

  • mask – want bitfield of CEPH_STATX_* flags showing designed attributes.

  • flag – bitfield that can be used to set AT_* modifier flags (only AT_NO_ATTR_SYNC and AT_SYMLINK_NOFOLLOW)

Creates a symbolic link.

Parameters
  • existing – the path to the existing file/directory to link to.

  • newname – the path to the new file/directory to link from.

sync_fs()

Synchronize all filesystem data to persistent media

Removes a file, link, or symbolic link. If the file/link has multiple links to it, the file will not disappear from the namespace until all references to it are removed.

Parameters

path – the path of the file or link to unlink.

unmount()

Unmount a mount handle.

utime()

Set access and modification time for path

Parameters
  • path – file path for which timestamps have to be changed

  • times – if times is not None, it must be a tuple (atime, mtime)

utimes()

Set access and modification time for path

Parameters
  • path – file path for which timestamps have to be changed

  • times – if times is not None, it must be a tuple (atime, mtime)

  • follow_symlink – perform the operation on the target file if @path is a symbolic link (default)

version()

Get the version number of the libcephfs C library.

Returns

a tuple of (major, minor, extra) components of the libcephfs version

write()

Write data to a file.

Parameters
  • fd – the file descriptor of the open file to write to

  • buf – the bytes to write to the file

  • offset – the offset of the file write into. If this value is negative, the function writes to the current offset of the file descriptor.