def sync(self): """ :return: """ LOG.info('Syncing volumes for storage id:{0}'.format(self.storage_id)) try: # collect the volumes list from driver and database storage_volumes = self.driver_api.list_volumes( self.context, self.storage_id) db_volumes = db.volume_get_all( self.context, filters={"storage_id": self.storage_id}) add_list, update_list, delete_id_list = self._classify_resources( storage_volumes, db_volumes, 'native_volume_id') LOG.info('###StorageVolumeTask for {0}:add={1},delete={2},' 'update={3}'.format(self.storage_id, len(add_list), len(delete_id_list), len(update_list))) if delete_id_list: db.volumes_delete(self.context, delete_id_list) if update_list: db.volumes_update(self.context, update_list) if add_list: db.volumes_create(self.context, add_list) except Exception as e: msg = _('Failed to sync volumes entry in DB: {0}'.format(e)) LOG.error(msg) raise else: LOG.info("Syncing volumes successful!!!")
def index(self, req): ctxt = req.environ['delfin.context'] query_params = {} query_params.update(req.GET) # update options other than filters sort_keys, sort_dirs = api_utils.get_sort_params(query_params) marker, limit, offset = api_utils.get_pagination_params(query_params) # strip out options except supported search options api_utils.remove_invalid_options(ctxt, query_params, self._get_volumes_search_options()) volumes = db.volume_get_all(ctxt, marker, limit, sort_keys, sort_dirs, query_params, offset) return volume_view.build_volumes(volumes)
def db_resource_get_all(self, filters): return db.volume_get_all(self.context, filters=filters)