From 52c2366c232444c90675d22e550093aceac87c6a Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Mon, 6 Nov 2017 22:29:56 -0700 Subject: [PATCH] addding not_during_range to schedule --- salt/modules/schedule.py | 3 ++- salt/utils/schedule.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/salt/modules/schedule.py b/salt/modules/schedule.py index 487713c5ca..29e9139868 100644 --- a/salt/modules/schedule.py +++ b/salt/modules/schedule.py @@ -58,6 +58,7 @@ SCHEDULE_CONF = [ 'return_config', 'return_kwargs', 'run_on_start' + 'not_during_range', ] @@ -353,7 +354,7 @@ def build_schedule_item(name, **kwargs): for item in ['range', 'when', 'once', 'once_fmt', 'cron', 'returner', 'after', 'return_config', 'return_kwargs', - 'until', 'run_on_start']: + 'until', 'run_on_start', 'not_during_range']: if item in kwargs: schedule[name][item] = kwargs[item] diff --git a/salt/utils/schedule.py b/salt/utils/schedule.py index 8e9ecec0a2..d7e65d7b7d 100644 --- a/salt/utils/schedule.py +++ b/salt/utils/schedule.py @@ -1322,6 +1322,37 @@ class Schedule(object): Ignoring job {0}.'.format(job)) continue + if 'not_during_range' in data: + if not _RANGE_SUPPORTED: + log.error('Missing python-dateutil. Ignoring job {0}'.format(job)) + continue + else: + if isinstance(data['not_during_range'], dict): + try: + start = int(time.mktime(dateutil_parser.parse(data['not_during_range']['start']).timetuple())) + except ValueError: + log.error('Invalid date string for start in not_during_range. Ignoring job {0}.'.format(job)) + continue + try: + end = int(time.mktime(dateutil_parser.parse(data['not_during_range']['end']).timetuple())) + except ValueError: + log.error('Invalid date string for end in not_during_range. Ignoring job {0}.'.format(job)) + log.error(data) + continue + if end > start: + if start <= now <= end: + run = False + else: + run = True + else: + log.error('schedule.handle_func: Invalid range, end must be larger than start. \ + Ignoring job {0}.'.format(job)) + continue + else: + log.error('schedule.handle_func: Invalid, range must be specified as a dictionary. \ + Ignoring job {0}.'.format(job)) + continue + if not run: continue