From: Guillaume Abrioux Date: Fri, 20 Oct 2023 09:21:16 +0000 (+0000) Subject: node-proxy: drop dispatch() in NodeProxy() X-Git-Tag: v19.1.0~384^2~41 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=b65c872b1e4de48b35c2f82cdd02dbd23dced68e;p=ceph.git node-proxy: drop dispatch() in NodeProxy() 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 --- diff --git a/src/pybind/mgr/cephadm/agent.py b/src/pybind/mgr/cephadm/agent.py index 28e1516f84f9c..82f289e50778f 100644 --- a/src/pybind/mgr/cephadm/agent.py +++ b/src/pybind/mgr/cephadm/agent.py @@ -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): diff --git a/src/pybind/mgr/cephadm/inventory.py b/src/pybind/mgr/cephadm/inventory.py index 625753a8825fa..c4e0b34f2cbf6 100644 --- a/src/pybind/mgr/cephadm/inventory.py +++ b/src/pybind/mgr/cephadm/inventory.py @@ -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]