From 18d229ca829536c115e351489f88891376232620 Mon Sep 17 00:00:00 2001 From: Jeremy Roberts Date: Sun, 30 Aug 2015 13:09:25 -0400 Subject: [PATCH] Added execution_time_limit for WinRM. Adds a configurable value for WinRm and the elevated permission shell ExecutionTimeLimit. Please see mitchellh/vagrant#5506 Ex: config.winrm.execution_time_limit = "P1D" --- plugins/communicators/winrm/communicator.rb | 3 ++- plugins/communicators/winrm/config.rb | 4 ++++ plugins/communicators/winrm/scripts/elevated_shell.ps1.erb | 5 +++-- plugins/communicators/winrm/shell.rb | 2 ++ 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/plugins/communicators/winrm/communicator.rb b/plugins/communicators/winrm/communicator.rb index fdb3fe615..38fda78f9 100644 --- a/plugins/communicators/winrm/communicator.rb +++ b/plugins/communicators/winrm/communicator.rb @@ -210,7 +210,8 @@ module VagrantPlugins "powershell -executionpolicy bypass -file \"#{guest_script_path}\" " + "-username \"#{shell.username}\" -password \"#{shell.password}\" " + - "-encoded_command \"#{wrapped_encoded_command}\"" + "-encoded_command \"#{wrapped_encoded_command}\" " + + "-execution_time_limit \"#{shell.execution_time_limit}\"" end # Handles the raw WinRM shell result and converts it to a diff --git a/plugins/communicators/winrm/config.rb b/plugins/communicators/winrm/config.rb index 79901d503..3387ca142 100644 --- a/plugins/communicators/winrm/config.rb +++ b/plugins/communicators/winrm/config.rb @@ -11,6 +11,7 @@ module VagrantPlugins attr_accessor :timeout attr_accessor :transport attr_accessor :ssl_peer_verification + attr_accessor :execution_time_limit def initialize @username = UNSET_VALUE @@ -23,6 +24,7 @@ module VagrantPlugins @timeout = UNSET_VALUE @transport = UNSET_VALUE @ssl_peer_verification = UNSET_VALUE + @execution_time_limit = UNSET_VALUE end def finalize! @@ -37,6 +39,7 @@ module VagrantPlugins @retry_delay = 2 if @retry_delay == UNSET_VALUE @timeout = 1800 if @timeout == UNSET_VALUE @ssl_peer_verification = true if @ssl_peer_verification == UNSET_VALUE + @execution_time_limit = "PT2H" if @execution_time_limit == UNSET_VALUE end def validate(machine) @@ -49,6 +52,7 @@ module VagrantPlugins errors << "winrm.max_tries cannot be nil." if @max_tries.nil? errors << "winrm.retry_delay cannot be nil." if @max_tries.nil? errors << "winrm.timeout cannot be nil." if @timeout.nil? + errors << "winrm.execution_time_limit cannot be nil." if @execution_time_limit.nil? unless @ssl_peer_verification == true || @ssl_peer_verification == false errors << "winrm.ssl_peer_verification must be a boolean." end diff --git a/plugins/communicators/winrm/scripts/elevated_shell.ps1.erb b/plugins/communicators/winrm/scripts/elevated_shell.ps1.erb index 17767e436..66bc94043 100644 --- a/plugins/communicators/winrm/scripts/elevated_shell.ps1.erb +++ b/plugins/communicators/winrm/scripts/elevated_shell.ps1.erb @@ -1,4 +1,4 @@ -param([String]$username, [String]$password, [String]$encoded_command) +param([String]$username, [String]$password, [String]$encoded_command, [String]$execution_time_limit) $task_name = "WinRM_Elevated_Shell" $out_file = "$env:SystemRoot\Temp\WinRM_Elevated_Shell.log" @@ -33,7 +33,7 @@ $task_xml = @' false false false - PT2H + {execution_time_limit} 4 @@ -49,6 +49,7 @@ $arguments = "/c powershell.exe -EncodedCommand $encoded_command > $out_file $task_xml = $task_xml.Replace("{arguments}", $arguments) $task_xml = $task_xml.Replace("{username}", $username) +$task_xml = $task_xml.Replace("{execution_time_limit}", $execution_time_limit) $schedule = New-Object -ComObject "Schedule.Service" $schedule.Connect() diff --git a/plugins/communicators/winrm/shell.rb b/plugins/communicators/winrm/shell.rb index 9b0f4e302..967565046 100644 --- a/plugins/communicators/winrm/shell.rb +++ b/plugins/communicators/winrm/shell.rb @@ -37,6 +37,7 @@ module VagrantPlugins attr_reader :port attr_reader :username attr_reader :password + attr_reader :execution_time_limit attr_reader :config def initialize(host, port, config) @@ -47,6 +48,7 @@ module VagrantPlugins @port = port @username = config.username @password = config.password + @execution_time_limit = config.execution_time_limit @config = config end