]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind: configurable cephfs_vol_client prefix and ns_prefix. 9430/head
authorXiaoxi Chen <xiaoxchen@ebay.com>
Tue, 26 Apr 2016 22:51:48 +0000 (17:51 -0500)
committerJohn Spray <john.spray@redhat.com>
Thu, 2 Jun 2016 15:14:06 +0000 (16:14 +0100)
Which is useful if we would like to have multiple backends
in manila and potentially set different layout based on prefix.

And also make ns_prefix configurable also in order to support
multiple backend.

Fixes #15417

Signed-off-by: Xiaoxi Chen <xiaoxchen@ebay.com>
(cherry picked from commit d1a21b07ede77ab3f2be7a753426d76de0343086)

src/pybind/ceph_volume_client.py

index bb75e3477be77abba55efd532b28b211f9a6828a..e37c904f9dfb611f4904b95edec464db688948c3 100644 (file)
@@ -203,17 +203,19 @@ class CephFSVolumeClient(object):
     """
 
     # Where shall we create our volumes?
-    VOLUME_PREFIX = "/volumes"
     POOL_PREFIX = "fsvolume_"
-    POOL_NS_PREFIX = "fsvolumens_"
+    DEFAULT_VOL_PREFIX = "/volumes"
+    DEFAULT_NS_PREFIX = "fsvolumens_"
 
-    def __init__(self, auth_id, conf_path, cluster_name):
+    def __init__(self, auth_id, conf_path, cluster_name, volume_prefix=None, pool_ns_prefix=None):
         self.fs = None
         self.rados = None
         self.connected = False
         self.conf_path = conf_path
         self.cluster_name = cluster_name
         self.auth_id = auth_id
+        self.volume_prefix = volume_prefix if volume_prefix else self.DEFAULT_VOL_PREFIX
+        self.pool_ns_prefix = pool_ns_prefix if pool_ns_prefix else self.DEFAULT_NS_PREFIX
 
     def evict(self, auth_id, timeout=30, volume_path=None):
         """
@@ -269,7 +271,7 @@ class CephFSVolumeClient(object):
         :return: absolute path (string)
         """
         return os.path.join(
-            self.VOLUME_PREFIX,
+            self.volume_prefix,
             volume_path.group_id if volume_path.group_id is not None else NO_GROUP_NAME,
             volume_path.volume_id)
 
@@ -278,7 +280,7 @@ class CephFSVolumeClient(object):
             raise ValueError("group_id may not be None")
 
         return os.path.join(
-            self.VOLUME_PREFIX,
+            self.volume_prefix,
             group_id
         )
 
@@ -409,7 +411,7 @@ class CephFSVolumeClient(object):
     def destroy_group(self, group_id):
         path = self._get_group_path(group_id)
         try:
-            self.fs.stat(self.VOLUME_PREFIX)
+            self.fs.stat(self.volume_prefix)
         except cephfs.ObjectNotFound:
             pass
         else:
@@ -465,7 +467,7 @@ class CephFSVolumeClient(object):
             self.fs.setxattr(path, 'ceph.dir.layout.pool', pool_name, 0)
 
         # enforce security isolation, use seperate namespace for this volume
-        namespace = "{0}{1}".format(self.POOL_NS_PREFIX, volume_path.volume_id)
+        namespace = "{0}{1}".format(self.pool_ns_prefix, volume_path.volume_id)
         log.info("create_volume: {0}, using rados namespace {1} to isolate data.".format(volume_path, namespace))
         self.fs.setxattr(path, 'ceph.dir.layout.pool_namespace', namespace, 0)
 
@@ -486,7 +488,7 @@ class CephFSVolumeClient(object):
         log.info("delete_volume: {0}".format(volume_path))
 
         # Create the trash folder if it doesn't already exist
-        trash = os.path.join(self.VOLUME_PREFIX, "_deleting")
+        trash = os.path.join(self.volume_prefix, "_deleting")
         self._mkdir_p(trash)
 
         # We'll move it to here
@@ -508,7 +510,7 @@ class CephFSVolumeClient(object):
         function is idempotent.
         """
 
-        trash = os.path.join(self.VOLUME_PREFIX, "_deleting")
+        trash = os.path.join(self.volume_prefix, "_deleting")
         trashed_volume = os.path.join(trash, volume_path.volume_id)
 
         try: