]>
git.proxmox.com Git - ceph.git/blob - ceph/src/ceph-volume/ceph_volume/util/system.py
6 from ceph_volume
import process
7 from . import as_string
10 # TODO: get these out of here and into a common area for others to consume
11 if platform
.system() == 'FreeBSD':
13 DEFAULT_FS_TYPE
= 'zfs'
14 PROCDIR
= '/compat/linux/proc'
15 # FreeBSD does not have blockdevices any more
20 DEFAULT_FS_TYPE
= 'xfs'
22 BLOCKDIR
= '/sys/block'
27 return str(uuid
.uuid4())
30 def get_ceph_user_ids():
32 Return the id and gid of the ceph user
35 user
= pwd
.getpwnam('ceph')
37 # is this even possible?
38 raise RuntimeError('"ceph" user is not available in the current system')
39 return user
[2], user
[3]
42 def mkdir_p(path
, chown
=True):
44 A `mkdir -p` that defaults to chown the path to the ceph user
49 if e
.errno
== errno
.EEXIST
:
54 uid
, gid
= get_ceph_user_ids()
55 os
.chown(path
, uid
, gid
)
58 def chown(path
, recursive
=True):
60 ``chown`` a path to the ceph user (uid and guid fetched at runtime)
62 uid
, gid
= get_ceph_user_ids()
63 if os
.path
.islink(path
):
64 path
= os
.path
.realpath(path
)
66 process
.run(['chown', '-R', 'ceph:ceph', path
])
68 os
.chown(path
, uid
, gid
)
71 def is_mounted(source
, destination
=None):
73 Check if the given device is mounted, optionally validating destination.
74 This relies on absolute path devices, it will ignore non-absolute
77 tmpfs /run tmpfs rw,seclabel,nosuid,nodev,mode=755 0 0
79 But will parse paths that are absolute like::
81 /dev/sdc2 /boot xfs rw,attr2,inode64,noquota 0 0
83 When destination is passed in, it will check that the entry where the
84 source appears is mounted to where destination defines. This is useful so
85 that an error message can report that a source is not mounted at an
88 dev
= os
.path
.realpath(source
)
89 with
open(PROCDIR
+ '/mounts', 'rb') as proc_mounts
:
90 for line
in proc_mounts
:
94 mounted_device
= fields
[0]
95 mounted_path
= fields
[1]
96 if os
.path
.isabs(mounted_device
) and os
.path
.exists(mounted_device
):
97 mounted_device
= os
.path
.realpath(mounted_device
)
98 if as_string(mounted_device
) == dev
:
100 destination
= os
.path
.realpath(destination
)
101 return destination
== as_string(os
.path
.realpath(mounted_path
))