def add(self, **kwargs):
"""Add an entry to the database
This is only to be called by `Schedule.add` classmethod to create
a schedule. Fields `owner` and `name` are already populated in
`self.schedule`. The `self.schedule` is not yet saved.
"""
# check if required variables exist.
if not (kwargs.get('script_id', '') or kwargs.get('action', '')):
raise BadRequestError("You must provide script_id "
"or machine's action")
if not kwargs.get('conditions'):
raise BadRequestError("You must provide a list of conditions, "
"at least machine ids or tags")
if kwargs.get('schedule_type') not in ['crontab',
'interval', 'one_off']:
raise BadRequestError('schedule type must be one of these '
'(crontab, interval, one_off)]')
if kwargs.get('schedule_type') == 'one_off' and not kwargs.get(
'schedule_entry', ''):
raise BadRequestError('one_off schedule '
'requires date given in schedule_entry')
try:
self.update(**kwargs)
except (me.ValidationError, me.NotUniqueError) as exc:
# Propagate original error.
log.error("Error adding %s: %s", self.schedule.name,
exc.to_dict())
raise
log.info("Added schedule with name '%s'", self.schedule.name)
self.schedule.owner.mapper.update(self.schedule)
评论列表
文章目录