]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
node-proxy: drop dispatch() in NodeProxy()
authorGuillaume Abrioux <gabrioux@ibm.com>
Fri, 20 Oct 2023 09:21:16 +0000 (09:21 +0000)
committerGuillaume Abrioux <gabrioux@ibm.com>
Thu, 25 Jan 2024 15:07:20 +0000 (15:07 +0000)
The current logic prevents from using any cherrypy decorators
on actual endpoints as we use a set of 'proxy functions'
(index and dispatch) instead.

Signed-off-by: Guillaume Abrioux <gabrioux@ibm.com>
src/pybind/mgr/cephadm/agent.py
src/pybind/mgr/cephadm/inventory.py

index 28e1516f84f9cf5989e244126eaf4942866881e3..82f289e50778f1218f2001cff7ae9ae0a6f5e704 100644 (file)
@@ -100,9 +100,6 @@ class NodeProxy:
         if len(vpath) == 2:
             hostname = vpath.pop(0)
             cherrypy.request.params['hostname'] = hostname
-        cmd = vpath.pop(0)
-        cherrypy.request.params['cmd'] = cmd
-
         return self
 
     @cherrypy.expose
@@ -224,37 +221,47 @@ class NodeProxy:
     def summary(self, **kw: Any) -> Dict[str, Any]:
         return self.mgr.node_proxy.summary(**kw)
 
+    @cherrypy.expose
     @cherrypy.tools.allow(methods=['GET'])
     @cherrypy.tools.json_out()
-    def common(self, **kw) -> Dict[str, Any]:
-        return self.mgr.node_proxy.common(**kw)
+    def memory(self, **kw: Any) -> Dict[str, Any]:
+        return self.mgr.node_proxy.common('memory', **kw)
 
     @cherrypy.expose
     @cherrypy.tools.allow(methods=['GET'])
     @cherrypy.tools.json_out()
-    def firmwares(self, **kw) -> Dict[str, Any]:
-        return self.mgr.node_proxy.firmwares(**kw)
+    def network(self, **kw: Any) -> Dict[str, Any]:
+        return self.mgr.node_proxy.common('network', **kw)
 
-    def dispatch(self, hostname='', cmd=''):
-        kw = dict(hostname=hostname, cmd=cmd)
-        try:
-            func = getattr(self, cmd)
-            result = func(**kw)
-        except AttributeError:
-            try:
-                result = self.common(**kw)
-            except RuntimeError as e:
-                cherrypy.response.status = 404
-                result = {"error": f"{e}"}
-            return {"error": "Not a valid endpoint."}
-        finally:
-            return result
+    @cherrypy.expose
+    @cherrypy.tools.allow(methods=['GET'])
+    @cherrypy.tools.json_out()
+    def processors(self, **kw: Any) -> Dict[str, Any]:
+        return self.mgr.node_proxy.common('processors', **kw)
+
+    @cherrypy.expose
+    @cherrypy.tools.allow(methods=['GET'])
+    @cherrypy.tools.json_out()
+    def storage(self, **kw: Any) -> Dict[str, Any]:
+        return self.mgr.node_proxy.common('storage', **kw)
+
+    @cherrypy.expose
+    @cherrypy.tools.allow(methods=['GET'])
+    @cherrypy.tools.json_out()
+    def power(self, **kw: Any) -> Dict[str, Any]:
+        return self.mgr.node_proxy.common('power', **kw)
 
     @cherrypy.expose
+    @cherrypy.tools.allow(methods=['GET'])
     @cherrypy.tools.json_out()
-    def index(self, hostname=None, cmd=''):
-        result = self.dispatch(hostname, cmd)
-        return result
+    def fans(self, **kw: Any) -> Dict[str, Any]:
+        return self.mgr.node_proxy.common('fans', **kw)
+
+    @cherrypy.expose
+    @cherrypy.tools.allow(methods=['GET'])
+    @cherrypy.tools.json_out()
+    def firmwares(self, **kw: Any) -> Dict[str, Any]:
+        return self.mgr.node_proxy.firmwares(**kw)
 
 
 class HostData(Server):
index 625753a8825fafd771c8216021e193d8fae3c009..c4e0b34f2cbf6dbe7853126babb0f7edba0cfc37 100644 (file)
@@ -1465,16 +1465,15 @@ class NodeProxyCache:
         else:
             return _result
 
-    def common(self, **kw):
-        hostname = kw.get('hostname',)
-        cmd = kw.get('cmd',)
+    def common(self, endpoint: str, **kw: Any) -> Dict[str, Any]:
+        hostname = kw.get('hostname')
         _result = {}
 
         for host, data in self.data.items():
             try:
-                _result[host] = data['status'][cmd]
+                _result[host] = data['status'][endpoint]
             except KeyError:
-                raise RuntimeError(f'Invalid node-proxy category {cmd}')
+                raise RuntimeError(f'Invalid node-proxy endpoint {endpoint}')
 
         if hostname and hostname in self.data.keys():
             return _result[hostname]