コード例 #1
0
ファイル: root.py プロジェクト: w796933/kimchi
    def __init__(self, wok_options):
        make_dirs = [
            os.path.dirname(os.path.abspath(config.get_object_store())),
            os.path.abspath(config.get_distros_store()),
            os.path.abspath(config.get_screenshot_path()),
            os.path.abspath(config.get_virtviewerfiles_path())
        ]
        for directory in make_dirs:
            if not os.path.isdir(directory):
                os.makedirs(directory)

        # When running on test mode, specify the objectstore location to
        # remove the file on server shutting down. That way, the system will
        # not suffer any change while running on test mode
        if wok_options.test and (wok_options.test is True
                                 or wok_options.test.lower() == 'true'):
            self.objectstore_loc = tempfile.mktemp()
            self.model = mockmodel.MockModel(self.objectstore_loc)

            def remove_objectstore():
                if os.path.exists(self.objectstore_loc):
                    os.unlink(self.objectstore_loc)

            cherrypy.engine.subscribe('exit', remove_objectstore)
        else:
            self.model = kimchiModel.Model()

        dev_env = wok_options.environment != 'production'
        super(Kimchi, self).__init__(self.model, dev_env)

        for ident, node in sub_nodes.items():
            setattr(self, ident, node(self.model))

        self.api_schema = json.load(
            open(
                os.path.join(os.path.dirname(os.path.abspath(__file__)),
                             'API.json')))
        self.paths = config.kimchiPaths
        self.domain = 'kimchi'
        self.messages = messages

        self.extends = {
            "/plugins/gingerbase": {
                "host-dashboard.html": "/plugins/kimchi/js/kimchi.peers.js"
            }
        }

        self.depends = ['gingerbase']

        # Some paths or URI's present in the objectstore have changed after
        # Kimchi 2.0.0 release. Check here if an upgrade in the schema and data
        # are necessary.
        if upgrade_objectstore_schema(config.get_object_store(), 'version'):
            upgrade_objectstore_data('icon', 'images', 'plugins/kimchi/')
            upgrade_objectstore_data('storagepool', '/storagepools',
                                     '/plugins/kimchi')
            upgrade_objectstore_template_disks(self.model.conn)

        # Upgrade memory data, if necessary
        upgrade_objectstore_memory()
コード例 #2
0
ファイル: root.py プロジェクト: alinefm/kimchi
    def __init__(self, wok_options):
        make_dirs = [
            os.path.dirname(os.path.abspath(config.get_object_store())),
            os.path.abspath(config.get_distros_store()),
            os.path.abspath(config.get_screenshot_path()),
            os.path.abspath(config.get_virtviewerfiles_path()),
        ]
        for directory in make_dirs:
            if not os.path.isdir(directory):
                os.makedirs(directory)

        # When running on test mode, specify the objectstore location to
        # remove the file on server shutting down. That way, the system will
        # not suffer any change while running on test mode
        if wok_options.test and (
            wok_options.test is True or wok_options.test.lower() == 'true'
        ):
            self.objectstore_loc = tempfile.mktemp()
            self.model = mockmodel.MockModel(self.objectstore_loc)

            def remove_objectstore():
                if os.path.exists(self.objectstore_loc):
                    os.unlink(self.objectstore_loc)

            cherrypy.engine.subscribe('exit', remove_objectstore)
        else:
            self.model = kimchiModel.Model()

        dev_env = wok_options.environment != 'production'
        super(Kimchi, self).__init__(self.model, dev_env)

        for ident, node in sub_nodes.items():
            setattr(self, ident, node(self.model))

        with open(
            os.path.join(os.path.dirname(
                os.path.abspath(__file__)), 'API.json')
        ) as fd:
            self.api_schema = json.load(fd)

        self.paths = config.kimchiPaths
        self.domain = 'kimchi'
        self.messages = messages

        # Some paths or URI's present in the objectstore have changed after
        # Kimchi 2.0.0 release. Check here if an upgrade in the schema and data
        # are necessary.
        if upgrade_objectstore_schema(config.get_object_store(), 'version'):
            upgrade_objectstore_data('icon', 'images', 'plugins/kimchi/')
            upgrade_objectstore_data(
                'storagepool', '/storagepools', '/plugins/kimchi')
            upgrade_objectstore_template_disks(self.model.conn)

        # Upgrade memory data, if necessary
        upgrade_objectstore_memory()
コード例 #3
0
    def __init__(self, wok_options):
        make_dirs = [
            os.path.dirname(os.path.abspath(config.get_object_store())),
            os.path.abspath(config.get_distros_store()),
            os.path.abspath(config.get_screenshot_path()),
            os.path.abspath(config.get_virtviewerfiles_path())
        ]
        for directory in make_dirs:
            if not os.path.isdir(directory):
                os.makedirs(directory)

        if hasattr(wok_options, "model"):
            self.model = wok_options.model
        elif wok_options.test:
            self.model = mockmodel.MockModel()
        else:
            self.model = kimchiModel.Model()

        dev_env = wok_options.environment != 'production'
        super(Kimchi, self).__init__(self.model, dev_env)

        for ident, node in sub_nodes.items():
            setattr(self, ident, node(self.model))

        if isinstance(self.model, kimchiModel.Model):
            ws_proxy = websocket.new_ws_proxy()
            cherrypy.engine.subscribe('exit', ws_proxy.terminate)

        self.api_schema = json.load(
            open(
                os.path.join(os.path.dirname(os.path.abspath(__file__)),
                             'API.json')))
        self.paths = config.kimchiPaths
        self.domain = 'kimchi'
        self.messages = messages

        self.extends = {
            "/plugins/gingerbase": {
                "host-dashboard.html": "/plugins/kimchi/js/kimchi.peers.js"
            }
        }

        # Some paths or URI's present in the objectstore have changed after
        # Kimchi 2.0.0 release. Check here if an upgrade in the schema and data
        # are necessary.
        if upgrade_objectstore_schema(config.get_object_store(), 'version'):
            upgrade_objectstore_data('icon', 'images', 'plugins/kimchi/')
            upgrade_objectstore_data('storagepool', '/storagepools',
                                     '/plugins/kimchi')
            upgrade_objectstore_template_disks(self.model.conn)

        # Upgrade memory data, if necessary
        upgrade_objectstore_memory()
コード例 #4
0
    def __init__(self, wok_options):
        make_dirs = [
            os.path.dirname(os.path.abspath(config.get_object_store())),
            os.path.abspath(config.get_distros_store()),
            os.path.abspath(config.get_screenshot_path()),
            os.path.abspath(config.get_virtviewerfiles_path())
        ]
        for directory in make_dirs:
            if not os.path.isdir(directory):
                os.makedirs(directory)

        if hasattr(wok_options, "model"):
            self.model = wok_options.model
        elif wok_options.test:
            self.model = mockmodel.MockModel()
        else:
            self.model = kimchiModel.Model()

        dev_env = wok_options.environment != 'production'
        super(Kimchi, self).__init__(self.model, dev_env)

        for ident, node in sub_nodes.items():
            setattr(self, ident, node(self.model))

        if isinstance(self.model, kimchiModel.Model):
            ws_proxy = websocket.new_ws_proxy()
            cherrypy.engine.subscribe('exit', ws_proxy.terminate)

        self.api_schema = json.load(open(os.path.join(os.path.dirname(
                                    os.path.abspath(__file__)), 'API.json')))
        self.paths = config.kimchiPaths
        self.domain = 'kimchi'
        self.messages = messages

        self.extends = {
            "/plugins/gingerbase": {
                "host-dashboard.html": "/plugins/kimchi/js/kimchi.peers.js"
            }
        }

        # Some paths or URI's present in the objectstore have changed after
        # Kimchi 2.0.0 release. Check here if an upgrade in the schema and data
        # are necessary.
        if upgrade_objectstore_schema(config.get_object_store(), 'version'):
            upgrade_objectstore_data('icon', 'images', 'plugins/kimchi/')
            upgrade_objectstore_data('storagepool', '/storagepools',
                                     '/plugins/kimchi')
            upgrade_objectstore_template_disks(self.model.conn)

        # Upgrade memory data, if necessary
        upgrade_objectstore_memory()
コード例 #5
0
ファイル: root.py プロジェクト: sdnnfv/kimchi
    def __init__(self, wok_options):
        if hasattr(wok_options, "model"):
            self.model = wok_options.model
        elif wok_options.test:
            self.model = mockmodel.MockModel()
        else:
            self.model = kimchiModel.Model()

        dev_env = wok_options.environment != 'production'
        super(KimchiRoot, self).__init__(self.model, dev_env)

        for ident, node in sub_nodes.items():
            setattr(self, ident, node(self.model))

        if isinstance(self.model, kimchiModel.Model):
            vnc_ws_proxy = vnc.new_ws_proxy()
            cherrypy.engine.subscribe('exit', vnc_ws_proxy.terminate)

        self.api_schema = json.load(
            open(
                os.path.join(os.path.dirname(os.path.abspath(__file__)),
                             'API.json')))
        self.paths = config.kimchiPaths
        self.domain = 'kimchi'
        self.messages = messages

        make_dirs = [
            os.path.dirname(os.path.abspath(config.get_object_store())),
            os.path.abspath(config.get_distros_store()),
            os.path.abspath(config.get_debugreports_path()),
            os.path.abspath(config.get_screenshot_path())
        ]
        for directory in make_dirs:
            if not os.path.isdir(directory):
                os.makedirs(directory)
コード例 #6
0
ファイル: utils.py プロジェクト: alinefm/kimchi
def upgrade_objectstore_data(item, old_uri, new_uri):
    """
        Upgrade the value of a given JSON's item of all Template and VM entries
        of the objectstore from old_uri to new_uri.
    """
    total = 0
    try:
        conn = sqlite3.connect(config.get_object_store(), timeout=10)
        cursor = conn.cursor()
        sql = "SELECT id, json FROM objects WHERE type='template' OR type='vm'"
        cursor.execute(sql)
        for row in cursor.fetchall():
            # execute update here
            template = json.loads(row[1])
            path = template[item] if item in template else 'none'
            if path.startswith(old_uri):
                template[item] = new_uri + path
                sql = 'UPDATE objects SET json=?, version=? WHERE id=?'
                cursor.execute(
                    sql, (json.dumps(template),
                          config.get_kimchi_version(), row[0])
                )
                conn.commit()
                total += 1
    except sqlite3.Error as e:
        if conn:
            conn.rollback()
        wok_log.error('Error while upgrading objectstore data: %s', e.args[0])
        raise OperationFailed('KCHUTILS0006E')
    finally:
        if conn:
            conn.close()
        wok_log.info("%d '%s' entries upgraded in objectstore.", total, item)
コード例 #7
0
ファイル: model.py プロジェクト: mahak/kimchi
    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)
コード例 #8
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)
コード例 #9
0
ファイル: root.py プロジェクト: weixshen/kimchi
    def __init__(self, wok_options):
        if hasattr(wok_options, "model"):
            self.model = wok_options.model
        elif wok_options.test:
            self.model = mockmodel.MockModel()
        else:
            self.model = kimchiModel.Model()

        dev_env = wok_options.environment != 'production'
        super(KimchiRoot, self).__init__(self.model, dev_env)

        for ident, node in sub_nodes.items():
            setattr(self, ident, node(self.model))

        if isinstance(self.model, kimchiModel.Model):
            vnc_ws_proxy = vnc.new_ws_proxy()
            cherrypy.engine.subscribe('exit', vnc_ws_proxy.terminate)

        self.api_schema = json.load(open(os.path.join(os.path.dirname(
                                    os.path.abspath(__file__)), 'API.json')))
        self.paths = config.kimchiPaths
        self.domain = 'kimchi'
        self.messages = messages

        make_dirs = [
            os.path.dirname(os.path.abspath(config.get_object_store())),
            os.path.abspath(config.get_distros_store()),
            os.path.abspath(config.get_screenshot_path())
        ]
        for directory in make_dirs:
            if not os.path.isdir(directory):
                os.makedirs(directory)
コード例 #10
0
def upgrade_objectstore_data(item, old_uri, new_uri):
    """
        Upgrade the value of a given JSON's item of all Template and VM entries
        of the objectstore from old_uri to new_uri.
    """
    total = 0
    try:
        conn = sqlite3.connect(config.get_object_store(), timeout=10)
        cursor = conn.cursor()
        sql = "SELECT id, json FROM objects WHERE type='template' OR type='vm'"
        cursor.execute(sql)
        for row in cursor.fetchall():
            # execute update here
            template = json.loads(row[1])
            path = (template[item] if item in template else 'none')
            if path.startswith(old_uri):
                template[item] = new_uri + path
                sql = "UPDATE objects SET json=?, version=? WHERE id=?"
                cursor.execute(sql, (json.dumps(template),
                                     config.get_kimchi_version(), row[0]))
                conn.commit()
                total += 1
    except sqlite3.Error, e:
        if conn:
            conn.rollback()
        wok_log.error("Error while upgrading objectstore data: %s", e.args[0])
        raise OperationFailed("KCHUTILS0006E")
コード例 #11
0
ファイル: utils.py プロジェクト: Truja/kimchi
def get_objectstore_fields():
    """
        Return a list with all fields of the objectstore.
    """
    conn = sqlite3.connect(config.get_object_store(), timeout=10)
    cursor = conn.cursor()
    schema_fields = []
    sql = "PRAGMA table_info('objects')"
    cursor.execute(sql)
    for row in cursor.fetchall():
        schema_fields.append(row[1])
    return schema_fields
コード例 #12
0
ファイル: utils.py プロジェクト: pengoC/kimchi
def get_objectstore_fields():
    """
        Return a list with all fields of the objectstore.
    """
    conn = sqlite3.connect(config.get_object_store(), timeout=10)
    cursor = conn.cursor()
    schema_fields = []
    sql = "PRAGMA table_info('objects')"
    cursor.execute(sql)
    for row in cursor.fetchall():
        schema_fields.append(row[1])
    return schema_fields
コード例 #13
0
def upgrade_objectstore_template_disks(libv_conn):
    """
        Upgrade the value of a given JSON's item of all Templates.
        Removes 'storagepool' entry and adds
        'pool: { name: ..., type: ... }'
    """
    total = 0
    try:
        conn = sqlite3.connect(config.get_object_store(), timeout=10)
        cursor = conn.cursor()
        sql = "SELECT id, json FROM objects WHERE type='template'"
        cursor.execute(sql)
        for row in cursor.fetchall():
            template = json.loads(row[1])

            # Get pool info
            pool_uri = template['storagepool']
            pool_name = pool_name_from_uri(pool_uri)
            pool = libv_conn.get().storagePoolLookupByName(
                pool_name.encode('utf-8'))
            pool_type = xpath_get_text(pool.XMLDesc(0), '/pool/@type')[0]

            # Update json
            new_disks = []
            for disk in template['disks']:
                disk['pool'] = {'name': pool_uri, 'type': pool_type}
                new_disks.append(disk)
            template['disks'] = new_disks
            del template['storagepool']

            sql = 'UPDATE objects SET json=? WHERE id=?'
            cursor.execute(sql, (json.dumps(template), row[0]))
            conn.commit()
            total += 1
    except sqlite3.Error as e:
        if conn:
            conn.rollback()
        wok_log.error('Error while upgrading objectstore data: %s', e.args[0])
        raise OperationFailed('KCHUTILS0006E')
    finally:
        if conn:
            conn.close()
        wok_log.info("%d 'template' entries upgraded in objectstore.", total)
コード例 #14
0
ファイル: utils.py プロジェクト: alinefm/kimchi
def upgrade_objectstore_memory():
    """
        Upgrade the value of a given JSON's item of all Templates.
        Changes 'memory': XXX by 'memory': {'current': XXXX,
                                            'maxmemory': XXXX}
    """
    total = 0
    try:
        conn = sqlite3.connect(config.get_object_store(), timeout=10)
        cursor = conn.cursor()
        sql = "SELECT id,json FROM objects WHERE type='template'"
        cursor.execute(sql)
        for row in cursor.fetchall():
            template = json.loads(row[1])

            # Get memory info
            memory = template['memory']
            # New memory is a dictionary with 'current' and 'maxmemory'
            if type(memory) is not dict:
                maxmem = get_template_default(
                    'modern', 'memory').get('maxmemory')
                if maxmem < memory:
                    maxmem = memory
                template['memory'] = {'current': memory, 'maxmemory': maxmem}
            else:
                continue

            sql = 'UPDATE objects SET json=? WHERE id=?'
            cursor.execute(sql, (json.dumps(template), row[0]))
            conn.commit()
            total += 1
    except sqlite3.Error as e:
        if conn:
            conn.rollback()
        wok_log.error('Error while upgrading objectstore data: %s', e.args[0])
        raise OperationFailed('KCHUTILS0006E')
    finally:
        if conn:
            conn.close()
        if total > 0:
            wok_log.info(
                "%d 'template' memory entries upgraded in objectstore.", total)
コード例 #15
0
ファイル: utils.py プロジェクト: alinefm/kimchi
def upgrade_objectstore_template_disks(libv_conn):
    """
        Upgrade the value of a given JSON's item of all Templates.
        Removes 'storagepool' entry and adds
        'pool: { name: ..., type: ... }'
    """
    total = 0
    try:
        conn = sqlite3.connect(config.get_object_store(), timeout=10)
        cursor = conn.cursor()
        sql = "SELECT id, json FROM objects WHERE type='template'"
        cursor.execute(sql)
        for row in cursor.fetchall():
            template = json.loads(row[1])

            # Get pool info
            pool_uri = template['storagepool']
            pool_name = pool_name_from_uri(pool_uri)
            pool = libv_conn.get().storagePoolLookupByName(pool_name.encode('utf-8'))
            pool_type = xpath_get_text(pool.XMLDesc(0), '/pool/@type')[0]

            # Update json
            new_disks = []
            for disk in template['disks']:
                disk['pool'] = {'name': pool_uri, 'type': pool_type}
                new_disks.append(disk)
            template['disks'] = new_disks
            del template['storagepool']

            sql = 'UPDATE objects SET json=? WHERE id=?'
            cursor.execute(sql, (json.dumps(template), row[0]))
            conn.commit()
            total += 1
    except sqlite3.Error as e:
        if conn:
            conn.rollback()
        wok_log.error('Error while upgrading objectstore data: %s', e.args[0])
        raise OperationFailed('KCHUTILS0006E')
    finally:
        if conn:
            conn.close()
        wok_log.info("%d 'template' entries upgraded in objectstore.", total)
コード例 #16
0
def upgrade_objectstore_memory():
    """
        Upgrade the value of a given JSON's item of all Templates.
        Changes 'memory': XXX by 'memory': {'current': XXXX,
                                            'maxmemory': XXXX}
    """
    total = 0
    try:
        conn = sqlite3.connect(config.get_object_store(), timeout=10)
        cursor = conn.cursor()
        sql = "SELECT id,json FROM objects WHERE type='template'"
        cursor.execute(sql)
        for row in cursor.fetchall():
            template = json.loads(row[1])

            # Get memory info
            memory = template['memory']
            # New memory is a dictionary with 'current' and 'maxmemory'
            if type(memory) is not dict:
                maxmem = get_template_default('modern',
                                              'memory').get('maxmemory')
                if maxmem < memory:
                    maxmem = memory
                template['memory'] = {'current': memory, 'maxmemory': maxmem}
            else:
                continue

            sql = 'UPDATE objects SET json=? WHERE id=?'
            cursor.execute(sql, (json.dumps(template), row[0]))
            conn.commit()
            total += 1
    except sqlite3.Error as e:
        if conn:
            conn.rollback()
        wok_log.error('Error while upgrading objectstore data: %s', e.args[0])
        raise OperationFailed('KCHUTILS0006E')
    finally:
        if conn:
            conn.close()
        if total > 0:
            wok_log.info(
                "%d 'template' memory entries upgraded in objectstore.", total)
コード例 #17
0
ファイル: model.py プロジェクト: open-power-host-os/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'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)
コード例 #18
0
ファイル: model.py プロジェクト: MontePreso/kimchi
    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)
コード例 #19
0
ファイル: utils.py プロジェクト: Truja/kimchi
def upgrade_objectstore_schema(field=None):
    """
        Add a new column (of type TEXT) in the objectstore schema.
    """
    if field is None:
        wok_log.error("Cannot upgrade objectstore schema.")
        return False

    if field in get_objectstore_fields():
        return False
    try:
        conn = sqlite3.connect(config.get_object_store(), timeout=10)
        cursor = conn.cursor()
        sql = "ALTER TABLE objects ADD COLUMN %s TEXT" % field
        cursor.execute(sql)
        wok_log.info("Objectstore schema sucessfully upgraded.")
        conn.close()
    except sqlite3.Error, e:
        if conn:
            conn.rollback()
            conn.close()
        wok_log.error("Cannot upgrade objectstore schema: ", e.args[0])
        return False
コード例 #20
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)
コード例 #21
0
ファイル: utils.py プロジェクト: pengoC/kimchi
def upgrade_objectstore_schema(field=None):
    """
        Add a new column (of type TEXT) in the objectstore schema.
    """
    if field is None:
        wok_log.error("Cannot upgrade objectstore schema.")
        return False

    if field in get_objectstore_fields():
        return False
    try:
        conn = sqlite3.connect(config.get_object_store(), timeout=10)
        cursor = conn.cursor()
        sql = "ALTER TABLE objects ADD COLUMN %s TEXT" % field
        cursor.execute(sql)
        wok_log.info("Objectstore schema sucessfully upgraded.")
        conn.close()
    except sqlite3.Error, e:
        if conn:
            conn.rollback()
            conn.close()
        wok_log.error("Cannot upgrade objectstore schema: ", e.args[0])
        return False