(self, request, tenant_id, np_id)
return b''
Remove a notification plan
Remove a notification plan
Remove a notification plan
def delete_notification_plan(self, request, tenant_id, np_id):
        """
        Remove a notification plan
        """
        notification_plans = self._entity_cache_for_tenant(
            tenant_id).notification_plans
        entities = self._entity_cache_for_tenant(tenant_id).entities
        alarmids_using_np = [alarm.id
                             for entity in entities.values()
                             for alarm in entity.alarms.values()
                             if alarm.notification_plan_id == np_id]

        if len(alarmids_using_np):
            status = 403
            request.setResponseCode(status)
            err_message = ('Notification plans cannot be removed while alarms ' +
                           'are using it: {0}'.format(' '.join(alarmids_using_np)))
            self._audit('notification_plans', request, tenant_id, status)
            return json.dumps({'type': 'forbiddenError',
                               'code': status,
                               'txnId': '.fake.mimic.transaction.id.c-1111111.ts-123444444.v-12344frf',
                               'message': err_message,
                               'details': err_message})

        try:
            _delete_notification_plan(notification_plans, np_id)
        except ObjectDoesNotExist as e:
            request.setResponseCode(e.code)
            self._audit('notification_plans', request, tenant_id, e.code)
            return json.dumps(e.to_json())

        status = 204
        request.setResponseCode(status)
        self._audit('notification_plans', request, tenant_id, status)
        request.setHeader(b'content-type', b'text/plain')
        return b''
def delete_notification_plan ( self , request , tenant_id , np_id ) : notification_plans = self . _entity_cache_for_tenant ( tenant_id ) . notification_plans entities = self . _entity_cache_for_tenant ( tenant_id ) . entities alarmids_using_np = [ alarm . id for entity in entities . values ( ) for alarm in entity . alarms . values ( ) if alarm . notification_plan_id == np_id ] if len ( alarmids_using_np ) : status = 403 request . setResponseCode ( status ) err_message = ( 'Notification plans cannot be removed while alarms ' + 'are using it: {0}' . format ( ' ' . join ( alarmids_using_np ) ) ) self . _audit ( 'notification_plans' , request , tenant_id , status ) return json . dumps ( { 'type' : 'forbiddenError' , 'code' : status , 'txnId' : '.fake.mimic.transaction.id.c-1111111.ts-123444444.v-12344frf' , 'message' : err_message , 'details' : err_message } ) try : _delete_notification_plan ( notification_plans , np_id ) except ObjectDoesNotExist as e : request . setResponseCode ( e . code ) self . _audit ( 'notification_plans' , request , tenant_id , e . code ) return json . dumps ( e . to_json ( ) ) status = 204 request . setResponseCode ( status ) self . _audit ( 'notification_plans' , request , tenant_id , status ) request . setHeader ( b'content-type' , b'text/plain' ) return b''