예제 #1
0
파일: model.py 프로젝트: zmrblog/kimchi
    def __init__(self, libvirt_uri=None, objstore_loc=None):

        self.objstore = ObjectStore(objstore_loc or config.get_object_store())
        self.conn = LibvirtConnection(libvirt_uri)

        # Register for libvirt events
        self.events = LibvirtEvents()
        self.events.handleEnospc(self.conn)
        self.events.registerPoolEvents(self.conn, self._events_handler,
                                       'storages')
        self.events.registerNetworkEvents(self.conn, self._events_handler,
                                          'networks')
        self.events.registerDomainEvents(self.conn, self._events_handler,
                                         'vms')

        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_model_instances('wok.model.tasks')
        for instance in instances:
            models.append(instance(**kargs))

        super(Model, self).__init__(models)
예제 #2
0
파일: model.py 프로젝트: zmrblog/kimchi
class Model(BaseModel):
    def __init__(self, libvirt_uri=None, objstore_loc=None):

        self.objstore = ObjectStore(objstore_loc or config.get_object_store())
        self.conn = LibvirtConnection(libvirt_uri)

        # Register for libvirt events
        self.events = LibvirtEvents()
        self.events.handleEnospc(self.conn)
        self.events.registerPoolEvents(self.conn, self._events_handler,
                                       'storages')
        self.events.registerNetworkEvents(self.conn, self._events_handler,
                                          'networks')
        self.events.registerDomainEvents(self.conn, self._events_handler,
                                         'vms')

        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_model_instances('wok.model.tasks')
        for instance in instances:
            models.append(instance(**kargs))

        super(Model, self).__init__(models)

    def _events_handler(self, conn, pool, ev, details, opaque):
        # Do not use any known method (POST, PUT, DELETE) as it is used by Wok
        # engine and may lead in having 2 notifications for the same action
        send_wok_notification('/plugins/kimchi', opaque, 'METHOD')
예제 #3
0
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.handleEnospc(self.conn)

        # Import task model from Wok
        instances = get_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)
예제 #4
0
파일: model.py 프로젝트: MontePreso/kimchi
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.handleEnospc(self.conn)

        # Import task model from Wok
        instances = get_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)
예제 #5
0
class Model(BaseModel):
    def __init__(self, libvirt_uri=None, objstore_loc=None):

        self.objstore = ObjectStore(objstore_loc or config.get_object_store())
        self.conn = LibvirtConnection(libvirt_uri)

        # 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_model_instances('wok.model.tasks')
        for instance in instances:
            models.append(instance(**kargs))

        return super(Model, self).__init__(models)
예제 #6
0
    def __init__(self, libvirt_uri=None, objstore_loc=None):

        self.objstore = ObjectStore(objstore_loc or config.get_object_store())
        self.conn = LibvirtConnection(libvirt_uri)

        # 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_model_instances('wok.model.tasks')
        for instance in instances:
            models.append(instance(**kargs))

        return super(Model, self).__init__(models)