def get(pk: int): database = EventModel.get(pk=pk) aws = Events().describe_event( EventRepository.NARUKO_EVENT_NAME.format(event_id=database.id)) return EventRepository.EVENT_CLASSES[type(database)](database, aws)
def fetch_schedules_by_resource(resource: Resource, aws: AwsEnvironmentModel): # DBから該当するリソースのスケジュールを取得 database_data_list = ScheduleModel.objects.filter( resource_id=resource.resource_id, service=resource.get_service_name().lower(), region=resource.region, aws_environment=aws).filter(deleted=0) # AWSからCloudWatchEventを取得 cloudwatchevents = Events().list_rules() response = [] for database in database_data_list: name = EventRepository.NARUKO_EVENT_NAME.format( event_id=database.id) target_cloudwatchevent = [ c for c in cloudwatchevents if c.name == name ] if target_cloudwatchevent: response.append(Schedule(database, target_cloudwatchevent[0])) else: # DBだけにあるデータは削除する database.delete() return response
def delete(pk: int): # AWSからCloudWatchEventを削除 database = EventModel.get(pk=pk) Events().delete_event( EventRepository.NARUKO_EVENT_NAME.format(event_id=database.id)) # DBから該当するイベントを削除 database.delete()
def save(event: Event): # DBへの保存 event.event_model.save() # CloudWatchEventの保存 event.cloudwatchevent.name = EventRepository.NARUKO_EVENT_NAME.format( event_id=event.event_model.id) return Events().save_event(event)