diff options
Diffstat (limited to 'glances/outputs/glances_bottle.py')
-rw-r--r-- | glances/outputs/glances_bottle.py | 51 |
1 files changed, 24 insertions, 27 deletions
diff --git a/glances/outputs/glances_bottle.py b/glances/outputs/glances_bottle.py index 053a1175..5ea21873 100644 --- a/glances/outputs/glances_bottle.py +++ b/glances/outputs/glances_bottle.py @@ -333,15 +333,8 @@ class GlancesBottle(object): abort(404, "Cannot get views for plugin %s (%s)" % (plugin, str(e))) return ret - def _api_item(self, plugin, item): - """Glances API RESTFul implementation. - - Return the JSON represenation of the couple plugin/item - HTTP/200 if OK - HTTP/400 if plugin is not found - HTTP/404 if others error - - """ + def _api_itemvalue(self, plugin, item, value=None): + """ Father method for _api_item and _api_value""" response.content_type = 'application/json' if plugin not in self.plugins_list: @@ -350,35 +343,39 @@ class GlancesBottle(object): # Update the stat self.stats.update() - plist = self.stats.get_plugin(plugin).get_stats_item(item) + if value is None: + ret = self.stats.get_plugin(plugin).get_stats_item(item) - if plist is None: - abort(404, "Cannot get item %s in plugin %s" % (item, plugin)) + if ret is None: + abort(404, "Cannot get item %s in plugin %s" % (item, plugin)) else: - return plist + ret = self.stats.get_plugin(plugin).get_stats_value(item, value) - def _api_value(self, plugin, item, value): + if ret is None: + abort(404, "Cannot get item(%s)=value(%s) in plugin %s" % (item, value, plugin)) + + return ret + + def _api_item(self, plugin, item): """Glances API RESTFul implementation. - Return the process stats (dict) for the given item=value + Return the JSON represenation of the couple plugin/item HTTP/200 if OK HTTP/400 if plugin is not found HTTP/404 if others error - """ - response.content_type = 'application/json' - - if plugin not in self.plugins_list: - abort(400, "Unknown plugin %s (available plugins: %s)" % (plugin, self.plugins_list)) - # Update the stat - self.stats.update() + """ + return self._api_itemvalue(plugin, item) - pdict = self.stats.get_plugin(plugin).get_stats_value(item, value) + def _api_value(self, plugin, item, value): + """Glances API RESTFul implementation. - if pdict is None: - abort(404, "Cannot get item(%s)=value(%s) in plugin %s" % (item, value, plugin)) - else: - return pdict + Return the process stats (dict) for the given item=value + HTTP/200 if OK + HTTP/400 if plugin is not found + HTTP/404 if others error + """ + return self._api_itemvalue(plugin, item, value) def _api_args(self): """Glances API RESTFul implementation. |