# Path: mom/GuestMonitor.py
# class GuestMonitor(Monitor):
#     """
#     A GuestMonitor thread collects and reports statistics about 1 running guest
#     """
#     def __init__(self, config, info, hypervisor_iface):
#         self.config = config
#         self.logger = logging.getLogger('mom.GuestMonitor')
#         self.interval = self.config.getint('main', 'guest-monitor-interval')
# 
#         Monitor.__init__(self, config, info['name'])
#         with self.data_lock:
#             self.properties.update(info)
#             self.properties['hypervisor_iface'] = hypervisor_iface
# 
#         collector_list = self.config.get('guest', 'collectors')
#         self.collectors = Collector.get_collectors(collector_list,
#                             self.properties, self.config)
#         if self.collectors is None:
#             self.logger.error("Guest Monitor initialization failed")
# 
#     def getGuestName(self):
#         """
#         Provide structured access to the guest name without calling hypervisor
#         interface.
#         """
#         return self.properties.get('name')
# 
# Path: mom/GuestMonitor.py
# class GuestMonitorThread(threading.Thread):
#     def __init__(self, info, monitor):
#         threading.Thread.__init__(self)
# 
#         name = "GuestMonitor-%s" % info['name']
#         if six.PY2:
#             # In python 2 the name should not have type 'unicode'.
#             # The name is only used for logging, so it should
#             # be safe to represent it in utf-8 encoding.
#             name = name.encode('utf-8')
# 
#         self.setName(name)
#         self.setDaemon(True)
#         self.logger = logging.getLogger('mom.GuestMonitor.Thread')
# 
#         self._mon = monitor
# 
#     def run(self):
#         try:
#             self.logger.info("%s starting", self.getName())
#             while self._mon.should_run():
#                 self._mon.collect()
#                 time.sleep(self._mon.interval)
#         except Exception:
#             self.logger.exception("%s crashed", self.getName())
#         else:
#             self.logger.info("%s ending", self.getName())


from collections import namedtuple
from mom.GuestMonitor import GuestMonitor
from mom.GuestMonitor import GuestMonitorThread
import threading
import time
import logging
            self.logger.error("Guest Manager crashed", exc_info=True)
        else:
            self.logger.info("Guest Manager ending")

    def _spawn_guest_monitors(self, domain_list):
        """
        Get the list of running domains and spawn GuestMonitors for any guests
        we are not already tracking.  The GuestMonitor constructor might block
        so don't hold guests_sem while calling it.
        """
        with self.guests_lock:
            spawn_list = set(domain_list) - set(self.guests)

        new_guests = {}
        for id in spawn_list:
            info = self.hypervisor_iface.getVmInfo(id)
            if info is None:
                self.logger.error("Failed to get guest:%s information -- monitor "\
                    "can't start", id)
                continue

            new_guests[id] = self._create_monitor(info)

        if new_guests:
            with self.guests_lock:
                for id, guest in new_guests.items():
                    if is_running(guest):
                        self._register_guest(id, guest)

    def _create_monitor(self, info):

# Path: mom/GuestMonitor.py
# class GuestMonitor(Monitor):
#     """
#     A GuestMonitor thread collects and reports statistics about 1 running guest
#     """
#     def __init__(self, config, info, hypervisor_iface):
#         self.config = config
#         self.logger = logging.getLogger('mom.GuestMonitor')
#         self.interval = self.config.getint('main', 'guest-monitor-interval')
# 
#         Monitor.__init__(self, config, info['name'])
#         with self.data_lock:
#             self.properties.update(info)
#             self.properties['hypervisor_iface'] = hypervisor_iface
# 
#         collector_list = self.config.get('guest', 'collectors')
#         self.collectors = Collector.get_collectors(collector_list,
#                             self.properties, self.config)
#         if self.collectors is None:
#             self.logger.error("Guest Monitor initialization failed")
# 
#     def getGuestName(self):
#         """
#         Provide structured access to the guest name without calling hypervisor
#         interface.
#         """
#         return self.properties.get('name')
# 
# Path: mom/GuestMonitor.py
# class GuestMonitorThread(threading.Thread):
#     def __init__(self, info, monitor):
#         threading.Thread.__init__(self)
# 
#         name = "GuestMonitor-%s" % info['name']
#         if six.PY2:
#             # In python 2 the name should not have type 'unicode'.
#             # The name is only used for logging, so it should
#             # be safe to represent it in utf-8 encoding.
#             name = name.encode('utf-8')
# 
#         self.setName(name)
#         self.setDaemon(True)
#         self.logger = logging.getLogger('mom.GuestMonitor.Thread')
# 
#         self._mon = monitor
# 
#     def run(self):
#         try:
#             self.logger.info("%s starting", self.getName())
#             while self._mon.should_run():
#                 self._mon.collect()
#                 time.sleep(self._mon.interval)
#         except Exception:
#             self.logger.exception("%s crashed", self.getName())
#         else:
#             self.logger.info("%s ending", self.getName())


# Path: mom/GuestManager.py
from collections import namedtuple
from mom.GuestMonitor import GuestMonitor
from mom.GuestMonitor import GuestMonitorThread
import threading
import time
import logging

            self.logger.error("Guest Manager crashed", exc_info=True)
        else:
            self.logger.info("Guest Manager ending")

    def _spawn_guest_monitors(self, domain_list):
        """
        Get the list of running domains and spawn GuestMonitors for any guests
        we are not already tracking.  The GuestMonitor constructor might block
        so don't hold guests_sem while calling it.
        """
        with self.guests_lock:
            spawn_list = set(domain_list) - set(self.guests)

        new_guests = {}
        for id in spawn_list:
            info = self.hypervisor_iface.getVmInfo(id)
            if info is None:
                self.logger.error("Failed to get guest:%s information -- monitor "\
                    "can't start", id)
                continue

            new_guests[id] = self._create_monitor(info)

        if new_guests:
            with self.guests_lock:
                for id, guest in new_guests.items():
                    if is_running(guest):
                        self._register_guest(id, guest)

    def _create_monitor(self, info):

        guest = GuestMonitor(self.config, info, self.hypervisor_iface)