Пример #1
0
    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.conn = LibvirtConnection(libvirt_uri)
        kargs = {'objstore': self.objstore, 'conn': self.conn}
        models = []

        # 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)
Пример #2
0
def load_url_sub_node(path, package_name, expect_attr="_url_sub_node_name"):
    sub_nodes = {}
    for mod_name in listPathModules(path):
        if mod_name.startswith("_"):
            continue

        module = import_module(package_name + '.' + mod_name)

        for node in [getattr(module, x) for x in dir(module)]:
            if not hasattr(node, expect_attr):
                continue
            name = getattr(node, expect_attr)["name"]
            sub_nodes.update({name: node})

    return sub_nodes
Пример #3
0
def load_url_sub_node(path, package_name, expect_attr="_url_sub_node_name"):
    sub_nodes = {}
    for mod_name in listPathModules(path):
        if mod_name.startswith("_"):
            continue

        module = import_module(package_name + '.' + mod_name)

        for node in [getattr(module, x) for x in dir(module)]:
            if not hasattr(node, expect_attr):
                continue
            name = getattr(node, expect_attr)["name"]
            sub_nodes.update({name: node})

    return sub_nodes
Пример #4
0
    def __init__(self):
        self.features = {}

        pckg_namespace = __name__.rsplit('.', 1)[0]

        for mod_name in listPathModules(os.path.dirname(__file__)):
            if mod_name.startswith("_") or mod_name == 'capabilities':
                continue

            instances = get_model_instances(pckg_namespace + '.' + mod_name)
            for instance in instances:
                feat_name = instance.__name__.replace('Model', '')
                try:
                    self.features[feat_name] = instance.is_feature_available
                except AttributeError:
                    self.features[feat_name] = None
Пример #5
0
    def __init__(self, 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

        if objstore_loc is None:
            objstore_loc = config.get_object_store()

        # Some paths or URI's present in the objectstore have changed after
        # Wok 2.0.0 release. Check here if a schema upgrade is necessary.
        upgrade_objectstore_schema(objstore_loc, 'version')

        self.objstore = ObjectStore(objstore_loc)
        kargs = {'objstore': self.objstore}

        models = []
        # 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.gingerbase.model.' +
                                      mod_name)
            for instance in instances:
                models.append(instance(**kargs))

        return super(Model, self).__init__(models)
Пример #6
0
    def __init__(self, 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

        if objstore_loc is None:
            objstore_loc = config.get_object_store()

        # Some paths or URI's present in the objectstore have changed after
        # Wok 2.0.0 release. Check here if a schema upgrade is necessary.
        upgrade_objectstore_schema(objstore_loc, 'version')

        self.objstore = ObjectStore(objstore_loc)
        kargs = {'objstore': self.objstore}

        models = []
        # 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.gingerbase.model.' +
                                      mod_name)
            for instance in instances:
                models.append(instance(**kargs))

        return super(Model, self).__init__(models)
Пример #7
0
    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)
Пример #8
0
    def __init__(self, objstore_loc=None):

        self.objstore = ObjectStore(objstore_loc)
        kargs = {'objstore': self.objstore}

        this = os.path.basename(__file__)
        this_mod = os.path.splitext(this)[0]

        models = []
        for mod_name in listPathModules(os.path.dirname(__file__)):
            if mod_name.startswith("_") or mod_name == this_mod:
                continue

            module = import_module('wok.model.' + mod_name)
            members = inspect.getmembers(module, inspect.isclass)
            for cls_name, instance in members:
                if inspect.getmodule(instance) == module:
                    if cls_name.endswith('Model'):
                        models.append(instance(**kargs))

        return super(Model, self).__init__(models)
Пример #9
0
    def __init__(self, objstore_loc=None):

        self.objstore = ObjectStore(objstore_loc)
        kargs = {'objstore': self.objstore}

        this = os.path.basename(__file__)
        this_mod = os.path.splitext(this)[0]

        models = []
        for mod_name in listPathModules(os.path.dirname(__file__)):
            if mod_name.startswith("_") or mod_name == this_mod:
                continue

            module = import_module('wok.model.' + mod_name)
            members = inspect.getmembers(module, inspect.isclass)
            for cls_name, instance in members:
                if inspect.getmodule(instance) == module:
                    if cls_name.endswith('Model'):
                        models.append(instance(**kargs))

        return super(Model, self).__init__(models)
Пример #10
0
    def __init__(self, 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

        if objstore_loc is None:
            objstore_loc = config.get_object_store()

        self.objstore = ObjectStore(objstore_loc)
        kargs = {'objstore': self.objstore}

        models = []
        # Import task model from Wok
        instances = get_instances('wok.model.tasks')
        for instance in instances:
            models.append(instance(**kargs))

        # Import all gingers390x 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.gingers390x.model.' + mod_name
            )
            for instance in instances:
                models.append(instance(**kargs))

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