* `CephService.send_command` is much easier to use.
* Refactored `CephFSClients.get` and `Dashboard.load_bufer`
Signed-off-by: Sebastian Wagner <sebastian.wagner@suse.com>
from __future__ import absolute_import
from collections import defaultdict
-import json
import cherrypy
-from mgr_module import CommandResult
+
+from ..services.ceph_service import CephService
from .. import mgr
from ..tools import ApiController, AuthRequired, BaseController, ViewCache
except AttributeError:
raise cherrypy.HTTPError(404,
"No cephfs with id {0}".format(fs_id))
+
if clients is None:
raise cherrypy.HTTPError(404,
"No cephfs with id {0}".format(fs_id))
# pylint: disable=unused-variable
@ViewCache()
def get(self):
- mds_spec = "{0}:0".format(self.fscid)
- result = CommandResult("")
- self._module.send_command(result, "mds", mds_spec,
- json.dumps({
- "prefix": "session ls",
- }),
- "")
- r, outb, outs = result.wait()
# TODO handle nonzero returns, e.g. when rank isn't active
- assert r == 0
- return json.loads(outb)
+ return CephService.send_command('mds', 'session ls', srv_spec='{0}:0'.format(self.fscid))
import json
import cherrypy
-from mgr_module import CommandResult
from .. import mgr
from ..services.ceph_service import CephService
self.log_buffer.appendleft(log_struct)
def load_buffer(self, buf, channel_name):
- result = CommandResult("")
- mgr.send_command(result, "mon", "", json.dumps({
- "prefix": "log last",
- "format": "json",
- "channel": channel_name,
- "num": LOG_BUFFER_SIZE
- }), "")
- r, outb, outs = result.wait()
- if r != 0:
- # Oh well. We won't let this stop us though.
- self.log.error("Error fetching log history (r={0}, \"{1}\")".format(
- r, outs))
- else:
- try:
- lines = json.loads(outb)
- except ValueError:
- self.log.error("Error decoding log history")
- else:
- for l in lines:
- buf.appendleft(l)
+ lines = CephService.send_command('mon', 'log last', channel=channel_name,
+ num=LOG_BUFFER_SIZE)
+ for l in lines:
+ buf.appendleft(l)
# pylint: disable=R0914
@cherrypy.expose
import time
import collections
from collections import defaultdict
+import json
-from .. import mgr
+from mgr_module import CommandResult
+from .. import logger, mgr
class CephService(object):
pool['stats'] = s
pools_w_stats.append(pool)
return pools_w_stats
+
+ @classmethod
+ def send_command(cls, srv_type, prefix, srv_spec='', **kwargs):
+ """
+ :type prefix: str
+ :param srv_type: mon |
+ :param kwargs: will be added to argdict
+ :param srv_spec: typically empty. or something like "<fs_id>:0"
+
+ :raises PermissionError: See rados.make_ex
+ :raises ObjectNotFound: See rados.make_ex
+ :raises IOError: See rados.make_ex
+ :raises NoSpace: See rados.make_ex
+ :raises ObjectExists: See rados.make_ex
+ :raises ObjectBusy: See rados.make_ex
+ :raises NoData: See rados.make_ex
+ :raises InterruptedOrTimeoutError: See rados.make_ex
+ :raises TimedOut: See rados.make_ex
+ :raises ValueError: return code != 0
+ """
+ argdict = {
+ "prefix": prefix,
+ "format": "json",
+ }
+ argdict.update({k: v for k, v in kwargs.items() if v})
+
+ result = CommandResult("")
+ mgr.send_command(result, srv_type, srv_spec, json.dumps(argdict), "")
+ r, outb, outs = result.wait()
+ if r != 0:
+ msg = "send_command '{}' failed. (r={}, outs=\"{}\", kwargs={})".format(prefix, r, outs,
+ kwargs)
+ logger.error(msg)
+ raise ValueError(msg)
+ else:
+ try:
+ return json.loads(outb)
+ except Exception: # pylint: disable=broad-except
+ return outb