]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: check for an existing NFS config object
authorMichael Fritch <mfritch@suse.com>
Wed, 18 Mar 2020 19:57:18 +0000 (13:57 -0600)
committerMichael Fritch <mfritch@suse.com>
Wed, 25 Mar 2020 22:26:15 +0000 (16:26 -0600)
assume an existing NFS config if the named rados object already exists

Signed-off-by: Michael Fritch <mfritch@suse.com>
src/pybind/mgr/cephadm/nfs.py

index 081b52378595dd9d6d14ba5a2c8bd8b250a0a163..f03a840461f20487335bd233c1c327b795b18701 100644 (file)
@@ -1,4 +1,5 @@
 import logging
+import rados
 
 from typing import Dict, Optional
 
@@ -81,14 +82,27 @@ class NFSGanesha(object):
                     'Unable to update keyring caps %s: %s %s' \
                             % (entity, ret, err))
 
-    def create_rados_config_obj(self):
-        # type: () -> None
+    def create_rados_config_obj(self, clobber=False):
+        # type: (Optional[bool]) -> None
         obj = self.get_rados_config_name()
-        logger.info('Create rados config object: %s' % obj)
+
         with self.mgr.rados.open_ioctx(self.spec.pool) as ioctx:
             if self.spec.namespace:
                 ioctx.set_namespace(self.spec.namespace)
-            ioctx.write_full(obj, ''.encode('utf-8'))
+
+            exists = True
+            try:
+                ioctx.stat(obj)
+            except rados.ObjectNotFound as e:
+                exists = False
+
+            if exists and not clobber:
+                # Assume an existing config
+                logger.info('Rados config object exists: %s' % obj)
+            else:
+                # Create an empty config object
+                logger.info('Creating rados config object: %s' % obj)
+                ioctx.write_full(obj, ''.encode('utf-8'))
 
     def get_ganesha_conf(self):
         # type: () -> str