]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/smb: add create_only arg for handler apply function
authorJohn Mulligan <jmulligan@redhat.com>
Wed, 1 May 2024 14:55:27 +0000 (10:55 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Thu, 13 Jun 2024 13:54:05 +0000 (09:54 -0400)
Add a create_only argument to the handler class apply function. This
flag is used to prevent modification of existing resources. This flag
will be use by 'cluster create' and 'share create' commands to make
them true to their names and not sneaky modify-or-create commands.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/pybind/mgr/smb/handler.py

index 1bf96557f6b4bff6bb79218b80424082bc509834..7047f372c6b3ce7db47555dca3d8a74a034cce03 100644 (file)
@@ -342,7 +342,12 @@ class ClusterConfigHandler:
             f' orch {self._orch!r}'
         )
 
-    def apply(self, inputs: Iterable[SMBResource]) -> ResultGroup:
+    def apply(
+        self, inputs: Iterable[SMBResource], *, create_only: bool = False
+    ) -> ResultGroup:
+        """Apply resource configuration changes.
+        Set `create_only` to disable changing existing resource values.
+        """
         log.debug('applying changes to internal data store')
         results = ResultGroup()
         staging = _Staging(self.internal_store)
@@ -351,7 +356,9 @@ class ClusterConfigHandler:
             for resource in incoming:
                 staging.stage(resource)
             for resource in incoming:
-                results.append(self._check(resource, staging))
+                results.append(
+                    self._check(resource, staging, create_only=create_only)
+                )
         except ErrorResult as err:
             results.append(err)
         except Exception as err:
@@ -428,9 +435,22 @@ class ClusterConfigHandler:
         log.debug("search found %d resources", len(out))
         return out
 
-    def _check(self, resource: SMBResource, staging: _Staging) -> Result:
+    def _check(
+        self,
+        resource: SMBResource,
+        staging: _Staging,
+        *,
+        create_only: bool = False,
+    ) -> Result:
         """Check/validate a staged resource."""
         log.debug('staging resource: %r', resource)
+        if create_only:
+            if not staging.is_new(resource):
+                return Result(
+                    resource,
+                    success=False,
+                    msg='a resource with the same ID already exists',
+                )
         try:
             if isinstance(
                 resource, (resources.Cluster, resources.RemovedCluster)