summaryrefslogtreecommitdiff
path: root/lib/chef
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2021-06-05 17:54:26 -0700
committerTim Smith <tsmith@chef.io>2021-06-05 17:55:33 -0700
commit244ec5ccc4d35d0dc5f942f529c38f47528d69b1 (patch)
treeda163b7d2e9d5e68d569e69b8f975ae4112be70c /lib/chef
parentc66c37b7dd2dc0413d8d98885d4ad7b6ef604016 (diff)
downloadchef-244ec5ccc4d35d0dc5f942f529c38f47528d69b1.tar.gz
Speed up / avoid double logging in windows_printer_port
We already use converge_by here so there's no need to then use powershell_script which is slower than just running powershell_exec! Signed-off-by: Tim Smith <tsmith@chef.io>
Diffstat (limited to 'lib/chef')
-rw-r--r--lib/chef/resource/windows_printer_port.rb13
1 files changed, 5 insertions, 8 deletions
diff --git a/lib/chef/resource/windows_printer_port.rb b/lib/chef/resource/windows_printer_port.rb
index ae58ed3c6c..0edaa4fede 100644
--- a/lib/chef/resource/windows_printer_port.rb
+++ b/lib/chef/resource/windows_printer_port.rb
@@ -1,6 +1,7 @@
#
# Author:: Doug Ireton <doug@1strategy.com>
# Copyright:: 2012-2018, Nordstrom, Inc.
+# Copyright:: Chef Software, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -130,8 +131,7 @@ class Chef
port_name = new_resource.port_name || "IP_#{new_resource.ipv4_address}"
# create the printer port using PowerShell
- declare_resource(:powershell_script, "Creating printer port #{new_resource.port_name}") do
- code <<-EOH
+ powershell_exec! <<-EOH
Set-WmiInstance -class Win32_TCPIPPrinterPort `
-EnableAllPrivileges `
@@ -142,19 +142,16 @@ class Chef
Protocol = "#{new_resource.port_protocol}";
SNMPEnabled = "$#{new_resource.snmp_enabled}";
}
- EOH
- end
+ EOH
end
def delete_printer_port
port_name = new_resource.port_name || "IP_#{new_resource.ipv4_address}"
- declare_resource(:powershell_script, "Deleting printer port: #{new_resource.port_name}") do
- code <<-EOH
+ powershell_exec! <<-EOH
$port = Get-WMIObject -class Win32_TCPIPPrinterPort -EnableAllPrivileges -Filter "name = '#{port_name}'"
$port.Delete()
- EOH
- end
+ EOH
end
end
end