mirror of
https://github.com/nicolargo/glances.git
synced 2024-12-22 16:51:35 +03:00
Add getViews<plugin>() method for then XML API, first step for the issue977
This commit is contained in:
parent
5f4b92b88c
commit
996414e829
@ -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."""
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user