Commit 954814da authored by Administrator's avatar Administrator

[future] 添加Cron相关的基础API框架

parent 79971d67
# ~*~ coding: utf-8 ~*~
from __future__ import unicode_literals
from ..models import HostAlia, UserAlia, CmdAlia, RunasAlia, Extra_conf, Privilege, Sudo
from ..models import HostAlia, UserAlia, CmdAlia, RunasAlia, Extra_conf, Privilege, Sudo, CronTable
from rest_framework import serializers
......@@ -47,3 +47,7 @@ class SudoSerializer(serializers.ModelSerializer):
model = Sudo
class CronTableSerializer(serializers.ModelSerializer):
class Meta:
model = CronTable
......@@ -83,4 +83,15 @@ class SudoViewSet(mixins.CreateModelMixin,
permission_classes = (AdminUserRequired,)
class CronTableViewSet(mixins.CreateModelMixin,
mixins.ListModelMixin,
mixins.RetrieveModelMixin,
mixins.UpdateModelMixin,
mixins.DestroyModelMixin,
viewsets.GenericViewSet):
queryset = CronTable.objects.all()
serializer_class = CronTableSerializer
permission_classes = (AdminUserRequired,)
......@@ -393,6 +393,31 @@ root ALL=(ALL:ALL) ALL
"""
class CronTable(models.Model):
name = models.CharField(max_length=128, blank=True, null=True, unique=True, verbose_name=_('Runas_Alias'),
help_text=_("Description of a crontab entry"))
month = models.CharField(max_length=128, blank=True, null=True, verbose_name=_('Month'),
help_text=_("Month of the year the job should run ( 1-12, *, */2, etc )"))
weekday = models.CharField(max_length=128, blank=True, null=True, verbose_name=_('WeekDay'),
help_text=_("Day of the week that the job should run"
" ( 0-6 for Sunday-Saturday, *, etc )"))
day = models.CharField(max_length=128, blank=True, null=True, verbose_name=_('Day'),
help_text=_("Day of the month the job should run ( 1-31, *, */2, etc )"))
hour = models.CharField(max_length=128, blank=True, null=True, verbose_name=_('Hour'),
help_text=_("Hour when the job should run ( 0-23, *, */2, etc )"))
minute = models.CharField(max_length=128, blank=True, null=True, verbose_name=_('Minute'),
help_text=_("Minute when the job should run ( 0-59, *, */2, etc )"))
job = models.CharField(max_length=4096, blank=True, null=True, verbose_name=_('Job'),
help_text=_("The command to execute or, if env is set, the value of "
"environment variable. Required if state=present."))
user = models.CharField(max_length=128, blank=True, null=True, verbose_name=_('User'),
help_text=_("The specific user whose crontab should be modified."))
asset = models.ForeignKey(Asset, null=True, blank=True, related_name='crontables')
@property
def describe(self):
return "http://docs.ansible.com/ansible/cron_module.html"
......
......@@ -19,6 +19,7 @@ router.register(r'runas_alia', api_view.RunasAliaViewSet)
router.register(r'extra_conf', api_view.ExtraconfViewSet)
router.register(r'privilege', api_view.PrivilegeViewSet)
router.register(r'sudo', api_view.SudoViewSet)
router.register(r'cron', api_view.CronTableViewSet)
urlpatterns = [
# Resource Sudo url
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment