diff options
author | nicolargo <nicolas@nicolargo.com> | 2017-05-10 14:52:32 +0200 |
---|---|---|
committer | nicolargo <nicolas@nicolargo.com> | 2017-05-10 14:52:32 +0200 |
commit | 996414e82920b9aa508b9b8a2415b6ef192c7bf0 (patch) | |
tree | e2803dfef88063b8adb6314a93c6de1e36ee400b | |
parent | 5f4b92b88cc5faa3962978a79ea1e7e8725d8b21 (diff) |
Add getViews<plugin>() method for then XML API, first step for the issue977
-rw-r--r-- | glances/plugins/glances_plugin.py | 4 | ||||
-rw-r--r-- | glances/stats.py | 14 |
2 files changed, 17 insertions, 1 deletions
diff --git a/glances/plugins/glances_plugin.py b/glances/plugins/glances_plugin.py index 4603a89f..98bec585 100644 --- a/glances/plugins/glances_plugin.py +++ b/glances/plugins/glances_plugin.py @@ -457,6 +457,10 @@ class GlancesPlugin(object): else: return 'DEFAULT' + def get_json_views(self, item=None, key=None, option=None): + """Return views in JSON""" + return self._json_dumps(self.get_views(item, key, option)) + def load_limits(self, config): """Load limits from the configuration file, if it exists.""" diff --git a/glances/stats.py b/glances/stats.py index ce320781..05414aa7 100644 --- a/glances/stats.py +++ b/glances/stats.py @@ -54,9 +54,21 @@ class GlancesStats(object): The goal is to dynamically generate the following methods: - getPlugname(): return Plugname stat in JSON format + - getViewsPlugname(): return views of the Plugname stat in JSON format """ # Check if the attribute starts with 'get' - if item.startswith('get'): + if item.startswith('getViews'): + # Get the plugin name + plugname = item[len('getViews'):].lower() + # Get the plugin instance + plugin = self._plugins[plugname] + if hasattr(plugin, 'get_json_views'): + # The method get_views exist, return it + return getattr(plugin, 'get_json_views') + else: + # The method get_views is not found for the plugin + raise AttributeError(item) + elif item.startswith('get'): # Get the plugin name plugname = item[len('get'):].lower() # Get the plugin instance |