]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/nfs: convert _cmd_nfs_cluster_create to use EmptyResponder decorator
authorJohn Mulligan <jmulligan@redhat.com>
Thu, 5 May 2022 19:38:44 +0000 (15:38 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Thu, 12 Jan 2023 18:44:11 +0000 (13:44 -0500)
Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/pybind/mgr/nfs/cluster.py
src/pybind/mgr/nfs/module.py

index 041534b8b6d729414c94a7dbbec5bbe555fee334..0c072c7b31da136b1b225378c55b085803ce9c59 100644 (file)
@@ -11,8 +11,12 @@ from object_format import ErrorResponse
 import orchestrator
 
 from .exception import NFSInvalidOperation, ClusterNotFound
-from .utils import (available_clusters, restart_nfs_service, conf_obj_name,
-                    user_conf_obj_name)
+from .utils import (
+    NonFatalError,
+    available_clusters,
+    conf_obj_name,
+    restart_nfs_service,
+    user_conf_obj_name)
 from .export import NFSRados, exception_handler
 
 if TYPE_CHECKING:
@@ -105,8 +109,7 @@ class NFSCluster:
             virtual_ip: Optional[str],
             ingress: Optional[bool] = None,
             port: Optional[int] = None,
-    ) -> Tuple[int, str, str]:
-
+    ) -> None:
         try:
             if virtual_ip:
                 # validate virtual_ip value: ip_address throws a ValueError
@@ -128,10 +131,11 @@ class NFSCluster:
 
             if cluster_id not in available_clusters(self.mgr):
                 self._call_orch_apply_nfs(cluster_id, placement, virtual_ip, port)
-                return 0, "", ""
-            return 0, "", f"{cluster_id} cluster already exists"
+                return
+            raise NonFatalError(f"{cluster_id} cluster already exists")
         except Exception as e:
-            return exception_handler(e, f"NFS Cluster {cluster_id} could not be created")
+            log.exception(f"NFS Cluster {cluster_id} could not be created")
+            raise ErrorResponse.wrap(e)
 
     def delete_nfs_cluster(self, cluster_id: str) -> Tuple[int, str, str]:
         try:
index e883408a8b188b076afc17fcaf83248e6c6aa7e6..1be52f9512a2e84a3a30f2d93f7beedf9a55da3b 100644 (file)
@@ -114,12 +114,13 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule):
         return self.export_mgr.apply_export(cluster_id, export_config=inbuf)
 
     @CLICommand('nfs cluster create', perm='rw')
+    @object_format.EmptyResponder()
     def _cmd_nfs_cluster_create(self,
                                 cluster_id: str,
                                 placement: Optional[str] = None,
                                 ingress: Optional[bool] = None,
                                 virtual_ip: Optional[str] = None,
-                                port: Optional[int] = None) -> Tuple[int, str, str]:
+                                port: Optional[int] = None) -> None:
         """Create an NFS Cluster"""
         return self.nfs.create_nfs_cluster(cluster_id=cluster_id, placement=placement,
                                            virtual_ip=virtual_ip, ingress=ingress,