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
def get_list(self, vm_name): dom = VMModel.get_vm(vm_name, self.conn) return get_vm_disk_list(dom)