Script rhn_actions_control_py
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 import sys
18 import ModeControllerCreator
19 from optparse import Option, OptionParser
20
21
23 optionsTable = [
24 Option('--enable-deploy', action='store_true', help='Allow rhncfg-client to deploy files.', default=0),
25 Option('--enable-diff', action='store_true', help='Allow rhncfg-client to diff files.', default=0),
26 Option('--enable-upload', action='store_true', help='Allow rhncfg-client to upload files.', default=0),
27 Option('--enable-mtime-upload', action='store_true', help='Allow rhncfg-client to upload mtime.', default=0),
28 Option('--enable-run', action='store_true', help='Allow rhncfg-client the ability to execute remote scripts.', default=0),
29 Option('--enable-all', action='store_true', help='Allow rhncfg-client to do everything.', default=0),
30 Option('--disable-deploy', action='store_true', help='Disable deployment.', default=0),
31 Option('--disable-diff', action='store_true', help='Disable diff.', default=0),
32 Option('--disable-upload', action='store_true', help='Disable upload.', default=0),
33 Option('--disable-mtime-upload',action='store_true', help='Disable mtime upload.', default=0),
34 Option('--disable-run', action='store_true', help='Disable remote script execution.', default=0),
35 Option('--disable-all', action='store_true', help='Disable all options.', default=0),
36 Option('-f', '--force', action='store_true', help='Force the operation without confirmation', default=0),
37 Option('--report', action='store_true', help='Report the status of the mode settings (enabled or disabled)', default=0),
38 ]
39
40 parser = OptionParser(option_list=optionsTable)
41 (options, args) = parser.parse_args()
42
43 creator = ModeControllerCreator.get_controller_creator()
44 controller = creator.create_controller()
45 controller.set_force(options.force)
46
47 runcreator = ModeControllerCreator.get_run_controller_creator()
48 runcontroller = runcreator.create_controller()
49 runcontroller.set_force(options.force)
50
51 if options.enable_deploy:
52 controller.on('deploy')
53
54 if options.enable_diff:
55 controller.on('diff')
56
57 if options.enable_upload:
58 controller.on('upload')
59
60 if options.enable_mtime_upload:
61 controller.on('mtime_upload')
62
63 if options.enable_all:
64 controller.all_on()
65 runcontroller.all_on()
66
67 if options.enable_run:
68 runcontroller.on('run')
69 runcontroller.off('all')
70
71 if options.disable_deploy:
72 controller.off('deploy')
73
74 if options.disable_diff:
75 controller.off('diff')
76
77 if options.disable_upload:
78 controller.off('upload')
79
80 if options.disable_mtime_upload:
81 controller.off('mtime_upload')
82
83 if options.disable_all:
84 controller.all_off()
85 runcontroller.all_off()
86
87 if options.disable_run:
88 runcontroller.off('run')
89 runcontroller.off('all')
90
91 if options.report:
92 mode_list = ['deploy', 'diff', 'upload', 'mtime_upload']
93
94 for m in mode_list:
95 rstring = "%s is %s"
96 status = "disabled"
97 if controller.is_on(m):
98 status = "enabled"
99 print(rstring % (m, status))
100
101 status = "disabled"
102 if runcontroller.is_on('all'):
103 runcontroller.off('all')
104 runcontroller.on('run')
105
106 if runcontroller.is_on('run'):
107 status = "enabled"
108 print(rstring % ('run', status))
109
110
111 if __name__ == "__main__":
112 try:
113 sys.exit(main() or 0)
114 except KeyboardInterrupt:
115 sys.stderr.write("user interrupted\n")
116 sys.exit(0)
117