class Chef::Resource::WindowsWorkgroup

Public Instance Methods

clarify_reboot(reboot_action) click to toggle source

This resource historically took `:immediate` and `:delayed` as arguments to the reboot property but then tried to shove that straight to the `reboot` resource which objected strenuously. We need to convert these legacy actions into actual reboot actions

@return [Symbol] chef reboot resource action

# File lib/chef/resource/windows_workgroup.rb, line 59
def clarify_reboot(reboot_action)
  case reboot_action
  when :immediate
    :reboot_now
  when :delayed
    :request_reboot
  else
    reboot_action
  end
end
join_command() click to toggle source

return [String] the appropriate PS command to joint the workgroup

# File lib/chef/resource/windows_workgroup.rb, line 94
def join_command
  cmd = ""
  cmd << "$pswd = ConvertTo-SecureString \'#{new_resource.password}\' -AsPlainText -Force;" if new_resource.password
  cmd << "$credential = New-Object System.Management.Automation.PSCredential (\"#{new_resource.user}\",$pswd);" if new_resource.password
  cmd << "Add-Computer -WorkgroupName #{new_resource.workgroup_name}"
  cmd << " -Credential $credential" if new_resource.password
  cmd << " -Force"
  cmd
end
workgroup_member?() click to toggle source

@return [Boolean] is the node a member of the workgroup specified in the resource

# File lib/chef/resource/windows_workgroup.rb, line 105
def workgroup_member?
  node_workgroup = powershell_out!("(Get-WmiObject -Class Win32_ComputerSystem).Workgroup")
  raise "Failed to determine if system already a member of workgroup #{new_resource.workgroup_name}" if node_workgroup.error?
  node_workgroup.stdout.downcase.strip == new_resource.workgroup_name.downcase
end