]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/volumes/fs/subvolspec.py
import 14.2.4 nautilus point release
[ceph.git] / ceph / src / pybind / mgr / volumes / fs / subvolspec.py
CommitLineData
81eedcae 1import os
494da23a 2import uuid
81eedcae
TL
3
4class SubvolumeSpec(object):
5 """
6 Specification of a subvolume, identified by (subvolume-id, group-id) tuple. Add fields as
7 required...
8 """
9
10 # where shall we (by default) create subvolumes
11 DEFAULT_SUBVOL_PREFIX = "/volumes"
12 # and the default namespace
13 DEFAULT_NS_PREFIX = "fsvolumens_"
14
15 # Reserved subvolume group name which we use in paths for subvolumes
16 # that are not assigned to a group (i.e. created with group=None)
17 NO_GROUP_NAME = "_nogroup"
18
19 def __init__(self, subvolumeid, groupid, subvolume_prefix=None, pool_ns_prefix=None):
20 assert groupid != SubvolumeSpec.NO_GROUP_NAME
21
22 self.subvolumeid = subvolumeid
23 self.groupid = groupid if groupid is not None else SubvolumeSpec.NO_GROUP_NAME
24 self.subvolume_prefix = subvolume_prefix if subvolume_prefix else SubvolumeSpec.DEFAULT_SUBVOL_PREFIX
25 self.pool_ns_prefix = pool_ns_prefix if pool_ns_prefix else SubvolumeSpec.DEFAULT_NS_PREFIX
26
27 def is_default_group(self):
28 """
29 Is the group the default group?
30 """
31 return self.groupid == SubvolumeSpec.NO_GROUP_NAME
32
33 @property
34 def subvolume_id(self):
35 """
36 Return the subvolume-id from the subvolume specification
37 """
38 return self.subvolumeid
39
40 @property
41 def group_id(self):
42 """
43 Return the group-id from the subvolume secification
44 """
45 return self.groupid
46
47 @property
48 def subvolume_path(self):
49 """
50 return the subvolume path from subvolume specification
51 """
494da23a 52 return os.path.join(self.group_path, self.subvolumeid.encode('utf-8'))
81eedcae
TL
53
54 @property
55 def group_path(self):
56 """
57 return the group path from subvolume specification
58 """
494da23a 59 return os.path.join(self.subvolume_prefix.encode('utf-8'), self.groupid.encode('utf-8'))
81eedcae
TL
60
61 @property
62 def trash_path(self):
63 """
64 return the trash path from subvolume specification
65 """
494da23a 66 return os.path.join(self.subvolume_prefix.encode('utf-8'), b"_deleting", self.subvolumeid.encode('utf-8'))
81eedcae
TL
67
68 @property
494da23a 69 def unique_trash_path(self):
81eedcae 70 """
494da23a 71 return a unique trash directory entry path
81eedcae 72 """
494da23a 73 return os.path.join(self.subvolume_prefix.encode('utf-8'), b"_deleting", str(uuid.uuid4()).encode('utf-8'))
81eedcae
TL
74
75 @property
494da23a 76 def fs_namespace(self):
81eedcae 77 """
494da23a 78 return a filesystem namespace by stashing pool namespace prefix and subvolume-id
81eedcae 79 """
494da23a 80 return "{0}{1}".format(self.pool_ns_prefix, self.subvolumeid)
81eedcae
TL
81
82 @property
83 def trash_dir(self):
84 """
85 return the trash directory path
86 """
494da23a 87 return os.path.join(self.subvolume_prefix.encode('utf-8'), b"_deleting")
81eedcae
TL
88
89 def make_subvol_snap_path(self, snapdir, snapname):
90 """
91 return the subvolume snapshot path for a given snapshot name
92 """
93 return os.path.join(self.subvolume_path, snapdir, snapname)
94
95 def make_group_snap_path(self, snapdir, snapname):
96 """
97 return the group snapshot path for a given snapshot name
98 """
99 return os.path.join(self.group_path, snapdir, snapname)
100
101 def __str__(self):
102 return "{0}/{1}".format(self.groupid, self.subvolumeid)