-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCephFSConnector.py
More file actions
46 lines (30 loc) · 932 Bytes
/
Copy pathCephFSConnector.py
File metadata and controls
46 lines (30 loc) · 932 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import cephfs
fileSys = cephfs.LibCephFS()
# Load the ceph.conf from the default location. Pass in the path of ceph.conf if it's in a different location.
fileSys.conf_read_file()
fileSys.conf_set("client_permissions", "0")
# Mount the filesystem to the default location "/"
fileSys.mount()
# Make a dir, change the dir, and get the current working dir.
fileSys.mkdir('testDir', 777)
fileSys.chdir('testDir')
fileSys.getcwd()
# Create and write a file
fd = fileSys.open('/testDir/my.txt','w')
fileSys.write(fd,b'Hello World!',-1)
fileSys.close(fd)
# Read and print the content of the file
fileSys.open('/testDir/my.txt', 'r')
content = fileSys.read(fd,-1,10)
print(content)
# Check the metadata of the file
stat = fileSys.fstat(fd)
print(stat)
# Close the file
fileSys.close(fd)
# Remove the file and dir
fileSys.unlink('my.txt')
fileSys.chdir('/')
fileSys.rmdir('testDir')
# Unmount the filesystem
fileSys.unmount()