Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(MODULES-6845) Allow provider to read / modify V2 tasks #27

Merged
merged 8 commits into from
May 7, 2018
20 changes: 10 additions & 10 deletions lib/puppet/provider/scheduled_task/taskscheduler_api2.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'puppet/parameter'
require_relative '../../../puppet_x/puppetlabs/scheduled_task/taskscheduler2_v1task'
require_relative '../../../puppet_x/puppetlabs/scheduled_task/taskscheduler2_task'


Puppet::Type.type(:scheduled_task).provide(:taskscheduler_api2) do
Expand All @@ -13,7 +13,7 @@
has_feature :compatibility

def self.instances
PuppetX::PuppetLabs::ScheduledTask::TaskScheduler2V1Task.new.tasks.collect do |job_file|
PuppetX::PuppetLabs::ScheduledTask::TaskScheduler2Task.new.tasks.collect do |job_file|
job_title = File.basename(job_file, '.job')
new(
:provider => :taskscheduler_api2,
Expand All @@ -23,13 +23,13 @@ def self.instances
end

def exists?
PuppetX::PuppetLabs::ScheduledTask::TaskScheduler2V1Task.new.exists? resource[:name]
PuppetX::PuppetLabs::ScheduledTask::TaskScheduler2Task.new.exists? resource[:name]
end

def task
return @task if @task

@task ||= PuppetX::PuppetLabs::ScheduledTask::TaskScheduler2V1Task.new
@task ||= PuppetX::PuppetLabs::ScheduledTask::TaskScheduler2Task.new
@task.activate(resource[:name] + '.job') if exists?

@task
Expand All @@ -41,7 +41,7 @@ def clear_task
end

def enabled
task.flags & Win32::TaskScheduler::DISABLED == 0 ? :true : :false
task.flags & PuppetX::PuppetLabs::ScheduledTask::TaskScheduler2::TASK_FLAG_DISABLED == 0 ? :true : :false
end

def command
Expand Down Expand Up @@ -118,9 +118,9 @@ def working_dir=(value)

def enabled=(value)
if value == :true
task.flags = task.flags & ~Win32::TaskScheduler::DISABLED
task.flags = task.flags & ~PuppetX::PuppetLabs::ScheduledTask::TaskScheduler2::TASK_FLAG_DISABLED
else
task.flags = task.flags | Win32::TaskScheduler::DISABLED
task.flags = task.flags | PuppetX::PuppetLabs::ScheduledTask::TaskScheduler2::TASK_FLAG_DISABLED
end
end

Expand Down Expand Up @@ -176,19 +176,19 @@ def user=(value)

def create
clear_task
@task = PuppetX::PuppetLabs::ScheduledTask::TaskScheduler2V1Task.new(
@task = PuppetX::PuppetLabs::ScheduledTask::TaskScheduler2Task.new(
resource[:name],
PuppetX::PuppetLabs::ScheduledTask::Trigger::V1.default_trigger_for('once')
)
self.command = resource[:command]

[:arguments, :working_dir, :enabled, :trigger, :user].each do |prop|
[:arguments, :working_dir, :enabled, :trigger, :user, :compatibility].each do |prop|
send("#{prop}=", resource[prop]) if resource[prop]
end
end

def destroy
PuppetX::PuppetLabs::ScheduledTask::TaskScheduler2V1Task.new.delete(resource[:name] + '.job')
PuppetX::PuppetLabs::ScheduledTask::TaskScheduler2Task.new.delete(resource[:name] + '.job')
end

def flush
Expand Down
Loading