def _get_cell_mapping(self): session = db_api.get_api_session() with session.begin(): cell_map = (session.query(api_models.CellMapping).join( api_models.HostMapping).filter( api_models.HostMapping.host == self.host).first()) if cell_map is not None: return CellMapping._from_db_object(self._context, CellMapping(), cell_map)
def _from_db_object(context, host_mapping, db_host_mapping): for key in host_mapping.fields: db_value = db_host_mapping.get(key) if key == "cell_mapping": # NOTE(dheeraj): If cell_mapping is stashed in db object # we load it here. Otherwise, lazy loading will happen # when .cell_mapping is accessd later if not db_value: continue db_value = CellMapping._from_db_object(host_mapping._context, CellMapping(), db_value) setattr(host_mapping, key, db_value) host_mapping.obj_reset_changes() host_mapping._context = context return host_mapping
def _get_cell_mapping(self): session = db_api.get_api_session() with session.begin(): cell_map = (session.query(api_models.CellMapping) .join(api_models.HostMapping) .filter(api_models.HostMapping.host == self.host) .first()) if cell_map is not None: return CellMapping._from_db_object( self._context, CellMapping(), cell_map)
def _from_db_object(context, host_mapping, db_host_mapping): for key in host_mapping.fields: db_value = db_host_mapping.get(key) if key == "cell_mapping": # NOTE(dheeraj): If cell_mapping is stashed in db object # we load it here. Otherwise, lazy loading will happen # when .cell_mapping is accessd later if not db_value: continue db_value = CellMapping._from_db_object( host_mapping._context, CellMapping(), db_value) setattr(host_mapping, key, db_value) host_mapping.obj_reset_changes() host_mapping._context = context return host_mapping