]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr / volumes: introduce subvolume specification class
authorVenky Shankar <vshankar@redhat.com>
Thu, 16 May 2019 05:54:12 +0000 (01:54 -0400)
committerVenky Shankar <vshankar@redhat.com>
Fri, 14 Jun 2019 04:26:51 +0000 (00:26 -0400)
Specifications class that represents a unique subvolume
identified by (subvolume-id, group-id) tuple. Provide
heleper functions for fetching  various subvolume specific
attributes such as subvolume path, group path etc.

Signed-off-by: Venky Shankar <vshankar@redhat.com>
src/pybind/mgr/volumes/fs/subvolspec.py [new file with mode: 0644]

diff --git a/src/pybind/mgr/volumes/fs/subvolspec.py b/src/pybind/mgr/volumes/fs/subvolspec.py
new file mode 100644 (file)
index 0000000..63e5094
--- /dev/null
@@ -0,0 +1,87 @@
+import os
+
+class SubvolumeSpec(object):
+    """
+    Specification of a subvolume, identified by (subvolume-id, group-id) tuple. Add fields as
+    required...
+    """
+
+    # where shall we (by default) create subvolumes
+    DEFAULT_SUBVOL_PREFIX = "/volumes"
+    # and the default namespace
+    DEFAULT_NS_PREFIX = "fsvolumens_"
+
+    # Reserved subvolume group name which we use in paths for subvolumes
+    # that are not assigned to a group (i.e. created with group=None)
+    NO_GROUP_NAME = "_nogroup"
+
+    def __init__(self, subvolumeid, groupid, subvolume_prefix=None, pool_ns_prefix=None):
+        assert groupid != SubvolumeSpec.NO_GROUP_NAME
+
+        self.subvolumeid = subvolumeid
+        self.groupid = groupid if groupid is not None else SubvolumeSpec.NO_GROUP_NAME
+        self.subvolume_prefix = subvolume_prefix if subvolume_prefix else SubvolumeSpec.DEFAULT_SUBVOL_PREFIX
+        self.pool_ns_prefix = pool_ns_prefix if pool_ns_prefix else SubvolumeSpec.DEFAULT_NS_PREFIX
+
+    def is_default_group(self):
+        """
+        Is the group the default group?
+        """
+        return self.groupid == SubvolumeSpec.NO_GROUP_NAME
+
+    @property
+    def subvolume_path(self):
+        """
+        return the subvolume path from subvolume specification
+        """
+        return os.path.join(self.subvolume_prefix, self.groupid, self.subvolumeid)
+
+    @property
+    def group_path(self):
+        """
+        return the group path from subvolume specification
+        """
+        return os.path.join(self.subvolume_prefix, self.groupid)
+
+    @property
+    def trash_path(self):
+        """
+        return the trash path from subvolume specification
+        """
+        return os.path.join(self.subvolume_prefix, "_deleting", self.subvolumeid)
+
+    @property
+    def fs_namespace(self):
+        """
+        return a filesystem namespace by stashing pool namespace prefix and subvolume-id
+        """
+        return "{0}{1}".format(self.pool_ns_prefix, self.subvolumeid)
+
+    @property
+    def group_dir(self):
+        """
+        return the group directory path
+        """
+        return self.subvolume_prefix
+
+    @property
+    def trash_dir(self):
+        """
+        return the trash directory path
+        """
+        return os.path.join(self.subvolume_prefix, "_deleting")
+
+    def make_subvol_snap_path(self, snapdir, snapname):
+        """
+        return the subvolume snapshot path for a given snapshot name
+        """
+        return os.path.join(self.subvolume_path, snapdir, snapname)
+
+    def make_group_snap_path(self, snapdir, snapname):
+        """
+        return the group snapshot path for a given snapshot name
+        """
+        return os.path.join(self.group_path, snapdir, snapname)
+
+    def __str__(self):
+        return "{0}/{1}".format(self.groupid, self.subvolumeid)