[Kimchi-devel] [PATCH v2][Wok 3/8] Implements control/model of new plugin API

Aline Manera alinefm at linux.vnet.ibm.com
Wed Jun 8 21:19:13 UTC 2016



On 06/08/2016 06:07 PM, Rodrigo Trujillo wrote:
>
>
> On 06/08/2016 03:59 PM, Aline Manera wrote:
>>
>>
>> On 06/06/2016 04:13 PM, Rodrigo Trujillo wrote:
>>> Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo at linux.vnet.ibm.com>
>>> ---
>>>   src/wok/control/plugins.py | 31 ++++++++++++++++++++++++++++---
>>>   src/wok/i18n.py            |  3 +++
>>>   src/wok/model/plugins.py   | 38 
>>> ++++++++++++++++++++++++++++++--------
>>>   3 files changed, 61 insertions(+), 11 deletions(-)
>>>
>>> diff --git a/src/wok/control/plugins.py b/src/wok/control/plugins.py
>>> index 57dfa1b..5c125eb 100644
>>> --- a/src/wok/control/plugins.py
>>> +++ b/src/wok/control/plugins.py
>>> @@ -19,11 +19,36 @@
>>>   # License along with this library; if not, write to the Free Software
>>>   # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  
>>> 02110-1301 USA
>>>
>>> -from wok.control.base import SimpleCollection
>>> +from wok.control.base import Collection, Resource, SimpleCollection
>>>   from wok.control.utils import UrlSubNode
>>>
>>>
>>> - at UrlSubNode("plugins")
>>> -class Plugins(SimpleCollection):
>>> + at UrlSubNode("plugins", False)
>>> +class PluginsSimple(SimpleCollection):
>>> +    """
>>> +    Returns only enabled plugins in order to built initial Wok UI
>>> +    """
>>> +    def __init__(self, model):
>>> +        super(PluginsSimple, self).__init__(model)
>>> +        pass
>>> +
>>> +
>>> + at UrlSubNode("pluginsmanager", True)
>>> +class Plugins(Collection):
>>>       def __init__(self, model):
>>>           super(Plugins, self).__init__(model)
>>> +        self.resource = Plugin
>>> +        self.admin_methods = ['GET']
>>> +
>>> +
>>> +class Plugin(Resource):
>>> +    def __init__(self, model, id):
>>> +        super(Plugin, self).__init__(model, id)
>>> +        self.uri_fmt = "/pluginsmanager/%s"
>>> +        self.enable = self.generate_action_handler('enable')
>>> +        self.disable = self.generate_action_handler('disable')
>>> +        self.admin_methods = ['GET', 'POST']
>>> +
>>> +    @property
>>> +    def data(self):
>>> +        return self.info
>>> diff --git a/src/wok/i18n.py b/src/wok/i18n.py
>>> index 4fc21f1..bda3949 100644
>>> --- a/src/wok/i18n.py
>>> +++ b/src/wok/i18n.py
>>> @@ -60,4 +60,7 @@ messages = {
>>>       "WOKRES0001L": _("Request made on resource"),
>>>       "WOKROOT0001L": _("User '%(username)s' logged in"),
>>>       "WOKROOT0002L": _("User '%(username)s' logged out"),
>>> +
>>> +    "WOKPLUG0001E": _("Plugin '%(plugin_name)s' not found."),
>>> +    "WOKPLUG0002E": _("Error updating configuration file of plugin 
>>> '%(plugin)s'."),
>>>   }
>>> diff --git a/src/wok/model/plugins.py b/src/wok/model/plugins.py
>>> index 4beff44..b0ac366 100644
>>> --- a/src/wok/model/plugins.py
>>> +++ b/src/wok/model/plugins.py
>>> @@ -3,8 +3,6 @@
>>>   #
>>>   # Copyright IBM Corp, 2015-2016
>>>   #
>>
>>> -# Code derived from Project Kimchi
>>> -#
>>
>> Any reason to remove the above line?
>
> You asked in previous review  :D  :D  :D  :D
>

I asked it for pluginsmanager.py new file! =P

This plugins.py is there and contain code imported from Kimchi.

>>
>>>   # This library is free software; you can redistribute it and/or
>>>   # modify it under the terms of the GNU Lesser General Public
>>>   # License as published by the Free Software Foundation; either
>>> @@ -19,9 +17,17 @@
>>>   # License along with this library; if not, write to the Free Software
>>>   # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  
>>> 02110-1301 USA
>>>
>>> -import cherrypy
>>>
>>> -from wok.utils import get_enabled_plugins
>>> +from wok.exception import NotFoundError
>>> +from wok.pluginsmanager import Plugins
>>> +
>>> +
>>> +class PluginsSimpleModel(object):
>>> +    def __init__(self, **kargs):
>>> +        pass
>>> +
>>> +    def get_list(self):
>>> +        return Plugins().get_enabled_plugins()
>>>
>>>
>>>   class PluginsModel(object):
>>> @@ -29,7 +35,23 @@ class PluginsModel(object):
>>>           pass
>>>
>>>       def get_list(self):
>>> -        # Will only return plugins that were loaded correctly by 
>>> WOK and are
>>> -        # properly configured in cherrypy
>>> -        return [plugin for (plugin, config) in get_enabled_plugins()
>>> -                if config.get('wok').get('uri') in 
>>> cherrypy.tree.apps.keys()]
>>> +        return Plugins().get_all_plugins_names()
>>> +
>>> +
>>> +class PluginModel(object):
>>> +    def __init__(self, **kargs):
>>> +        pass
>>> +
>>> +    def lookup(self, plugin):
>>> +        info = Plugins().get_plugin_info(plugin)
>>> +        if not info:
>>> +            raise NotFoundError('WOKPLUG0001E', {'plugin_name': 
>>> plugin})
>>> +
>>> +        return {'name': plugin,
>>> +                'enabled': info['enabled']}
>>> +
>>> +    def enable(self, plugin_name):
>>> +        Plugins().enable_plugin(plugin_name)
>>> +
>>> +    def disable(self, plugin_name):
>>> +        Plugins().disable_plugin(plugin_name)
>>
>> _______________________________________________
>> Kimchi-devel mailing list
>> Kimchi-devel at ovirt.org
>> http://lists.ovirt.org/mailman/listinfo/kimchi-devel
>>
>
> _______________________________________________
> Kimchi-devel mailing list
> Kimchi-devel at ovirt.org
> http://lists.ovirt.org/mailman/listinfo/kimchi-devel
>




More information about the Kimchi-devel mailing list