class Chef::Resource::WindowsPrinterPort

Constants

PORTS_REG_KEY

Public Instance Methods

create_printer_port() click to toggle source
# File lib/chef/resource/windows_printer_port.rb, line 103
        def create_printer_port
          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

              Set-WmiInstance -class Win32_TCPIPPrinterPort `
                -EnableAllPrivileges `
                -Argument @{ HostAddress = "#{new_resource.ipv4_address}";
                            Name        = "#{port_name}";
                            Description = "#{new_resource.port_description}";
                            PortNumber  = "#{new_resource.port_number}";
                            Protocol    = "#{new_resource.port_protocol}";
                            SNMPEnabled = "$#{new_resource.snmp_enabled}";
                          }
            EOH
          end
        end
delete_printer_port() click to toggle source
# File lib/chef/resource/windows_printer_port.rb, line 123
        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
              $port = Get-WMIObject -class Win32_TCPIPPrinterPort -EnableAllPrivileges -Filter "name = '#{port_name}'"
              $port.Delete()
            EOH
          end
        end
port_exists?(name) click to toggle source
# File lib/chef/resource/windows_printer_port.rb, line 63
def port_exists?(name)
  port_reg_key = PORTS_REG_KEY + name

  logger.trace "Checking to see if this reg key exists: '#{port_reg_key}'"
  registry_key_exists?(port_reg_key)
end