From 954814da6518c9a8cb364a212b88d7da3c8af92e Mon Sep 17 00:00:00 2001 From: Administrator Date: Tue, 22 Nov 2016 10:41:18 +0800 Subject: [PATCH] =?UTF-8?q?[future]=20=E6=B7=BB=E5=8A=A0Cron=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E7=9A=84=E5=9F=BA=E7=A1=80API=E6=A1=86=E6=9E=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/ops/api/serializers.py | 6 +++++- apps/ops/api/views.py | 11 +++++++++++ apps/ops/models.py | 25 +++++++++++++++++++++++++ apps/ops/urls.py | 1 + 4 files changed, 42 insertions(+), 1 deletion(-) diff --git a/apps/ops/api/serializers.py b/apps/ops/api/serializers.py index 7e6ede6cb..1cafdf574 100644 --- a/apps/ops/api/serializers.py +++ b/apps/ops/api/serializers.py @@ -1,7 +1,7 @@ # ~*~ 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 diff --git a/apps/ops/api/views.py b/apps/ops/api/views.py index b8a0436b0..1b0de74ee 100644 --- a/apps/ops/api/views.py +++ b/apps/ops/api/views.py @@ -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,) + + diff --git a/apps/ops/models.py b/apps/ops/models.py index ba5c4cc1e..23541a38f 100644 --- a/apps/ops/models.py +++ b/apps/ops/models.py @@ -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" + diff --git a/apps/ops/urls.py b/apps/ops/urls.py index c4a42c9b5..205abf6d0 100644 --- a/apps/ops/urls.py +++ b/apps/ops/urls.py @@ -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