Project: Curve (Runtime / Cloud Native Storage)
File: curve-client-python-api_en.md

```python import curvefs cbd1 = curvefs.CBDClient() cbd2 = curvefs.CBDClient() ``` ```python import curvefs cbd = curvefs.CBDClient() cbd.Init("/etc/curve/client.conf") ``` ```python import curvefs cbd = curvefs.CBDClient() cbd.Init("/etc/curve/client.conf") # subsequent examples omit the initialization process user = curvefs.UserInfo_t() user.owner = "curve" user.password = "" # when the password is empty, it can be omitted cbd.Create("/curve", user, 1010241024*1024) typedef struct UserInfo { char owner[256]; # username char password[256]; # password } UserInfo_t; ``` ```python user = curvefs.UserInfo_t() user.owner = "curve" finfo = curvefs.FileInfo_t() cbd.StatFile("/curve", user, finfo) print finfo.filetype print finfo.length print finfo.ctime typedef struct FileInfo { uint64_t id; uint64_t parentid; int filetype; # volume type uint64_t length; # volume size uint64_t ctime; # volume create time char filename[256]; # volume name char owner[256]; # volume owner int fileStatus; # volume status } FileInfo_t; ``` ```python user = curvefs.UserInfo_t() user.owner = "curve" cbd.Extend("/curve", user, 2010241024*1024) finfo = curvefs.FileInfo_t() cbd.StatFile("/curve", user, finfo) print finfo.length ``` ```python user = curvefs.UserInfo_t() user.owner = "user1" fd = cbd.Open("/tmp1", user) cbd.Close(fd) ``` ```python user = curvefs.UserInfo_t() user.owner = "user1" fd = cbd.Open("/tmp1", user) cbd.Write(fd, "aaaaaaaa"*512, 0, 4096) cbd.Write(fd, "bbbbbbbb"*512, 4096, 4096) cbd.Read(fd"", 0, 4096) cbd.Close(fd) ``` Note: The current python api does not support asynchronous reading and writing ```python user = curvefs.UserInfo_t() user.owner = "curve" cbd.Unlink("/curve", user) ``` ```python user = curvefs.UserInfo_t() user.owner = "curve" cbd.Recover("/curve", user, 0) ``` ```python user = curvefs.UserInfo_t() user.owner = "curve" cbd.Rename(user, "/curve", "/curve-new") ``` ```python user = curvefs.UserInfo_t() user.owner = "curve" cbd.Mkdir("/curvedir", user) ``` ```python user = curvefs.UserInfo_t() user.owner = "curve" cbd.Rmdir("/curvedir", user) ``` ```python files = cbd.Listdir("/test", user) for f in files: print f ``` ```python clusterId = cbd.GetClusterId() print clusterId ``` ```python cbd.UnInit() ``` | Code | Message | description | | :--: | :-- | | | 0 | OK | success | | -1 | EXISTS | file or directory exists | | -2 | FAILED | fail | | -3 | DISABLEDIO | disable io | | -4 | AUTHFAIL | authentication failed | | -5 | DELETING | deleting | | -6 | NOTEXIST | file not exist | | -7 | UNDER_SNAPSHOT | under snapshot | | -8 | NOT_UNDERSNAPSHOT | not under snapshot | | -9 | DELETE_ERROR | delete error | | -10 | NOT_ALLOCATE | segment not allocated | | -11 | NOT_SUPPORT | operation not supported | | -12 | NOT_EMPTY | directory not empty | | -13 | NOSHRINKBIGGER_FILE | no shrinkage | | -14 | SESSION_NOTEXISTS | session not exist | | -15 | FILE_OCCUPIED | file occupied | | -16 | PARAM_ERROR | parameter error | | -17 | INTERNAL_ERROR | internal error | | -18 | CRC_ERROR | CRC error | | -19 | INVALID_REQUEST | parameter invalid | | -20 | DISK_FAIL | disk fail | | -21 | NO_SPACE | no space | | -22 | NOT_ALIGNED | io not aligned | | -23 | BAD_FD | file is being closed, fd unavailable | | -24 | LENGTHNOTSUPPORT | file length is not supported | | -25 | SESSIONNOTEXIST | session not exist, duplicate with -14 | | -26 | STATUSNOTMATCH | status error | | -27 | DELETEBEINGCLONED | delete the file being cloned | | -28 | CLIENTNOTSUPPORT_SNAPSHOT | this version of client not support snapshot | | -29 | SNAPSHOT_FROZEN | snapshot is disabled | | -100 | UNKNOWN | unknown error |