def _save_helper(self, cell_type, update_cells): obj = instance_info_cache.InstanceInfoCache() cells_api = cells_rpcapi.CellsAPI() self.mox.StubOutWithMock(db, 'instance_info_cache_update') self.mox.StubOutWithMock(cells_opts, 'get_cell_type') self.mox.StubOutWithMock(cells_rpcapi, 'CellsAPI', use_mock_anything=True) self.mox.StubOutWithMock(cells_api, 'instance_info_cache_update_at_top') nwinfo = network_model.NetworkInfo.hydrate([{'address': 'foo'}]) db.instance_info_cache_update( self.context, 'fake-uuid', {'network_info': nwinfo.json()}).AndReturn('foo') if update_cells: cells_opts.get_cell_type().AndReturn(cell_type) if cell_type == 'compute': cells_rpcapi.CellsAPI().AndReturn(cells_api) cells_api.instance_info_cache_update_at_top( self.context, 'foo') self.mox.ReplayAll() obj._context = self.context obj.instance_uuid = 'fake-uuid' obj.network_info = nwinfo obj.save(update_cells=update_cells)
def _save_helper(self, cell_type, update_cells): obj = instance_info_cache.InstanceInfoCache() cells_api = cells_rpcapi.CellsAPI() self.mox.StubOutWithMock(db, 'instance_info_cache_update') self.mox.StubOutWithMock(cells_opts, 'get_cell_type') self.mox.StubOutWithMock(cells_rpcapi, 'CellsAPI', use_mock_anything=True) self.mox.StubOutWithMock(cells_api, 'instance_info_cache_update_at_top') nwinfo = network_model.NetworkInfo.hydrate([{'address': 'foo'}]) db.instance_info_cache_update(self.context, 'fake-uuid', { 'network_info': nwinfo.json() }).AndReturn('foo') if update_cells: cells_opts.get_cell_type().AndReturn(cell_type) if cell_type == 'compute': cells_rpcapi.CellsAPI().AndReturn(cells_api) cells_api.instance_info_cache_update_at_top( self.context, 'foo') self.mox.ReplayAll() obj._context = self.context obj.instance_uuid = 'fake-uuid' obj.network_info = nwinfo obj.save(update_cells=update_cells)
def _info_cache_cells_update(ctxt, info_cache): cell_type = cells_opts.get_cell_type() if cell_type != "compute": return cells_api = cells_rpcapi.CellsAPI() try: cells_api.instance_info_cache_update_at_top(ctxt, info_cache) except Exception: LOG.exception(_LE("Failed to notify cells of instance info " "cache update"))
def _info_cache_cells_update(ctxt, info_cache): cell_type = cells_opts.get_cell_type() if cell_type != 'compute': return cells_api = cells_rpcapi.CellsAPI() try: cells_api.instance_info_cache_update_at_top(ctxt, info_cache) except Exception: LOG.exception(_LE("Failed to notify cells of instance info " "cache update"))
def save(self): updates = self.obj_get_changes() if 'instance' in updates: raise exception.ObjectActionError(action='save', reason='instance changed') updates.pop('id', None) updated = db.block_device_mapping_update(self._context, self.id, updates, legacy=False) self._from_db_object(self._context, self, updated) cell_type = cells_opts.get_cell_type() if cell_type == 'compute': cells_api = cells_rpcapi.CellsAPI() cells_api.bdm_update_or_create_at_top(self._context, self)
def destroy(self): if not self.obj_attr_is_set('id'): raise exception.ObjectActionError(action='destroy', reason='already destroyed') db.block_device_mapping_destroy(self._context, self.id) delattr(self, base.get_attrname('id')) cell_type = cells_opts.get_cell_type() if cell_type == 'compute': cells_api = cells_rpcapi.CellsAPI() cells_api.bdm_destroy_at_top(self._context, self.instance_uuid, device_name=self.device_name, volume_id=self.volume_id)
def _create(self, context, update_or_create=False): """Create the block device record in the database. In case the id field is set on the object, and if the instance is set raise an ObjectActionError. Resets all the changes on the object. Returns None :param context: security context used for database calls :param update_or_create: consider existing block devices for the instance based on the device name and swap, and only update the ones that match. Normally only used when creating the instance for the first time. """ cell_type = cells_opts.get_cell_type() if cell_type == 'api': raise exception.ObjectActionError( action='create', reason='BlockDeviceMapping cannot be ' 'created in the API cell.') if self.obj_attr_is_set('id'): raise exception.ObjectActionError(action='create', reason='already created') updates = self.obj_get_changes() if 'instance' in updates: raise exception.ObjectActionError(action='create', reason='instance assigned') cells_create = update_or_create or None if update_or_create: db_bdm = db.block_device_mapping_update_or_create(context, updates, legacy=False) else: db_bdm = db.block_device_mapping_create(context, updates, legacy=False) self._from_db_object(context, self, db_bdm) if cell_type == 'compute': cells_api = cells_rpcapi.CellsAPI() cells_api.bdm_update_or_create_at_top(context, self, create=cells_create)
def _create(self, context, update_or_create=False): """Create the block device record in the database. In case the id field is set on the object, and if the instance is set raise an ObjectActionError. Resets all the changes on the object. Returns None :param context: security context used for database calls :param update_or_create: consider existing block devices for the instance based on the device name and swap, and only update the ones that match. Normally only used when creating the instance for the first time. """ cell_type = cells_opts.get_cell_type() if cell_type == 'api': raise exception.ObjectActionError( action='create', reason='BlockDeviceMapping cannot be ' 'created in the API cell.') if self.obj_attr_is_set('id'): raise exception.ObjectActionError(action='create', reason='already created') updates = self.obj_get_changes() if 'instance' in updates: raise exception.ObjectActionError(action='create', reason='instance assigned') cells_create = update_or_create or None if update_or_create: db_bdm = db.block_device_mapping_update_or_create( context, updates, legacy=False) else: db_bdm = db.block_device_mapping_create( context, updates, legacy=False) self._from_db_object(context, self, db_bdm) if cell_type == 'compute': cells_api = cells_rpcapi.CellsAPI() cells_api.bdm_update_or_create_at_top( context, self, create=cells_create)
def create(self): if self.obj_attr_is_set('id'): raise exception.ObjectActionError(action='create', reason='already created') values = { 'instance_uuid': self.instance_uuid, 'code': self.code, 'message': self.message, 'details': self.details, 'host': self.host, } db_fault = db.instance_fault_create(self._context, values) self._from_db_object(self._context, self, db_fault) self.obj_reset_changes() # Cells should only try sending a message over to patron-cells # if cells is enabled and we're not the API cell. Otherwise, # if the API cell is calling this, we could end up with # infinite recursion. if cells_opts.get_cell_type() == 'compute': try: cells_rpcapi.CellsAPI().instance_fault_create_at_top( self._context, db_fault) except Exception: LOG.exception(_LE("Failed to notify cells of instance fault"))