[Kimchi-devel] [PATCH] [Kimchi] model.py: use the new 'get_all_model_instances' utils function
Lucio Correia
luciojhc at linux.vnet.ibm.com
Fri Aug 12 13:30:19 UTC 2016
Reviewed-By: Lucio Correia <luciojhc at linux.vnet.ibm.com>
On 11-08-2016 17:53, dhbarboza82 at gmail.com wrote:
> From: Daniel Henrique Barboza <danielhb at linux.vnet.ibm.com>
>
> This patch uses the new get_all_model_instances function from
> WoK utils to retrieve all Kimchi model instances
>
> Signed-off-by: Daniel Henrique Barboza <danielhb at linux.vnet.ibm.com>
> ---
> model/model.py | 40 ++++++++--------------------------------
> 1 file changed, 8 insertions(+), 32 deletions(-)
>
> diff --git a/model/model.py b/model/model.py
> index 327d5a7..719652d 100644
> --- a/model/model.py
> +++ b/model/model.py
> @@ -17,13 +17,10 @@
> # 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 inspect
> -import os
> -
> from wok.basemodel import BaseModel
> from wok.objectstore import ObjectStore
> from wok.plugins.kimchi import config
> -from wok.utils import import_module, listPathModules
> +from wok.utils import get_all_model_instances, get_model_instances
>
> from wok.plugins.kimchi.model.libvirtconnection import LibvirtConnection
> from wok.plugins.kimchi.model.libvirtevents import LibvirtEvents
> @@ -32,42 +29,21 @@ from wok.plugins.kimchi.model.libvirtevents import LibvirtEvents
> class Model(BaseModel):
> def __init__(self, libvirt_uri=None, objstore_loc=None):
>
> - def get_instances(module_name):
> - instances = []
> - module = import_module(module_name)
> - members = inspect.getmembers(module, inspect.isclass)
> - for cls_name, instance in members:
> - if inspect.getmodule(instance) == module and \
> - cls_name.endswith('Model'):
> - instances.append(instance)
> -
> - return instances
> -
> self.objstore = ObjectStore(objstore_loc or config.get_object_store())
> - self.events = LibvirtEvents()
> self.conn = LibvirtConnection(libvirt_uri)
> - kargs = {'objstore': self.objstore, 'conn': self.conn,
> - 'eventsloop': self.events}
> - models = []
>
> # Register for Libvirt's host ENOSPC event and notify UI if it happens
> + self.events = LibvirtEvents()
> self.events.handleEnospc(self.conn)
>
> + kargs = {'objstore': self.objstore, 'conn': self.conn,
> + 'eventsloop': self.events}
> +
> + models = get_all_model_instances(__name__, __file__, kargs)
> +
> # Import task model from Wok
> - instances = get_instances('wok.model.tasks')
> + instances = get_model_instances('wok.model.tasks')
> for instance in instances:
> models.append(instance(**kargs))
>
> - # Import all Kimchi plugin models
> - this = os.path.basename(__file__)
> - this_mod = os.path.splitext(this)[0]
> -
> - for mod_name in listPathModules(os.path.dirname(__file__)):
> - if mod_name.startswith("_") or mod_name == this_mod:
> - continue
> -
> - instances = get_instances('wok.plugins.kimchi.model.' + mod_name)
> - for instance in instances:
> - models.append(instance(**kargs))
> -
> return super(Model, self).__init__(models)
>
--
Lucio Correia
Software Engineer
IBM LTC Brazil
More information about the Kimchi-devel
mailing list