diff options
author | Tim Smith <tsmith@chef.io> | 2021-06-13 13:34:41 -0700 |
---|---|---|
committer | Tim Smith <tsmith@chef.io> | 2021-06-13 18:28:36 -0700 |
commit | 59c5bcdd55cd663d74ddc0809c42defb61252da5 (patch) | |
tree | ced9a60011958861a9aa87d308381f6aa8c741c8 | |
parent | 494e7ed6ae56438aad952d8b072bc5a3c3615224 (diff) | |
download | chef-59c5bcdd55cd663d74ddc0809c42defb61252da5.tar.gz |
Try to handle the driver installation
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r-- | kitchen-tests/cookbooks/end_to_end/recipes/_windows_printer.rb | 2 | ||||
-rw-r--r-- | lib/chef/resource/windows_printer.rb | 17 |
2 files changed, 14 insertions, 5 deletions
diff --git a/kitchen-tests/cookbooks/end_to_end/recipes/_windows_printer.rb b/kitchen-tests/cookbooks/end_to_end/recipes/_windows_printer.rb index 18da8af3b0..64a05c05c9 100644 --- a/kitchen-tests/cookbooks/end_to_end/recipes/_windows_printer.rb +++ b/kitchen-tests/cookbooks/end_to_end/recipes/_windows_printer.rb @@ -33,6 +33,6 @@ end windows_printer "HP LaserJet 5th Floor" do ipv4_address "10.4.64.41" driver_name "Generic / Text Only" - port_name "My awesome printer port" + port_name "My awesome port" create_port false end diff --git a/lib/chef/resource/windows_printer.rb b/lib/chef/resource/windows_printer.rb index b64f67a142..24d746b648 100644 --- a/lib/chef/resource/windows_printer.rb +++ b/lib/chef/resource/windows_printer.rb @@ -22,6 +22,10 @@ require_relative "../resource" class Chef class Resource + # @todo + # 1. Allow updating the printer properties + # 2. Fail with a warning if the port can't be found and create_port is false + # 3. Fail with helpful messaging if the printer driver can't be installed class WindowsPrinter < Chef::Resource unified_mode true @@ -29,7 +33,7 @@ class Chef provides(:windows_printer) { true } - description "Use the **windows_printer** resource to setup Windows printers. Note that this doesn't currently install a printer driver. You must already have the driver installed on the system." + description "Use the **windows_printer** resource to setup Windows printers. This resource will automatically install the driver specified in the `driver_name` property and will automatically create a printer port using either the `ipv4_address` property or the `port_name property." introduced "14.0" examples <<~DOC **Create a printer**: @@ -67,7 +71,6 @@ class Chef create_port false end ``` - DOC property :device_id, String, @@ -122,13 +125,15 @@ class Chef device_id new_resource.device_id comment printer_data["Comment"] default printer_data["Default"] - driver_name printer_data["DriverName"] location printer_data["Location"] shared printer_data["Shared"] share_name printer_data["ShareName"] port_name printer_data["PortName"] - # @todo handle the port current_resource + driver_data = powershell_exec(%Q{Get-PrinterDriver -Name="#{new_resource.driver_name}"}).result + unless driver_data.empty? + driver_name new_resource.driver_name + end end end @@ -144,6 +149,10 @@ class Chef end end + converge_by("install driver #{new_resource.driver_name}") do + powershell_exec!("Add-PrinterDriver -Name '#{new_resource.driver_name}'") + end + converge_by("create #{@new_resource.device_id}") do powershell_exec! <<-EOH Set-WmiInstance -class Win32_Printer ` |