def update(self, request, tenant_pk=None, aws_env_pk=None, region_pk=None, service_pk=None, resource_pk=None, pk=None): log = NarukoLogging(request) logger = log.get_logger(__name__) logger.info("START: update") try: with transaction.atomic(): tenant = TenantModel.objects.get(id=tenant_pk) aws_env = AwsEnvironmentModel.objects.get(id=aws_env_pk, tenant=tenant) schedule = ScheduleFactory.create( resource_id=resource_pk, service=service_pk, region=region_pk, aws_id=aws_env_pk, event_id=pk, **request.data) create_schedule = ControlScheduleUseCase(log).save_schedule(request.user, tenant, aws_env, schedule) except (TypeError, ValueError, KeyError, ClientError, NarukoException) as e: # リクエストデータが不正 logger.exception(e) return Response(status=status.HTTP_400_BAD_REQUEST) except ObjectDoesNotExist as e: # AWS環境が存在しない logger.exception(e) return Response(status=status.HTTP_404_NOT_FOUND) except Exception as e: logger.exception(e) raise else: logger.info("END: update") return Response(data=create_schedule.serialize(), status=status.HTTP_201_CREATED)
def create(self, request, tenant_pk=None, aws_env_pk=None, region_pk=None, service_pk=None, resource_pk=None): log = NarukoLogging(request) logger = log.get_logger(__name__) logger.info("START: create") tenant = TenantModel.objects.get(id=tenant_pk) aws_env = AwsEnvironmentModel.objects.get(id=aws_env_pk, tenant=tenant) schedule = ScheduleFactory.create(resource_id=resource_pk, service=service_pk, region=region_pk, aws_id=aws_env_pk, **request.data) create_schedule = ControlScheduleUseCase(log).save_schedule( request.user, tenant, aws_env, schedule) logger.info("END: create") return Response(data=create_schedule.serialize(), status=status.HTTP_201_CREATED)