From 5e1620315b6581104b1fa88dae6a081e1f9620ab Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Fri, 26 Feb 2021 11:47:11 +0800 Subject: [PATCH] mgr/prometheus: implement command using CLIReadCommand Signed-off-by: Kefu Chai (cherry picked from commit 3b9ecd14d7d714be7a7c72fa3d44d7781d360135) --- src/pybind/mgr/prometheus/module.py | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/src/pybind/mgr/prometheus/module.py b/src/pybind/mgr/prometheus/module.py index 19c3f5f36c529..222ffd8583255 100644 --- a/src/pybind/mgr/prometheus/module.py +++ b/src/pybind/mgr/prometheus/module.py @@ -10,7 +10,7 @@ import re import socket import threading import time -from mgr_module import MgrModule, MgrStandbyModule, PG_STATES, Option, ServiceInfoT +from mgr_module import CLIReadCommand, MgrModule, MgrStandbyModule, PG_STATES, Option, ServiceInfoT from mgr_util import get_default_addr, profile_method from rbd import RBD from collections import namedtuple @@ -268,14 +268,6 @@ class MetricCollectionThread(threading.Thread): class Module(MgrModule): - COMMANDS = [ - { - "cmd": "prometheus file_sd_config", - "desc": "Return file_sd compatible prometheus config for mgr cluster", - "perm": "r" - }, - ] - MODULE_OPTIONS = [ Option( 'server_addr' @@ -1235,7 +1227,11 @@ class Module(MgrModule): return ''.join(_metrics) + '\n' + @CLIReadCommand('prometheus file_sd_config') def get_file_sd_config(self): + ''' + Return file_sd compatible prometheus config for mgr cluster + ''' servers = self.list_servers() targets = [] for server in servers: @@ -1258,13 +1254,6 @@ class Module(MgrModule): self.collect() self.get_file_sd_config() - def handle_command(self, inbuf, cmd): - if cmd['prefix'] == 'prometheus file_sd_config': - return self.get_file_sd_config() - else: - return (-errno.EINVAL, '', - "Command not found '{0}'".format(cmd['prefix'])) - def serve(self): class Root(object): -- 2.39.5