Пример #1
0
    def create(self, request, body=None):
        invalid_params = []
        if not body:
            invalid_params.append('request body is empty')
        elif not 'schedule' in body:
            invalid_params.append('request body needs "schedule" entity')
        else:
            if not body['schedule'].get('tenant'):
                invalid_params.append('request body needs "tenant" entity')
            if not body['schedule'].get('action'):
                invalid_params.append('request body needs "action" entity')
        
        if invalid_params:
            msg = _('The following errors occured with your request: %s') \
                    % ', '.join(invalid_params)
            raise webob.exc.HTTPBadRequest(explanation=msg)

        api_utils.deserialize_schedule_metadata(body['schedule'])
        values = {}
        values.update(body['schedule'])
        values['next_run'] = api_utils.schedule_to_next_run(body['schedule'])
        schedule = self.db_api.schedule_create(values)

        utils.serialize_datetimes(schedule)
        api_utils.serialize_schedule_metadata(schedule)
        return {'schedule': schedule}
Пример #2
0
    def create(self, request, body=None):
        invalid_params = []
        if not body:
            invalid_params.append('request body is empty')
        elif 'schedule' not in body:
            invalid_params.append('request body needs "schedule" entity')
        else:
            if not body['schedule'].get('tenant'):
                invalid_params.append('request body needs "tenant" entity')
            if not body['schedule'].get('action'):
                invalid_params.append('request body needs "action" entity')

        if invalid_params:
            msg = _('The following errors occured with your request: %s') \
                % ', '.join(invalid_params)
            raise webob.exc.HTTPBadRequest(explanation=msg)

        api_utils.deserialize_schedule_metadata(body['schedule'])
        values = {}
        values.update(body['schedule'])
        values['next_run'] = api_utils.schedule_to_next_run(body['schedule'])
        schedule = self.db_api.schedule_create(values)

        utils.serialize_datetimes(schedule)
        api_utils.serialize_schedule_metadata(schedule)
        return {'schedule': schedule}
Пример #3
0
    def update(self, request, schedule_id, body):
        if not body:
            msg = _('The request body must not be empty')
            raise webob.exc.HTTPBadRequest(explanation=msg)
        elif not 'schedule' in body:
            msg = _('The request body must contain a "schedule" entity')
            raise webob.exc.HTTPBadRequest(explanation=msg)
        # NOTE(jculp): only raise if a blank tenant is passed
        # passing no tenant at all is perfectly fine.
        elif ('tenant' in body['schedule'] and not
            body['schedule']['tenant'].strip()):
            msg = _('The request body has not specified a "tenant" entity')
            raise webob.exc.HTTPBadRequest(explanation=msg)

        api_utils.deserialize_schedule_metadata(body['schedule'])
        values = {}
        values.update(body['schedule'])

        try:
            values = api_utils.check_read_only_properties(values)
        except exception.Forbidden as e:
            raise webob.exc.HTTPForbidden(explanation=unicode(e))

        request_next_run = body['schedule'].get('next_run')
        times = {
            'minute': None,
            'hour': None,
            'month': None,
            'day_of_week': None,
            'day_of_month': None,
        }
        update_schedule_times = False
        for key in times:
            if key in values:
                times[key] = values[key]
                update_schedule_times = True

        if update_schedule_times:
            # NOTE(ameade): We must recalculate the schedules next_run time
            # since the schedule has changed
            values.update(times)
            values['next_run'] = api_utils.schedule_to_next_run(times)
        elif request_next_run:
            try:
                timeutils.parse_isotime(request_next_run)
            except ValueError as e:
                msg = _('Invalid "next_run" value. Must be ISO 8601 format')
                raise webob.exc.HTTPBadRequest(explanation=msg)

        try:
            schedule = self.db_api.schedule_update(schedule_id, values)
        except exception.NotFound:
            msg = _('Schedule %s could not be found.') % schedule_id
            raise webob.exc.HTTPNotFound(explanation=msg)

        utils.serialize_datetimes(schedule)
        api_utils.serialize_schedule_metadata(schedule)
        return {'schedule': schedule}
Пример #4
0
    def update(self, request, schedule_id, body):
        if not body:
            msg = _('The request body must not be empty')
            raise webob.exc.HTTPBadRequest(explanation=msg)
        elif 'schedule' not in body:
            msg = _('The request body must contain a "schedule" entity')
            raise webob.exc.HTTPBadRequest(explanation=msg)
        # NOTE(jculp): only raise if a blank tenant is passed
        # passing no tenant at all is perfectly fine.
        elif('tenant' in body['schedule'] and not
             body['schedule']['tenant'].strip()):
            msg = _('The request body has not specified a "tenant" entity')
            raise webob.exc.HTTPBadRequest(explanation=msg)

        api_utils.deserialize_schedule_metadata(body['schedule'])
        values = {}
        values.update(body['schedule'])

        try:
            values = api_utils.check_read_only_properties(values)
        except exception.Forbidden as e:
            raise webob.exc.HTTPForbidden(explanation=unicode(e))

        request_next_run = body['schedule'].get('next_run')
        times = {
            'minute': None,
            'hour': None,
            'month': None,
            'day_of_week': None,
            'day_of_month': None,
        }
        update_schedule_times = False
        for key in times:
            if key in values:
                times[key] = values[key]
                update_schedule_times = True

        if update_schedule_times:
            # NOTE(ameade): We must recalculate the schedules next_run time
            # since the schedule has changed
            values.update(times)
            values['next_run'] = api_utils.schedule_to_next_run(times)
        elif request_next_run:
            try:
                timeutils.parse_isotime(request_next_run)
            except ValueError as e:
                msg = _('Invalid "next_run" value. Must be ISO 8601 format')
                raise webob.exc.HTTPBadRequest(explanation=msg)

        try:
            schedule = self.db_api.schedule_update(schedule_id, values)
        except exception.NotFound:
            msg = _('Schedule %s could not be found.') % schedule_id
            raise webob.exc.HTTPNotFound(explanation=msg)

        utils.serialize_datetimes(schedule)
        api_utils.serialize_schedule_metadata(schedule)
        return {'schedule': schedule}
Пример #5
0
 def get(self, request, schedule_id):
     try:
         schedule = self.db_api.schedule_get_by_id(schedule_id)
         utils.serialize_datetimes(schedule)
         api_utils.serialize_schedule_metadata(schedule)
     except exception.NotFound:
         msg = _('Schedule %s could not be found.') % schedule_id
         raise webob.exc.HTTPNotFound(explanation=msg)
     return {'schedule': schedule}
Пример #6
0
 def get(self, request, schedule_id):
     try:
         schedule = self.db_api.schedule_get_by_id(schedule_id)
         utils.serialize_datetimes(schedule)
         api_utils.serialize_schedule_metadata(schedule)
     except exception.NotFound:
         msg = _('Schedule %s could not be found.') % schedule_id
         raise webob.exc.HTTPNotFound(explanation=msg)
     return {'schedule': schedule}
Пример #7
0
    def create(self, request, body=None):
        if (body is None or type(body).__name__ != 'dict' or
            body.get('schedule') is None):
            raise webob.exc.HTTPBadRequest()

        api_utils.deserialize_schedule_metadata(body['schedule'])
        values = {}
        values.update(body['schedule'])
        values['next_run'] = api_utils.schedule_to_next_run(body['schedule'])
        schedule = self.db_api.schedule_create(values)

        utils.serialize_datetimes(schedule)
        api_utils.serialize_schedule_metadata(schedule)
        return {'schedule': schedule}
Пример #8
0
    def update(self, request, schedule_id, body):
        if body is None or body.get('schedule') is None:
            raise webob.exc.HTTPBadRequest()

        try:
            api_utils.deserialize_schedule_metadata(body['schedule'])
            values = {}
            values.update(body['schedule'])
            schedule = self.db_api.schedule_update(schedule_id,
                                                   values)
            utils.serialize_datetimes(schedule)
            api_utils.serialize_schedule_metadata(schedule)
        except exception.NotFound:
            msg = _('Schedule %s could not be found.') % schedule_id
            raise webob.exc.HTTPNotFound(explanation=msg)
        return {'schedule': schedule}
Пример #9
0
    def create(self, request, body=None):
        if not body:
            msg = _('The request body must not be empty')
            raise webob.exc.HTTPBadRequest(explanation=msg)
        if not 'schedule' in body:
            msg = _('The request body must contain a "schedule" entity')
            raise webob.exc.HTTPBadRequest(explanation=msg)

        api_utils.deserialize_schedule_metadata(body['schedule'])
        values = {}
        values.update(body['schedule'])
        values['next_run'] = api_utils.schedule_to_next_run(body['schedule'])
        schedule = self.db_api.schedule_create(values)

        utils.serialize_datetimes(schedule)
        api_utils.serialize_schedule_metadata(schedule)
        return {'schedule': schedule}
Пример #10
0
    def update(self, request, schedule_id, body):
        if not body:
            msg = _('The request body must not be empty')
            raise webob.exc.HTTPBadRequest(explanation=msg)
        if not 'schedule' in body:
            msg = _('The request body must contain a "schedule" entity')
            raise webob.exc.HTTPBadRequest(explanation=msg)

        api_utils.deserialize_schedule_metadata(body['schedule'])
        values = {}
        values.update(body['schedule'])

        try:
            values = api_utils.check_read_only_properties(values)
        except exception.Forbidden as e:
            raise webob.exc.HTTPForbidden(explanation=unicode(e))

        times = {
            'minute': None,
            'hour': None,
            'month': None,
            'day_of_week': None,
            'day_of_month': None,
        }
        update_schedule_times = False
        for key in times:
            if key in values:
                times[key] = values[key]
                update_schedule_times = True

        if update_schedule_times:
            # NOTE(ameade): We must recalculate the schedules next_run time
            # since the schedule has changed
            values.update(times)
            values['next_run'] = api_utils.schedule_to_next_run(times)

        try:
            schedule = self.db_api.schedule_update(schedule_id, values)
        except exception.NotFound:
            msg = _('Schedule %s could not be found.') % schedule_id
            raise webob.exc.HTTPNotFound(explanation=msg)

        utils.serialize_datetimes(schedule)
        api_utils.serialize_schedule_metadata(schedule)
        return {'schedule': schedule}
Пример #11
0
 def list(self, request):
     filter_args = self._get_request_params(request)
     try:
         filter_args = utils.get_pagination_limit(filter_args)
     except exception.Invalid as e:
         raise webob.exc.HTTPBadRequest(explanation=str(e))
     try:
         schedules = self.db_api.schedule_get_all(filter_args=filter_args)
         if len(schedules) != 0 and len(schedules) == filter_args['limit']:
             next_page = '/v1/schedules?marker=%s' % schedules[-1].get('id')
         else:
             next_page = None
     except exception.NotFound:
         msg = _('The specified marker could not be found')
         raise webob.exc.HTTPNotFound(explanation=msg)
     for sched in schedules:
         utils.serialize_datetimes(sched),
         api_utils.serialize_schedule_metadata(sched)
     links = [{'rel': 'next', 'href': next_page}]
     return {'schedules': schedules, 'schedules_links': links}
Пример #12
0
 def list(self, request):
     filter_args = self._get_request_params(request)
     try:
         filter_args = utils.get_pagination_limit(filter_args)
         limit = filter_args['limit']
     except exception.Invalid as e:
         raise webob.exc.HTTPBadRequest(explanation=str(e))
     try:
         schedules = self.db_api.schedule_get_all(filter_args=filter_args)
         if len(schedules) != 0 and len(schedules) == limit:
             next_page = '/v1/schedules?marker=%s' % schedules[-1].get('id')
         else:
             next_page = None
     except exception.NotFound:
         msg = _('The specified marker could not be found')
         raise webob.exc.HTTPNotFound(explanation=msg)
     for sched in schedules:
         utils.serialize_datetimes(sched),
         api_utils.serialize_schedule_metadata(sched)
     links = [{'rel': 'next', 'href': next_page}]
     return {'schedules': schedules, 'schedules_links': links}