[Kimchi-devel] [PATCH 1/2] Make vm model to be a singleton

Shu Ming shuming at linux.vnet.ibm.com
Tue Mar 4 16:28:54 UTC 2014


2014/3/4 20:23, Sheldon:
> Reviewed-by: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
>
> do you means this BackgroundTask?
> self.guests_stats_thread = BackgroundTask(GUESTS_STATS_INTERVAL,
> self._update_guests_stats)
>
> we should avoid multiple times to run this BackgroundTask.
>
> when refer get_list method?
I get the same question here.  Does that mean class VMsModel will be 
instantiated multiples times and VMsModel.__init__() will be called 
multiple times?

> I'm afraid the there are server instances of VMsModel, but need to 
> check where are
> these instances from the code.

Agree. Not sure where are the multiple instances of class VMsModel 
coming from.

>
>
> On 03/04/2014 06:14 PM, lvroyce at linux.vnet.ibm.com wrote:
>> From: Royce Lv <lvroyce at linux.vnet.ibm.com>
>>
>> When refer vm model get_list method, the stats collection task
>> will run multiple times. Make vms model class a singleton so that
>> this task just run once.
>>
>> Signed-off-by: Royce Lv <lvroyce at linux.vnet.ibm.com>
>> ---
>>   src/kimchi/model/vms.py | 3 +++
>>   1 file changed, 3 insertions(+)
>>
>> diff --git a/src/kimchi/model/vms.py b/src/kimchi/model/vms.py
>> index 3ae2048..449acdb 100644
>> --- a/src/kimchi/model/vms.py
>> +++ b/src/kimchi/model/vms.py
>> @@ -27,6 +27,7 @@ from cherrypy.process.plugins import BackgroundTask
>>
>>   from kimchi import vnc
>>   from kimchi import xmlutils
>> +from kimchi.basemodel import Singleton
>>   from kimchi.exception import InvalidOperation, InvalidParameter
>>   from kimchi.exception import MissingParameter, NotFoundError, 
>> OperationFailed
>>   from kimchi.model.config import CapabilitiesModel
>> @@ -52,6 +53,8 @@ stats = {}
>>
>>
>>   class VMsModel(object):
>> +    __metaclass__ = Singleton
>> +
>>       def __init__(self, **kargs):
>>           self.conn = kargs['conn']
>>           self.objstore = kargs['objstore']
>
>




More information about the Kimchi-devel mailing list