]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/volumes/fs/subvolspec.py
import ceph 14.2.5
[ceph.git] / ceph / src / pybind / mgr / volumes / fs / subvolspec.py
1 import os
2 import uuid
3
4 class 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 """
52 return os.path.join(self.group_path, self.subvolumeid.encode('utf-8'))
53
54 @property
55 def group_path(self):
56 """
57 return the group path from subvolume specification
58 """
59 return os.path.join(self.subvolume_prefix.encode('utf-8'), self.groupid.encode('utf-8'))
60
61 @property
62 def trash_path(self):
63 """
64 return the trash path from subvolume specification
65 """
66 return os.path.join(self.subvolume_prefix.encode('utf-8'), b"_deleting", self.subvolumeid.encode('utf-8'))
67
68 @property
69 def unique_trash_path(self):
70 """
71 return a unique trash directory entry path
72 """
73 return os.path.join(self.subvolume_prefix.encode('utf-8'), b"_deleting", str(uuid.uuid4()).encode('utf-8'))
74
75 @property
76 def fs_namespace(self):
77 """
78 return a filesystem namespace by stashing pool namespace prefix and subvolume-id
79 """
80 return "{0}{1}".format(self.pool_ns_prefix, self.subvolumeid)
81
82 @property
83 def trash_dir(self):
84 """
85 return the trash directory path
86 """
87 return os.path.join(self.subvolume_prefix.encode('utf-8'), b"_deleting")
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.encode('utf-8'), snapname.encode('utf-8'))
94
95 def make_subvol_snapdir_path(self, snapdir):
96 """
97 return the subvolume snapdir path
98 """
99 return os.path.join(self.subvolume_path, snapdir.encode('utf-8'))
100
101 def make_group_snap_path(self, snapdir, snapname):
102 """
103 return the group snapshot path for a given snapshot name
104 """
105 return os.path.join(self.group_path, snapdir.encode('utf-8'), snapname.encode('utf-8'))
106
107 def make_group_snapdir_path(self, snapdir):
108 """
109 return the group's snapdir path
110 """
111 return os.path.join(self.group_path, snapdir.encode('utf-8'))
112
113 def __str__(self):
114 return "{0}/{1}".format(self.groupid, self.subvolumeid)