root/tags/bcfg2_0_8_4/bcfg2/src/lib/Server/Plugins/Crontab.py

Revision 2126, 1.6 KB (checked in by bradshaw, 3 years ago)

added my hot crontab hacker which randomizes the times at which cron.daily runs.

Line 
1'''This module manages the crontab file for bcfg2'''
2__revision__ = '$Revision: 1887 $'
3
4import binascii, os, socket, Bcfg2.Server.Plugin, random
5
6class Crontab(Bcfg2.Server.Plugin.Plugin):
7    '''This Generates a random set of times for the cron.daily entries to run.
8     The goal is to ensure that our Configuration Server/network does get crushed
9     all in a 5-10 minute period.
10'''
11    __name__ = 'Crontab'
12    __version__ = '$Id: Crontab 1887 2006-06-18 02:35:54Z desai $'
13    __author__ = 'bcfg-dev@mcs.anl.gov'
14
15    def __init__(self, core, datastore):
16        Bcfg2.Server.Plugin.Plugin.__init__(self, core, datastore)
17        try:
18            self.repository = Bcfg2.Server.Plugin.DirectoryBacked(self.data, self.core.fam)
19        except OSError, ioerr:
20            self.logger.error("Failed to load Crontab repository from %s" % (self.data))
21            self.logger.error(ioerr)
22            raise Bcfg2.Server.Plugin.PluginInitError
23        try:
24            prefix = open("%s/prefix" % (self.data)).read().strip()
25        except IOError:
26            prefix = ''
27        self.Entries = {'ConfigFile':
28                             {prefix + '/etc/crontab':self.build_crontab}}
29
30
31    def build_crontab(self, entry, metadata):
32        '''This function builds builds a crontab file with a random time for cron.daily'''
33        random.seed(metadata.hostname)
34        hour = random.randrange(0,6)
35        minute = random.randrange(0,59)
36        entry.text = self.repository.entries['crontab.template'].data% (minute, hour)
37        permdata = {'owner':'root', 'group':'root', 'perms':'0644'}
38        [entry.attrib.__setitem__(key, permdata[key]) for key in permdata]
Note: See TracBrowser for help on using the browser.