Reviewed-by: ShaoHe Feng <shaohef(a)linux.vnet.ibm.com>
So you will add a new patch and instantiate the VMsModel right?
Sure you can use Model instance.
I'm not sure VMsModel instance or Model instance which is better.
But IMO, it seems good to Make vms model to be a singleton.
But there is not a lock for our Singleton. not sure there is a race.
On 03/05/2014 04:14 PM, lvroyce(a)linux.vnet.ibm.com wrote:
From: Royce Lv <lvroyce(a)linux.vnet.ibm.com>
In vms model __init__ function, a backgroud task is started:
self.guests_stats_thread = BackgroundTask(GUESTS_STATS_INTERVAL,
self._update_guests_stats)
self.guests_stats_thread.start()
when VMsModel.get_list() need to be called
([PATCH]Add volume ref_cnt: Add model and mockmodel implementation)
one more background task is started.
This is not able to be fixed by staticmethod
because connection will not be passed by controller.
So make vms model a singleton.
Signed-off-by: Royce Lv <lvroyce(a)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 3f3a152..0d029eb 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.config import READONLY_POOL_TYPE
from kimchi.exception import InvalidOperation, InvalidParameter
from kimchi.exception import MissingParameter, NotFoundError, OperationFailed
@@ -53,6 +54,8 @@ stats = {}
class VMsModel(object):
+ __metaclass__ = Singleton
+
def __init__(self, **kargs):
self.conn = kargs['conn']
self.objstore = kargs['objstore']
--
Thanks and best regards!
Sheldon Feng(冯少合)<shaohef(a)linux.vnet.ibm.com>
IBM Linux Technology Center