def _get_device_db(self, context, device_id, current_statuses, new_status): try: device_db = (self._model_query( context, Device).filter(Device.id == device_id).filter( Device.status.in_(current_statuses)).with_lockmode( 'update').one()) except orm_exc.NoResultFound: raise vnfm.DeviceNotFound(device_id=device_id) if device_db.status == constants.PENDING_UPDATE: raise vnfm.DeviceInUse(device_id=device_id) device_db.update({'status': new_status}) return device_db
def _get_resource(self, context, model, id): try: return self._get_by_id(context, model, id) except orm_exc.NoResultFound: if issubclass(model, DeviceTemplate): raise vnfm.DeviceTemplateNotFound(device_tempalte_id=id) elif issubclass(model, ServiceType): raise vnfm.ServiceTypeNotFound(service_type_id=id) if issubclass(model, Device): raise vnfm.DeviceNotFound(device_id=id) else: raise