Пример #1
0
    def _get_ref_cnt(self, pool, name, path):
        vol_id = '%s:%s' % (pool, name)
        try:
            with self.objstore as session:
                try:
                    ref_cnt = session.get('storagevolume', vol_id)['ref_cnt']
                except NotFoundError:
                    # Fix storage volume created outside kimchi scope
                    ref_cnt = 0
                    # try to find this volume in exsisted vm
                    vms = VMsModel.get_vms(self.conn)
                    for vm in vms:
                        dom = VMModel.get_vm(vm, self.conn)
                        storages = get_vm_disk_list(dom)
                        for disk in storages:
                            d_info = get_vm_disk(dom, disk)
                            if path == d_info['path']:
                                ref_cnt = ref_cnt + 1
                    session.store('storagevolume', vol_id,
                                  {'ref_cnt': ref_cnt})
        except Exception as e:
            # This exception is going to catch errors returned by 'with',
            # specially ones generated by 'session.store'. It is outside
            # to avoid conflict with the __exit__ function of 'with'
            raise OperationFailed('KCHVOL0017E', {'err': e.message})

        return ref_cnt
Пример #2
0
    def _get_unavailable_devices(self):
        vm_list = VMsModel.get_vms(self.conn)
        unavailable_devs = []
        for vm in vm_list:
            dom = VMModel.get_vm(vm, self.conn)
            xmlstr = dom.XMLDesc(0)
            root = objectify.fromstring(xmlstr)
            try:
                hostdev = root.devices.hostdev
            except AttributeError:
                continue

            vm_devs = [DeviceModel.deduce_dev_name(e, self.conn)
                       for e in hostdev]

            for dev in vm_devs:
                unavailable_devs.append(dev)

        return unavailable_devs
Пример #3
0
    def _get_ref_cnt(self, pool, name, path):
        vol_id = '%s:%s' % (pool, name)
        with self.objstore as session:
            try:
                ref_cnt = session.get('storagevolume', vol_id)['ref_cnt']
            except NotFoundError:
                # Fix storage volume created outside kimchi scope
                ref_cnt = 0
                args = {'conn': self.conn, 'objstore': self.objstore}
                # try to find this volume in exsisted vm
                vms = VMsModel.get_vms(self.conn)
                for vm in vms:
                    storages = VMStoragesModel(**args).get_list(vm)
                    for disk in storages:
                        d_info = VMStorageModel(**args).lookup(vm, disk)
                        if path == d_info['path']:
                            ref_cnt = ref_cnt + 1
                session.store('storagevolume', vol_id, {'ref_cnt': ref_cnt})

        return ref_cnt
Пример #4
0
def get_disk_ref_cnt(objstore, conn, path):
    try:
        with objstore as session:
            try:
                ref_cnt = session.get('storagevolume', path)['ref_cnt']
            except NotFoundError:
                kimchi_log.info('Volume %s not found in obj store.' % path)
                ref_cnt = 0
                # try to find this volume in existing vm
                vms_list = VMsModel.get_vms(conn)
                for vm in vms_list:
                    dom = VMModel.get_vm(vm, conn)
                    storages = get_vm_disks(dom)
                    for disk in storages.keys():
                        d_info = get_vm_disk_info(dom, disk)
                        if path == d_info['path']:
                            ref_cnt = ref_cnt + 1
                try:
                    session.store('storagevolume', path,
                                  {'ref_cnt': ref_cnt})
                except Exception as e:
                    # Let the exception be raised. If we allow disks'
                    #   ref_cnts to be out of sync, data corruption could
                    #   occour if a disk is added to two guests
                    #   unknowingly.
                    kimchi_log.error('Unable to store storage volume id in'
                                     ' objectstore due error: %s',
                                     e.message)
                    raise OperationFailed('KCHVOL0017E',
                                          {'err': e.message})
    except Exception as e:
        # This exception is going to catch errors returned by 'with',
        # specially ones generated by 'session.store'. It is outside
        # to avoid conflict with the __exit__ function of 'with'
        raise OperationFailed('KCHVOL0017E', {'err': e.message})
    return ref_cnt