Francesco Romani has uploaded a new change for review.

Change subject: mom: add register API
......................................................................

mom: add register API

using this new API, an hypervisor can register a new VM into the
MOM monitoring loop, avoiding the MOM autodetection and, on overall,
simplyfing the MOM/hypervisor handshake.

Change-Id: I60e3b6aafb877a78813444870d93340e1325b82e
Signed-off-by: Francesco Romani <from...@redhat.com>
---
M mom/GuestManager.py
M mom/GuestMonitor.py
M mom/__init__.py
3 files changed, 33 insertions(+), 17 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/mom refs/changes/98/31598/1

diff --git a/mom/GuestManager.py b/mom/GuestManager.py
index 49c915a..080a3b3 100644
--- a/mom/GuestManager.py
+++ b/mom/GuestManager.py
@@ -14,6 +14,7 @@
 # License along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 
+from contextlib import contextmanager
 import threading
 import time
 import sys
@@ -51,13 +52,14 @@
                     "can't start", id)
                 continue
             guest = GuestMonitor(self.config, info, self.hypervisor_iface)
-            thread = None
-            if not self.hypervisor_iface.attachMonitor(id,
-                                                       guest.collect,
-                                                       guest.interval):
-                thread = GuestMonitorThread(info, guest)
-                thread.start()
-            self._register_guest(guest, thread)
+            self._add_vm_to_monitored(uuid, info['name'], guest)
+
+    @contextmanager
+    def register(self, uuid):
+        info = self.hypervisor_iface.getVmInfo(id)
+        guest = GuestMonitor(self.config, info, self.hypervisor_iface)
+        yield guest
+        self._add_vm_to_monitored(uuid, info['name'], guest)
 
     def wait_for_guest_monitors(self):
         """
@@ -74,14 +76,6 @@
                     thread.join(0)
             else:
                 break
-
-    def _register_guest(self, guest, thread=None):
-        self.guests_sem.acquire()
-        if id not in self.guests:
-            self.guests[id] = (guest, thread)
-        else:
-            del guest
-        self.guests_sem.release()
 
     def check_threads(self, domain_list):
         """
@@ -138,3 +132,22 @@
                     if name is not None:
                         ret.append(name)
         return ret
+
+    # private methods
+
+    def _add_vm_to_monitored(self, id, name, guest):
+        thread = None
+        if not self.hypervisor_iface.attachMonitor(id,
+                                                   guest.collect,
+                                                   guest.interval):
+            thread = GuestMonitorThread(name, guest)
+            thread.start()
+        self._register_guest(guest, thread)
+
+    def _register_guest(self, guest, thread=None):
+        self.guests_sem.acquire()
+        if id not in self.guests:
+            self.guests[id] = (guest, thread)
+        else:
+            del guest
+        self.guests_sem.release()
diff --git a/mom/GuestMonitor.py b/mom/GuestMonitor.py
index e7a7ca2..5fc3a96 100644
--- a/mom/GuestMonitor.py
+++ b/mom/GuestMonitor.py
@@ -52,10 +52,10 @@
 
 
 class GuestMonitorThread(threading.Thread):
-    def __init__(self, info, monitor):
+    def __init__(self, name, monitor):
         threading.Thread.__init__(self, name="guest:%s" % id)
 
-        self.setName("GuestMonitor-%s" % info['name'])
+        self.setName("GuestMonitor-%s" % name)
         self.setDaemon(True)
         self.logger = logging.getLogger('mom.GuestMonitor')
 
diff --git a/mom/__init__.py b/mom/__init__.py
index 2f0a0a8..e6b265c 100644
--- a/mom/__init__.py
+++ b/mom/__init__.py
@@ -33,6 +33,9 @@
         policy_engine = PolicyEngine(self.config, hypervisor_iface, 
host_monitor, \
                                      guest_manager)
 
+        # delegation
+        self.register = guest_manager.register
+
         threads = { 'host_monitor': host_monitor,
                          'guest_manager': guest_manager,
                          'policy_engine': policy_engine }


-- 
To view, visit http://gerrit.ovirt.org/31598
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I60e3b6aafb877a78813444870d93340e1325b82e
Gerrit-PatchSet: 1
Gerrit-Project: mom
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <from...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to