1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 import sys
17 try:
18
19 import commands
20 except ImportError:
21 import subprocess as commands
22
23 from spacewalk.common.usix import StringType
24 from distutils.sysconfig import get_python_lib
25
26 COMMAND = "python%s %s/virtualization/poller.py" % (sys.version[0], get_python_lib())
27
34 user = "root"
35
36 if minute == None:
37 minute = "*"
38 if hour == None:
39 hour = "*"
40 if dom == None:
41 dom = "*"
42 if month == None:
43 month = "*"
44 if dow == None:
45 dow = "*"
46
47 if type(minute) != StringType:
48 minute = str(minute).strip()
49 if type(hour) != StringType:
50 hour = str(hour).strip()
51 if type(dom) != StringType:
52 dom = str(dom).strip()
53 if type(month) != StringType:
54 month = str(month).strip()
55 if type(dow) != StringType:
56 dow = str(dow).strip()
57
58 str_template = "%s %s %s %s %s %s %s\n"
59
60 output_string = str_template % (minute, hour, dom, month, dow, user, command)
61 return output_string
62
63
64 -def schedule_poller(minute=None, hour=None, dom=None, month=None, dow=None):
65 try:
66
67 filename = "/etc/cron.d/rhn-virtualization.cron"
68 cronfile = open(filename, "w")
69
70
71 cron_line = create_crontab_line(minute, hour, dom, month, dow)
72
73
74 cronfile.write(cron_line)
75
76
77 cronfile.close()
78
79 except Exception:
80 e = sys.exc_info()[1]
81 return (1, str(e))
82
83
84 status, output = commands.getstatusoutput("/sbin/service crond restart")
85
86 if status != 0:
87 return (1, "Attempt to schedule poller failed: %s, %s" % (str(status), str(output)))
88 else:
89 return (0, "Scheduling of poller succeeded!")
90
91
92
93 if __name__ == "__main__":
94 schedule_poller(minute="0-59/2")
95