def build_schedule_item(name, **kwargs):
    '''
    Build a schedule job

    CLI Example:

    .. code-block:: bash

        salt '*' schedule.build_schedule_item job1 function='test.ping' seconds=3600
    '''

    ret = {'comment': [],
           'result': True}

    if not name:
        ret['comment'] = 'Job name is required.'
        ret['result'] = False
        return ret

    schedule = {}
    schedule[name] = salt.utils.odict.OrderedDict()
    schedule[name]['function'] = kwargs['function']

    time_conflict = False
    for item in ['seconds', 'minutes', 'hours', 'days']:
        if item in kwargs and 'when' in kwargs:
            time_conflict = True

        if item in kwargs and 'cron' in kwargs:
            time_conflict = True

    if time_conflict:
        ret['result'] = False
        ret['comment'] = 'Unable to use "seconds", "minutes", "hours", or "days" with "when" or "cron" options.'
        return ret

    if 'when' in kwargs and 'cron' in kwargs:
        ret['result'] = False
        ret['comment'] = 'Unable to use "when" and "cron" options together.  Ignoring.'
        return ret

    for item in ['seconds', 'minutes', 'hours', 'days']:
        if item in kwargs:
            schedule[name][item] = kwargs[item]

    if 'return_job' in kwargs:
        schedule[name]['return_job'] = kwargs['return_job']

    if 'metadata' in kwargs:
        schedule[name]['metadata'] = kwargs['metadata']

    if 'job_args' in kwargs:
        schedule[name]['args'] = kwargs['job_args']

    if 'job_kwargs' in kwargs:
        schedule[name]['kwargs'] = kwargs['job_kwargs']

    if 'maxrunning' in kwargs:
        schedule[name]['maxrunning'] = kwargs['maxrunning']
    else:
        schedule[name]['maxrunning'] = 1

    if 'name' in kwargs:
        schedule[name]['name'] = kwargs['name']
    else:
        schedule[name]['name'] = name

    if 'enabled' in kwargs:
        schedule[name]['enabled'] = kwargs['enabled']
    else:
        schedule[name]['enabled'] = True

    if 'jid_include' not in kwargs or kwargs['jid_include']:
        schedule[name]['jid_include'] = True

    if 'splay' in kwargs:
        if isinstance(kwargs['splay'], dict):
            # Ensure ordering of start and end arguments
            schedule[name]['splay'] = salt.utils.odict.OrderedDict()
            schedule[name]['splay']['start'] = kwargs['splay']['start']
            schedule[name]['splay']['end'] = kwargs['splay']['end']
        else:
            schedule[name]['splay'] = kwargs['splay']

    if 'when' in kwargs:
        if not _WHEN_SUPPORTED:
            ret['result'] = False
            ret['comment'] = 'Missing dateutil.parser, "when" is unavailable.'
            return ret
        else:
            validate_when = kwargs['when']
            if not isinstance(validate_when, list):
                validate_when = [validate_when]
            for _when in validate_when:
                try:
                    dateutil_parser.parse(_when)
                except ValueError:
                    ret['result'] = False
                    ret['comment'] = 'Schedule item {0} for "when" in invalid.'.format(_when)
                    return ret

    for item in ['range', 'when', 'once', 'once_fmt', 'cron',
                 'returner', 'after', 'return_config', 'return_kwargs',
                 'until', 'run_on_start', 'skip_during_range']:
        if item in kwargs:
            schedule[name][item] = kwargs[item]

    return schedule[name]
def build_schedule_item ( name , ** kwargs ) : ret = { 'comment' : [ ] , 'result' : True } if not name : ret [ 'comment' ] = 'Job name is required.' ret [ 'result' ] = False return ret schedule = { } schedule [ name ] = salt . utils . odict . OrderedDict ( ) schedule [ name ] [ 'function' ] = kwargs [ 'function' ] time_conflict = False for item in [ 'seconds' , 'minutes' , 'hours' , 'days' ] : if item in kwargs and 'when' in kwargs : time_conflict = True if item in kwargs and 'cron' in kwargs : time_conflict = True if time_conflict : ret [ 'result' ] = False ret [ 'comment' ] = 'Unable to use "seconds", "minutes", "hours", or "days" with "when" or "cron" options.' return ret if 'when' in kwargs and 'cron' in kwargs : ret [ 'result' ] = False ret [ 'comment' ] = 'Unable to use "when" and "cron" options together.  Ignoring.' return ret for item in [ 'seconds' , 'minutes' , 'hours' , 'days' ] : if item in kwargs : schedule [ name ] [ item ] = kwargs [ item ] if 'return_job' in kwargs : schedule [ name ] [ 'return_job' ] = kwargs [ 'return_job' ] if 'metadata' in kwargs : schedule [ name ] [ 'metadata' ] = kwargs [ 'metadata' ] if 'job_args' in kwargs : schedule [ name ] [ 'args' ] = kwargs [ 'job_args' ] if 'job_kwargs' in kwargs : schedule [ name ] [ 'kwargs' ] = kwargs [ 'job_kwargs' ] if 'maxrunning' in kwargs : schedule [ name ] [ 'maxrunning' ] = kwargs [ 'maxrunning' ] else : schedule [ name ] [ 'maxrunning' ] = 1 if 'name' in kwargs : schedule [ name ] [ 'name' ] = kwargs [ 'name' ] else : schedule [ name ] [ 'name' ] = name if 'enabled' in kwargs : schedule [ name ] [ 'enabled' ] = kwargs [ 'enabled' ] else : schedule [ name ] [ 'enabled' ] = True if 'jid_include' not in kwargs or kwargs [ 'jid_include' ] : schedule [ name ] [ 'jid_include' ] = True if 'splay' in kwargs : if isinstance ( kwargs [ 'splay' ] , dict ) : schedule [ name ] [ 'splay' ] = salt . utils . odict . OrderedDict ( ) schedule [ name ] [ 'splay' ] [ 'start' ] = kwargs [ 'splay' ] [ 'start' ] schedule [ name ] [ 'splay' ] [ 'end' ] = kwargs [ 'splay' ] [ 'end' ] else : schedule [ name ] [ 'splay' ] = kwargs [ 'splay' ] if 'when' in kwargs : if not _WHEN_SUPPORTED : ret [ 'result' ] = False ret [ 'comment' ] = 'Missing dateutil.parser, "when" is unavailable.' return ret else : validate_when = kwargs [ 'when' ] if not isinstance ( validate_when , list ) : validate_when = [ validate_when ] for _when in validate_when : try : dateutil_parser . parse ( _when ) except ValueError : ret [ 'result' ] = False ret [ 'comment' ] = 'Schedule item {0} for "when" in invalid.' . format ( _when ) return ret for item in [ 'range' , 'when' , 'once' , 'once_fmt' , 'cron' , 'returner' , 'after' , 'return_config' , 'return_kwargs' , 'until' , 'run_on_start' , 'skip_during_range' ] : if item in kwargs : schedule [ name ] [ item ] = kwargs [ item ] return schedule [ name ]
Build a schedule job

    CLI Example:

    .. code-block:: bash

        salt '*' schedule.build_schedule_item job1 function='test.ping' seconds=3600