Class: Chef::Provider::Group::Windows

Inherits:
Chef::Provider::Group show all
Defined in:
lib/chef/provider/group/windows.rb

Instance Attribute Summary

Attributes inherited from Chef::Provider::Group

#group_exists

Attributes inherited from Chef::Provider

#current_resource, #new_resource, #run_context

Instance Method Summary collapse

Methods inherited from Chef::Provider::Group

#action_create, #action_manage, #action_modify, #action_remove, #compare_group

Methods included from Mixin::Command

#chdir_or_tmpdir, #handle_command_failures, #not_if, #only_if, #output_of_command, #run_command, #run_command_with_systems_locale

Methods included from Mixin::Command::Windows

#popen4

Methods included from Mixin::Command::Unix

#popen4

Methods inherited from Chef::Provider

#action_nothing, build_from_file, #cookbook_name, #node, #resource_collection

Methods included from Mixin::ConvertToClassName

#convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string, #snake_case_basename

Methods included from Mixin::RecipeDefinitionDSLCore

#method_missing

Methods included from Mixin::Language

#data_bag, #data_bag_item, #platform?, #search, #value_for_platform

Constructor Details

#initialize(new_resource, run_context) ⇒ Windows

Returns a new instance of Windows.



29
30
31
32
# File 'lib/chef/provider/group/windows.rb', line 29

def initialize(new_resource,run_context)
  super
  @net_group = Chef::Util::Windows::NetGroup.new(@new_resource.name)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Chef::Mixin::RecipeDefinitionDSLCore

Instance Method Details

#create_groupObject



53
54
55
56
# File 'lib/chef/provider/group/windows.rb', line 53

def create_group
  @net_group.local_add
  manage_group
end

#load_current_resourceObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/chef/provider/group/windows.rb', line 34

def load_current_resource
  @current_resource = Chef::Resource::Group.new(@new_resource.name)
  @current_resource.group_name(@new_resource.group_name)

  members = nil
  begin
    members = @net_group.local_get_members
  rescue => e
    @group_exists = false
    Chef::Log.debug("#{@new_resource}: group does not exist")
  end

  if members
    @current_resource.members(members)
  end

  @current_resource
end

#manage_groupObject



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/chef/provider/group/windows.rb', line 58

def manage_group
  if @new_resource.append
    begin
      #ERROR_MEMBER_IN_ALIAS if a member already exists in the group
      @net_group.local_add_members(@new_resource.members)
    rescue
      members = @new_resource.members + @current_resource.members
      @net_group.local_set_members(members.uniq)
    end
  else
    @net_group.local_set_members(@new_resource.members)
  end
end

#remove_groupObject



72
73
74
# File 'lib/chef/provider/group/windows.rb', line 72

def remove_group
  @net_group.local_delete
end