Class: Chef::Provider::Group::Pw
- Inherits:
-
Chef::Provider::Group
- Object
- Chef::Provider
- Chef::Provider::Group
- Chef::Provider::Group::Pw
- Defined in:
- lib/chef/provider/group/pw.rb
Instance Attribute Summary
Attributes inherited from Chef::Provider::Group
Attributes inherited from Chef::Provider
#current_resource, #new_resource, #node
Instance Method Summary collapse
-
#create_group ⇒ Object
Create the group.
- #load_current_resource ⇒ Object
-
#manage_group ⇒ Object
Manage the group when it already exists.
-
#remove_group ⇒ Object
Remove the group.
-
#set_members_option ⇒ Object
Set the membership option depending on the current resource states.
-
#set_options ⇒ Object
Little bit of magic as per Adam’s useradd provider to pull and assign the command line flags.
Methods inherited from Chef::Provider::Group
#action_create, #action_manage, #action_modify, #action_remove, #compare_group, #initialize
Methods included from Mixin::Command
handle_command_failures, not_if, only_if, output_of_command, popen4, run_command, run_command_with_systems_locale
Methods inherited from Chef::Provider
#action_nothing, build_from_file, #initialize
Methods included from Mixin::ConvertToClassName
#convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string
Methods included from Mixin::RecipeDefinitionDSLCore
Methods included from Mixin::Language
#data_bag, #data_bag_item, #platform?, #search, #value_for_platform
Constructor Details
This class inherits a constructor from Chef::Provider::Group
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Chef::Mixin::RecipeDefinitionDSLCore
Instance Method Details
#create_group ⇒ Object
Create the group
30 31 32 33 34 35 |
# File 'lib/chef/provider/group/pw.rb', line 30 def create_group command = "pw groupadd" command << command << set_members_option run_command(:command => command) end |
#load_current_resource ⇒ Object
24 25 26 27 |
# File 'lib/chef/provider/group/pw.rb', line 24 def load_current_resource super raise Chef::Exceptions::Group, "Could not find binary /usr/sbin/pw for #{@new_resource}" unless ::File.exists?("/usr/sbin/pw") end |
#manage_group ⇒ Object
Manage the group when it already exists
38 39 40 41 42 43 |
# File 'lib/chef/provider/group/pw.rb', line 38 def manage_group command = "pw groupmod" command << command << set_members_option run_command(:command => command) end |
#remove_group ⇒ Object
Remove the group
46 47 48 |
# File 'lib/chef/provider/group/pw.rb', line 46 def remove_group run_command(:command => "pw groupdel #{@new_resource.group_name}") end |
#set_members_option ⇒ Object
Set the membership option depending on the current resource states
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/chef/provider/group/pw.rb', line 68 def set_members_option opt = "" unless @new_resource.members.empty? opt << " -M #{@new_resource.members.join(',')}" Chef::Log.debug("#{@new_resource}: setting group members to #{@new_resource.members.join(', ')}") else # New member list is empty so we should delete any old group members unless @current_resource.members.empty? opt << " -d #{@current_resource.members.join(',')}" Chef::Log.debug("#{@new_resource}: removing group members #{@current_resource.members.join(', ')}") else Chef::Log.debug("#{@new_resource}: not changing group members, the group has no members") end end opt end |
#set_options ⇒ Object
Little bit of magic as per Adam’s useradd provider to pull and assign the command line flags
Returns
- <string>
-
A string containing the option and then the quoted value
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/chef/provider/group/pw.rb', line 54 def opts = " #{@new_resource.group_name}" { :gid => "-g" }.sort { |a,b| a[0] <=> b[0] }.each do |field, option| if @current_resource.send(field) != @new_resource.send(field) if @new_resource.send(field) Chef::Log.debug("#{@new_resource}: setting #{field.to_s} to #{@new_resource.send(field)}") opts << " #{option} '#{@new_resource.send(field)}'" end end end opts end |