bolt 0.21.7 → 0.21.8

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of bolt might be problematic. Click here for more details.

Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/lib/bolt/transport/ssh/connection.rb +4 -5
  3. data/lib/bolt/transport/ssh.rb +4 -1
  4. data/lib/bolt/transport/winrm/connection.rb +3 -4
  5. data/lib/bolt/transport/winrm.rb +4 -1
  6. data/lib/bolt/version.rb +1 -1
  7. data/libexec/apply_catalog.rb +10 -2
  8. data/vendored/puppet/lib/puppet/application/apply.rb +20 -9
  9. data/vendored/puppet/lib/puppet/application/cert.rb +3 -1
  10. data/vendored/puppet/lib/puppet/application/device.rb +22 -5
  11. data/vendored/puppet/lib/puppet/configurer/fact_handler.rb +5 -1
  12. data/vendored/puppet/lib/puppet/configurer.rb +15 -2
  13. data/vendored/puppet/lib/puppet/defaults.rb +36 -25
  14. data/vendored/puppet/lib/puppet/face/certificate.rb +2 -0
  15. data/vendored/puppet/lib/puppet/feature/base.rb +0 -3
  16. data/vendored/puppet/lib/puppet/functions/call.rb +37 -0
  17. data/vendored/puppet/lib/puppet/functions.rb +5 -0
  18. data/vendored/puppet/lib/puppet/indirector/ldap.rb +6 -0
  19. data/vendored/puppet/lib/puppet/node/environment.rb +4 -2
  20. data/vendored/puppet/lib/puppet/parser/scope.rb +2 -2
  21. data/vendored/puppet/lib/puppet/pops/adapters.rb +14 -0
  22. data/vendored/puppet/lib/puppet/pops/evaluator/deferred_resolver.rb +128 -0
  23. data/vendored/puppet/lib/puppet/pops/evaluator/evaluator_impl.rb +4 -1
  24. data/vendored/puppet/lib/puppet/pops/functions/dispatch.rb +2 -0
  25. data/vendored/puppet/lib/puppet/pops/issues.rb +9 -1
  26. data/vendored/puppet/lib/puppet/pops/loader/static_loader.rb +0 -16
  27. data/vendored/puppet/lib/puppet/pops/loaders.rb +1 -3
  28. data/vendored/puppet/lib/puppet/pops/parser/eparser.rb +6 -6
  29. data/vendored/puppet/lib/puppet/pops/pcore.rb +11 -0
  30. data/vendored/puppet/lib/puppet/pops/types/type_factory.rb +17 -0
  31. data/vendored/puppet/lib/puppet/pops/validation/tasks_checker.rb +13 -5
  32. data/vendored/puppet/lib/puppet/pops.rb +1 -0
  33. data/vendored/puppet/lib/puppet/provider/service/debian.rb +1 -0
  34. data/vendored/puppet/lib/puppet/provider/service/smf.rb +2 -3
  35. data/vendored/puppet/lib/puppet/provider/service/upstart.rb +10 -2
  36. data/vendored/puppet/lib/puppet/ssl/certificate_authority.rb +6 -84
  37. data/vendored/puppet/lib/puppet/ssl/certificate_request.rb +11 -3
  38. data/vendored/puppet/lib/puppet/type/file.rb +3 -0
  39. data/vendored/puppet/lib/puppet/type/user.rb +17 -3
  40. data/vendored/puppet/lib/puppet/util/autoload.rb +36 -31
  41. data/vendored/puppet/lib/puppet/util.rb +2 -0
  42. metadata +3 -43
  43. data/vendored/puppet/lib/puppet/indirector/node/write_only_yaml.rb +0 -39
  44. data/vendored/puppet/lib/puppet/provider/augeas/augeas.rb +0 -573
  45. data/vendored/puppet/lib/puppet/provider/cisco.rb +0 -9
  46. data/vendored/puppet/lib/puppet/provider/computer/computer.rb +0 -20
  47. data/vendored/puppet/lib/puppet/provider/host/parsed.rb +0 -46
  48. data/vendored/puppet/lib/puppet/provider/interface/cisco.rb +0 -27
  49. data/vendored/puppet/lib/puppet/provider/macauthorization/macauthorization.rb +0 -298
  50. data/vendored/puppet/lib/puppet/provider/mcx/mcxcontent.rb +0 -173
  51. data/vendored/puppet/lib/puppet/provider/mount/parsed.rb +0 -282
  52. data/vendored/puppet/lib/puppet/provider/mount.rb +0 -76
  53. data/vendored/puppet/lib/puppet/provider/scheduled_task/win32_taskscheduler.rb +0 -590
  54. data/vendored/puppet/lib/puppet/provider/selboolean/getsetsebool.rb +0 -47
  55. data/vendored/puppet/lib/puppet/provider/selmodule/semodule.rb +0 -140
  56. data/vendored/puppet/lib/puppet/provider/ssh_authorized_key/parsed.rb +0 -105
  57. data/vendored/puppet/lib/puppet/provider/sshkey/parsed.rb +0 -50
  58. data/vendored/puppet/lib/puppet/provider/vlan/cisco.rb +0 -28
  59. data/vendored/puppet/lib/puppet/provider/yumrepo/inifile.rb +0 -315
  60. data/vendored/puppet/lib/puppet/type/augeas.rb +0 -211
  61. data/vendored/puppet/lib/puppet/type/computer.rb +0 -66
  62. data/vendored/puppet/lib/puppet/type/host.rb +0 -95
  63. data/vendored/puppet/lib/puppet/type/interface.rb +0 -121
  64. data/vendored/puppet/lib/puppet/type/k5login.rb +0 -165
  65. data/vendored/puppet/lib/puppet/type/macauthorization.rb +0 -167
  66. data/vendored/puppet/lib/puppet/type/mcx.rb +0 -98
  67. data/vendored/puppet/lib/puppet/type/mount.rb +0 -314
  68. data/vendored/puppet/lib/puppet/type/router.rb +0 -17
  69. data/vendored/puppet/lib/puppet/type/scheduled_task.rb +0 -183
  70. data/vendored/puppet/lib/puppet/type/selboolean.rb +0 -26
  71. data/vendored/puppet/lib/puppet/type/selmodule.rb +0 -59
  72. data/vendored/puppet/lib/puppet/type/ssh_authorized_key.rb +0 -143
  73. data/vendored/puppet/lib/puppet/type/sshkey.rb +0 -83
  74. data/vendored/puppet/lib/puppet/type/vlan.rb +0 -26
  75. data/vendored/puppet/lib/puppet/type/yumrepo.rb +0 -430
  76. data/vendored/puppet/lib/puppet/util/network_device/cisco/device.rb +0 -285
  77. data/vendored/puppet/lib/puppet/util/network_device/cisco/facts.rb +0 -72
  78. data/vendored/puppet/lib/puppet/util/network_device/cisco/interface.rb +0 -94
  79. data/vendored/puppet/lib/puppet/util/network_device/cisco.rb +0 -4
  80. data/vendored/puppet/lib/puppet/util/network_device/ipcalc.rb +0 -68
  81. data/vendored/puppet/lib/puppet/util/network_device/transport/ssh.rb +0 -126
  82. data/vendored/puppet/lib/puppet/util/network_device/transport/telnet.rb +0 -47
  83. data/vendored/puppet/lib/puppet/util/windows/taskscheduler.rb +0 -1267
@@ -1,590 +0,0 @@
1
- require 'puppet/parameter'
2
-
3
- if Puppet.features.microsoft_windows?
4
- require 'puppet/util/windows/taskscheduler'
5
- end
6
-
7
- Puppet::Type.type(:scheduled_task).provide(:win32_taskscheduler) do
8
- desc %q{This provider manages scheduled tasks on Windows.}
9
-
10
- defaultfor :operatingsystem => :windows
11
- confine :operatingsystem => :windows
12
-
13
- MINUTES_IN_DAY = 1440
14
-
15
- def self.instances
16
- Win32::TaskScheduler.new.tasks.collect do |job_file|
17
- job_title = File.basename(job_file, '.job')
18
-
19
- new(
20
- :provider => :win32_taskscheduler,
21
- :name => job_title
22
- )
23
- end
24
- end
25
-
26
- def exists?
27
- Win32::TaskScheduler.new.exists? resource[:name]
28
- end
29
-
30
- def task
31
- return @task if @task
32
-
33
- @task ||= Win32::TaskScheduler.new
34
- @task.activate(resource[:name] + '.job') if exists?
35
-
36
- @task
37
- end
38
-
39
- def clear_task
40
- @task = nil
41
- @triggers = nil
42
- end
43
-
44
- def enabled
45
- task.flags & Win32::TaskScheduler::DISABLED == 0 ? :true : :false
46
- end
47
-
48
- def command
49
- task.application_name
50
- end
51
-
52
- def arguments
53
- task.parameters
54
- end
55
-
56
- def working_dir
57
- task.working_directory
58
- end
59
-
60
- def user
61
- account = task.account_information
62
- return 'system' if account == ''
63
- account
64
- end
65
-
66
- def trigger
67
- return @triggers if @triggers
68
-
69
- @triggers = []
70
- task.trigger_count.times do |i|
71
- trigger = begin
72
- task.trigger(i)
73
- rescue Win32::TaskScheduler::Error
74
- # Win32::TaskScheduler can't handle all of the
75
- # trigger types Windows uses, so we need to skip the
76
- # unhandled types to prevent "puppet resource" from
77
- # blowing up.
78
- nil
79
- end
80
- next unless trigger and scheduler_trigger_types.include?(trigger['trigger_type'])
81
- puppet_trigger = {}
82
- case trigger['trigger_type']
83
- when Win32::TaskScheduler::TASK_TIME_TRIGGER_DAILY
84
- puppet_trigger['schedule'] = 'daily'
85
- puppet_trigger['every'] = trigger['type']['days_interval'].to_s
86
- when Win32::TaskScheduler::TASK_TIME_TRIGGER_WEEKLY
87
- puppet_trigger['schedule'] = 'weekly'
88
- puppet_trigger['every'] = trigger['type']['weeks_interval'].to_s
89
- puppet_trigger['day_of_week'] = days_of_week_from_bitfield(trigger['type']['days_of_week'])
90
- when Win32::TaskScheduler::TASK_TIME_TRIGGER_MONTHLYDATE
91
- puppet_trigger['schedule'] = 'monthly'
92
- puppet_trigger['months'] = months_from_bitfield(trigger['type']['months'])
93
- puppet_trigger['on'] = days_from_bitfield(trigger['type']['days'])
94
- when Win32::TaskScheduler::TASK_TIME_TRIGGER_MONTHLYDOW
95
- puppet_trigger['schedule'] = 'monthly'
96
- puppet_trigger['months'] = months_from_bitfield(trigger['type']['months'])
97
- puppet_trigger['which_occurrence'] = occurrence_constant_to_name(trigger['type']['weeks'])
98
- puppet_trigger['day_of_week'] = days_of_week_from_bitfield(trigger['type']['days_of_week'])
99
- when Win32::TaskScheduler::TASK_TIME_TRIGGER_ONCE
100
- puppet_trigger['schedule'] = 'once'
101
- end
102
- puppet_trigger['start_date'] = self.class.normalized_date("#{trigger['start_year']}-#{trigger['start_month']}-#{trigger['start_day']}")
103
- puppet_trigger['start_time'] = self.class.normalized_time("#{trigger['start_hour']}:#{trigger['start_minute']}")
104
- puppet_trigger['enabled'] = trigger['flags'] & Win32::TaskScheduler::TASK_TRIGGER_FLAG_DISABLED == 0
105
- puppet_trigger['minutes_interval'] = trigger['minutes_interval'] ||= 0
106
- puppet_trigger['minutes_duration'] = trigger['minutes_duration'] ||= 0
107
- puppet_trigger['index'] = i
108
-
109
- @triggers << puppet_trigger
110
- end
111
-
112
- @triggers
113
- end
114
-
115
- def user_insync?(current, should)
116
- return false unless current
117
-
118
- # Win32::TaskScheduler can return the 'SYSTEM' account as the
119
- # empty string.
120
- current = 'system' if current == ''
121
-
122
- # By comparing account SIDs we don't have to worry about case
123
- # sensitivity, or canonicalization of the account name.
124
- Puppet::Util::Windows::SID.name_to_sid(current) == Puppet::Util::Windows::SID.name_to_sid(should[0])
125
- end
126
-
127
- def trigger_insync?(current, should)
128
- should = [should] unless should.is_a?(Array)
129
- current = [current] unless current.is_a?(Array)
130
- return false unless current.length == should.length
131
-
132
- current_in_sync = current.all? do |c|
133
- should.any? {|s| triggers_same?(c, s)}
134
- end
135
-
136
- should_in_sync = should.all? do |s|
137
- current.any? {|c| triggers_same?(c,s)}
138
- end
139
-
140
- current_in_sync && should_in_sync
141
- end
142
-
143
- def command=(value)
144
- task.application_name = value
145
- end
146
-
147
- def arguments=(value)
148
- task.parameters = value
149
- end
150
-
151
- def working_dir=(value)
152
- task.working_directory = value
153
- end
154
-
155
- def enabled=(value)
156
- if value == :true
157
- task.flags = task.flags & ~Win32::TaskScheduler::DISABLED
158
- else
159
- task.flags = task.flags | Win32::TaskScheduler::DISABLED
160
- end
161
- end
162
-
163
- def trigger=(value)
164
- desired_triggers = value.is_a?(Array) ? value : [value]
165
- current_triggers = trigger.is_a?(Array) ? trigger : [trigger]
166
-
167
- extra_triggers = []
168
- desired_to_search = desired_triggers.dup
169
- current_triggers.each do |current|
170
- if found = desired_to_search.find {|desired| triggers_same?(current, desired)}
171
- desired_to_search.delete(found)
172
- else
173
- extra_triggers << current['index']
174
- end
175
- end
176
-
177
- needed_triggers = []
178
- current_to_search = current_triggers.dup
179
- desired_triggers.each do |desired|
180
- if found = current_to_search.find {|current| triggers_same?(current, desired)}
181
- current_to_search.delete(found)
182
- else
183
- needed_triggers << desired
184
- end
185
- end
186
-
187
- extra_triggers.reverse_each do |index|
188
- task.delete_trigger(index)
189
- end
190
-
191
- needed_triggers.each do |trigger_hash|
192
- # Even though this is an assignment, the API for
193
- # Win32::TaskScheduler ends up appending this trigger to the
194
- # list of triggers for the task, while #add_trigger is only able
195
- # to replace existing triggers. *shrug*
196
- task.trigger = translate_hash_to_trigger(trigger_hash)
197
- end
198
- end
199
-
200
- def user=(value)
201
- self.fail("Invalid user: #{value}") unless Puppet::Util::Windows::SID.name_to_sid(value)
202
-
203
- if value.to_s.downcase != 'system'
204
- task.set_account_information(value, resource[:password])
205
- else
206
- # Win32::TaskScheduler treats a nil/empty username & password as
207
- # requesting the SYSTEM account.
208
- task.set_account_information(nil, nil)
209
- end
210
- end
211
-
212
- def create
213
- clear_task
214
- @task = Win32::TaskScheduler.new(resource[:name], dummy_time_trigger)
215
- self.command = resource[:command]
216
-
217
- [:arguments, :working_dir, :enabled, :trigger, :user].each do |prop|
218
- send("#{prop}=", resource[prop]) if resource[prop]
219
- end
220
- end
221
-
222
- def destroy
223
- Win32::TaskScheduler.new.delete(resource[:name] + '.job')
224
- end
225
-
226
- def flush
227
- unless resource[:ensure] == :absent
228
- self.fail('Parameter command is required.') unless resource[:command]
229
- # HACK: even though the user may actually be insync?, for task changes to
230
- # fully propagate, it is necessary to explicitly set the user for the task,
231
- # even when it is SYSTEM (and has a nil password)
232
- # this is a Windows security feature with the v1 COM APIs that prevent
233
- # arbitrary reassignment of a task scheduler command to run as SYSTEM
234
- # without the authorization to do so
235
- self.user = resource[:user]
236
- task.save
237
- @task = nil
238
- end
239
- end
240
-
241
- def triggers_same?(current_trigger, desired_trigger)
242
- return false unless current_trigger['schedule'] == desired_trigger['schedule']
243
- return false if current_trigger.has_key?('enabled') && !current_trigger['enabled']
244
-
245
- desired = desired_trigger.dup
246
- desired['start_date'] ||= current_trigger['start_date'] if current_trigger.has_key?('start_date')
247
- desired['every'] ||= current_trigger['every'] if current_trigger.has_key?('every')
248
- desired['months'] ||= current_trigger['months'] if current_trigger.has_key?('months')
249
- desired['on'] ||= current_trigger['on'] if current_trigger.has_key?('on')
250
- desired['day_of_week'] ||= current_trigger['day_of_week'] if current_trigger.has_key?('day_of_week')
251
-
252
- translate_hash_to_trigger(current_trigger) == translate_hash_to_trigger(desired)
253
- end
254
-
255
- def self.normalized_date(date_string)
256
- date = Date.parse("#{date_string}")
257
- "#{date.year}-#{date.month}-#{date.day}"
258
- end
259
-
260
- def self.normalized_time(time_string)
261
- Time.parse("#{time_string}").strftime('%H:%M')
262
- end
263
-
264
- def dummy_time_trigger
265
- now = Time.now
266
- {
267
- 'flags' => 0,
268
- 'random_minutes_interval' => 0,
269
- 'end_day' => 0,
270
- 'end_year' => 0,
271
- 'minutes_interval' => 0,
272
- 'end_month' => 0,
273
- 'minutes_duration' => 0,
274
- 'start_year' => now.year,
275
- 'start_month' => now.month,
276
- 'start_day' => now.day,
277
- 'start_hour' => now.hour,
278
- 'start_minute' => now.min,
279
- 'trigger_type' => Win32::TaskScheduler::ONCE,
280
- }
281
- end
282
-
283
- def translate_hash_to_trigger(puppet_trigger)
284
- trigger = dummy_time_trigger
285
-
286
- if puppet_trigger['enabled'] == false
287
- trigger['flags'] |= Win32::TaskScheduler::TASK_TRIGGER_FLAG_DISABLED
288
- else
289
- trigger['flags'] &= ~Win32::TaskScheduler::TASK_TRIGGER_FLAG_DISABLED
290
- end
291
-
292
- extra_keys = puppet_trigger.keys.sort - ['index', 'enabled', 'schedule', 'start_date', 'start_time', 'every', 'months', 'on', 'which_occurrence', 'day_of_week', 'minutes_interval', 'minutes_duration']
293
- self.fail "Unknown trigger option(s): #{Puppet::Parameter.format_value_for_display(extra_keys)}" unless extra_keys.empty?
294
- self.fail "Must specify 'start_time' when defining a trigger" unless puppet_trigger['start_time']
295
-
296
- case puppet_trigger['schedule']
297
- when 'daily'
298
- trigger['trigger_type'] = Win32::TaskScheduler::DAILY
299
- trigger['type'] = {
300
- 'days_interval' => Integer(puppet_trigger['every'] || 1)
301
- }
302
- when 'weekly'
303
- trigger['trigger_type'] = Win32::TaskScheduler::WEEKLY
304
- trigger['type'] = {
305
- 'weeks_interval' => Integer(puppet_trigger['every'] || 1)
306
- }
307
-
308
- trigger['type']['days_of_week'] = if puppet_trigger['day_of_week']
309
- bitfield_from_days_of_week(puppet_trigger['day_of_week'])
310
- else
311
- scheduler_days_of_week.inject(0) {|day_flags,day| day_flags | day}
312
- end
313
- when 'monthly'
314
- trigger['type'] = {
315
- 'months' => bitfield_from_months(puppet_trigger['months'] || (1..12).to_a),
316
- }
317
-
318
- if puppet_trigger.keys.include?('on')
319
- if puppet_trigger.has_key?('day_of_week') or puppet_trigger.has_key?('which_occurrence')
320
- self.fail "Neither 'day_of_week' nor 'which_occurrence' can be specified when creating a monthly date-based trigger"
321
- end
322
-
323
- trigger['trigger_type'] = Win32::TaskScheduler::MONTHLYDATE
324
- trigger['type']['days'] = bitfield_from_days(puppet_trigger['on'])
325
- elsif puppet_trigger.keys.include?('which_occurrence') or puppet_trigger.keys.include?('day_of_week')
326
- self.fail 'which_occurrence cannot be specified as an array' if puppet_trigger['which_occurrence'].is_a?(Array)
327
- %w{day_of_week which_occurrence}.each do |field|
328
- self.fail "#{field} must be specified when creating a monthly day-of-week based trigger" unless puppet_trigger.has_key?(field)
329
- end
330
-
331
- trigger['trigger_type'] = Win32::TaskScheduler::MONTHLYDOW
332
- trigger['type']['weeks'] = occurrence_name_to_constant(puppet_trigger['which_occurrence'])
333
- trigger['type']['days_of_week'] = bitfield_from_days_of_week(puppet_trigger['day_of_week'])
334
- else
335
- self.fail "Don't know how to create a 'monthly' schedule with the options: #{puppet_trigger.keys.sort.join(', ')}"
336
- end
337
- when 'once'
338
- self.fail "Must specify 'start_date' when defining a one-time trigger" unless puppet_trigger['start_date']
339
-
340
- trigger['trigger_type'] = Win32::TaskScheduler::ONCE
341
- else
342
- self.fail "Unknown schedule type: #{puppet_trigger["schedule"].inspect}"
343
- end
344
-
345
- integer_interval = -1
346
- if puppet_trigger['minutes_interval']
347
- integer_interval = Integer(puppet_trigger['minutes_interval'])
348
- self.fail 'minutes_interval must be an integer greater or equal to 0' if integer_interval < 0
349
- trigger['minutes_interval'] = integer_interval
350
- end
351
-
352
- integer_duration = -1
353
- if puppet_trigger['minutes_duration']
354
- integer_duration = Integer(puppet_trigger['minutes_duration'])
355
- self.fail 'minutes_duration must be an integer greater than minutes_interval and equal to or greater than 0' if integer_duration <= integer_interval && integer_duration != 0
356
- trigger['minutes_duration'] = integer_duration
357
- end
358
-
359
- if integer_interval > 0 && integer_duration == -1
360
- integer_duration = MINUTES_IN_DAY
361
- trigger['minutes_duration'] = MINUTES_IN_DAY
362
- end
363
-
364
- if integer_interval >= integer_duration && integer_interval > 0
365
- self.fail 'minutes_interval cannot be set without minutes_duration also being set to a number greater than 0'
366
- end
367
-
368
- if start_date = puppet_trigger['start_date']
369
- start_date = Date.parse(start_date)
370
- self.fail "start_date must be on or after 1753-01-01" unless start_date >= Date.new(1753, 1, 1)
371
-
372
- trigger['start_year'] = start_date.year
373
- trigger['start_month'] = start_date.month
374
- trigger['start_day'] = start_date.day
375
- end
376
-
377
- start_time = Time.parse(puppet_trigger['start_time'])
378
- trigger['start_hour'] = start_time.hour
379
- trigger['start_minute'] = start_time.min
380
-
381
- trigger
382
- end
383
-
384
- def validate_trigger(value)
385
- value = [value] unless value.is_a?(Array)
386
-
387
- value.each do |t|
388
- if t.has_key?('index')
389
- self.fail "'index' is read-only on scheduled_task triggers and should be removed ('index' is usually provided in puppet resource scheduled_task)."
390
- end
391
-
392
- if t.has_key?('enabled')
393
- self.fail "'enabled' is read-only on scheduled_task triggers and should be removed ('enabled' is usually provided in puppet resource scheduled_task)."
394
- end
395
-
396
- translate_hash_to_trigger(t)
397
- end
398
-
399
- true
400
- end
401
-
402
- private
403
-
404
- def bitfield_from_months(months)
405
- bitfield = 0
406
-
407
- months = [months] unless months.is_a?(Array)
408
- months.each do |month|
409
- integer_month = Integer(month) rescue nil
410
- self.fail 'Month must be specified as an integer in the range 1-12' unless integer_month == month.to_f and integer_month.between?(1,12)
411
-
412
- bitfield |= scheduler_months[integer_month - 1]
413
- end
414
-
415
- bitfield
416
- end
417
-
418
- def bitfield_from_days(days)
419
- bitfield = 0
420
-
421
- days = [days] unless days.is_a?(Array)
422
- days.each do |day|
423
- # The special "day" of 'last' is represented by day "number"
424
- # 32. 'last' has the special meaning of "the last day of the
425
- # month", no matter how many days there are in the month.
426
- day = 32 if day == 'last'
427
-
428
- integer_day = Integer(day)
429
- self.fail "Day must be specified as an integer in the range 1-31, or as 'last'" unless integer_day.between?(1,32)
430
-
431
- bitfield |= 1 << integer_day - 1
432
- end
433
-
434
- bitfield
435
- end
436
-
437
- def bitfield_from_days_of_week(days_of_week)
438
- bitfield = 0
439
-
440
- days_of_week = [days_of_week] unless days_of_week.is_a?(Array)
441
- days_of_week.each do |day_of_week|
442
- bitfield |= day_of_week_name_to_constant(day_of_week)
443
- end
444
-
445
- bitfield
446
- end
447
-
448
- def months_from_bitfield(bitfield)
449
- months = []
450
-
451
- scheduler_months.each do |month|
452
- if bitfield & month != 0
453
- months << month_constant_to_number(month)
454
- end
455
- end
456
-
457
- months
458
- end
459
-
460
- def days_from_bitfield(bitfield)
461
- days = []
462
-
463
- i = 0
464
- while bitfield > 0
465
- if bitfield & 1 > 0
466
- # Day 32 has the special meaning of "the last day of the
467
- # month", no matter how many days there are in the month.
468
- days << (i == 31 ? 'last' : i + 1)
469
- end
470
-
471
- bitfield = bitfield >> 1
472
- i += 1
473
- end
474
-
475
- days
476
- end
477
-
478
- def days_of_week_from_bitfield(bitfield)
479
- days_of_week = []
480
-
481
- scheduler_days_of_week.each do |day_of_week|
482
- if bitfield & day_of_week != 0
483
- days_of_week << day_of_week_constant_to_name(day_of_week)
484
- end
485
- end
486
-
487
- days_of_week
488
- end
489
-
490
- def scheduler_trigger_types
491
- [
492
- Win32::TaskScheduler::TASK_TIME_TRIGGER_DAILY,
493
- Win32::TaskScheduler::TASK_TIME_TRIGGER_WEEKLY,
494
- Win32::TaskScheduler::TASK_TIME_TRIGGER_MONTHLYDATE,
495
- Win32::TaskScheduler::TASK_TIME_TRIGGER_MONTHLYDOW,
496
- Win32::TaskScheduler::TASK_TIME_TRIGGER_ONCE
497
- ]
498
- end
499
-
500
- def scheduler_days_of_week
501
- [
502
- Win32::TaskScheduler::SUNDAY,
503
- Win32::TaskScheduler::MONDAY,
504
- Win32::TaskScheduler::TUESDAY,
505
- Win32::TaskScheduler::WEDNESDAY,
506
- Win32::TaskScheduler::THURSDAY,
507
- Win32::TaskScheduler::FRIDAY,
508
- Win32::TaskScheduler::SATURDAY
509
- ]
510
- end
511
-
512
- def scheduler_months
513
- [
514
- Win32::TaskScheduler::JANUARY,
515
- Win32::TaskScheduler::FEBRUARY,
516
- Win32::TaskScheduler::MARCH,
517
- Win32::TaskScheduler::APRIL,
518
- Win32::TaskScheduler::MAY,
519
- Win32::TaskScheduler::JUNE,
520
- Win32::TaskScheduler::JULY,
521
- Win32::TaskScheduler::AUGUST,
522
- Win32::TaskScheduler::SEPTEMBER,
523
- Win32::TaskScheduler::OCTOBER,
524
- Win32::TaskScheduler::NOVEMBER,
525
- Win32::TaskScheduler::DECEMBER
526
- ]
527
- end
528
-
529
- def scheduler_occurrences
530
- [
531
- Win32::TaskScheduler::FIRST_WEEK,
532
- Win32::TaskScheduler::SECOND_WEEK,
533
- Win32::TaskScheduler::THIRD_WEEK,
534
- Win32::TaskScheduler::FOURTH_WEEK,
535
- Win32::TaskScheduler::LAST_WEEK
536
- ]
537
- end
538
-
539
- def day_of_week_constant_to_name(constant)
540
- case constant
541
- when Win32::TaskScheduler::SUNDAY; 'sun'
542
- when Win32::TaskScheduler::MONDAY; 'mon'
543
- when Win32::TaskScheduler::TUESDAY; 'tues'
544
- when Win32::TaskScheduler::WEDNESDAY; 'wed'
545
- when Win32::TaskScheduler::THURSDAY; 'thurs'
546
- when Win32::TaskScheduler::FRIDAY; 'fri'
547
- when Win32::TaskScheduler::SATURDAY; 'sat'
548
- end
549
- end
550
-
551
- def day_of_week_name_to_constant(name)
552
- case name
553
- when 'sun'; Win32::TaskScheduler::SUNDAY
554
- when 'mon'; Win32::TaskScheduler::MONDAY
555
- when 'tues'; Win32::TaskScheduler::TUESDAY
556
- when 'wed'; Win32::TaskScheduler::WEDNESDAY
557
- when 'thurs'; Win32::TaskScheduler::THURSDAY
558
- when 'fri'; Win32::TaskScheduler::FRIDAY
559
- when 'sat'; Win32::TaskScheduler::SATURDAY
560
- end
561
- end
562
-
563
- def month_constant_to_number(constant)
564
- month_num = 1
565
- while constant >> month_num - 1 > 1
566
- month_num += 1
567
- end
568
- month_num
569
- end
570
-
571
- def occurrence_constant_to_name(constant)
572
- case constant
573
- when Win32::TaskScheduler::FIRST_WEEK; 'first'
574
- when Win32::TaskScheduler::SECOND_WEEK; 'second'
575
- when Win32::TaskScheduler::THIRD_WEEK; 'third'
576
- when Win32::TaskScheduler::FOURTH_WEEK; 'fourth'
577
- when Win32::TaskScheduler::LAST_WEEK; 'last'
578
- end
579
- end
580
-
581
- def occurrence_name_to_constant(name)
582
- case name
583
- when 'first'; Win32::TaskScheduler::FIRST_WEEK
584
- when 'second'; Win32::TaskScheduler::SECOND_WEEK
585
- when 'third'; Win32::TaskScheduler::THIRD_WEEK
586
- when 'fourth'; Win32::TaskScheduler::FOURTH_WEEK
587
- when 'last'; Win32::TaskScheduler::LAST_WEEK
588
- end
589
- end
590
- end
@@ -1,47 +0,0 @@
1
- Puppet::Type.type(:selboolean).provide(:getsetsebool) do
2
- desc "Manage SELinux booleans using the getsebool and setsebool binaries."
3
-
4
- commands :getsebool => "/usr/sbin/getsebool"
5
- commands :setsebool => "/usr/sbin/setsebool"
6
-
7
- def value
8
- self.debug "Retrieving value of selboolean #{@resource[:name]}"
9
-
10
- status = getsebool(@resource[:name])
11
-
12
- if status =~ / off$/
13
- return :off
14
- elsif status =~ / on$/ then
15
- return :on
16
- else
17
- status.chomp!
18
- raise Puppet::Error, "Invalid response '#{status}' returned from getsebool"
19
- end
20
- end
21
-
22
- def value=(new)
23
- persist = ""
24
- if @resource[:persistent] == :true
25
- self.debug "Enabling persistence"
26
- persist = "-P"
27
- end
28
- execoutput("#{command(:setsebool)} #{persist} #{@resource[:name]} #{new}")
29
- :file_changed
30
- end
31
-
32
- # Required workaround, since SELinux policy prevents setsebool
33
- # from writing to any files, even tmp, preventing the standard
34
- # 'setsebool("...")' construct from working.
35
-
36
- def execoutput (cmd)
37
- output = ''
38
- begin
39
- execpipe(cmd) do |out|
40
- output = out.readlines.join('').chomp!
41
- end
42
- rescue Puppet::ExecutionFailure
43
- raise Puppet::ExecutionFailure, output.split("\n")[0], $!.backtrace
44
- end
45
- output
46
- end
47
- end