Class: Chef::Provider::ChefMirror
- Inherits:
-
LWRPBase
- Object
- LWRPBase
- Chef::Provider::ChefMirror
- Defined in:
- lib/chef/provider/chef_mirror.rb
Defined Under Namespace
Classes: CopyListener
Instance Method Summary collapse
- #copy_to(src_root, dest_root) ⇒ Object
- #load_current_resource ⇒ Object
- #local_fs ⇒ Object
- #options ⇒ Object
- #remote_fs ⇒ Object
- #repo_mode ⇒ Object
- #whyrun_supported? ⇒ Boolean
- #with_modified_config ⇒ Object
Instance Method Details
#copy_to(src_root, dest_root) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/chef/provider/chef_mirror.rb', line 50 def copy_to(src_root, dest_root) if new_resource.concurrency && new_resource.concurrency <= 0 raise "chef_mirror.concurrency must be above 0! Was set to #{new_resource.concurrency}" end # Honor concurrency Chef::ChefFS::Parallelizer.threads = (new_resource.concurrency || 10) - 1 # We don't let the user pass absolute paths; we want to reserve those for # multi-org support (/organizations/foo). if new_resource.path[0] == '/' raise "Absolute paths in chef_mirror not yet supported." end # Copy! path = Chef::ChefFS::FilePattern.new("/#{new_resource.path}") ui = CopyListener.new(self) error = Chef::ChefFS::FileSystem.copy_to(path, src_root, dest_root, nil, , ui, proc { |p| p.path }) if error raise "Errors while copying:#{ui.errors.map { |e| "#{e}\n" }.join('')}" end end |
#load_current_resource ⇒ Object
138 139 |
# File 'lib/chef/provider/chef_mirror.rb', line 138 def load_current_resource end |
#local_fs ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/chef/provider/chef_mirror.rb', line 72 def local_fs # If chef_repo_path is set to a string, put it in the form it usually is in # chef config (:chef_repo_path, :node_path, etc.) path_config = new_resource.chef_repo_path if path_config.is_a?(Hash) chef_repo_path = path_config.delete(:chef_repo_path) elsif path_config chef_repo_path = path_config path_config = {} else chef_repo_path = Chef::Config.chef_repo_path path_config = Chef::Config end chef_repo_path = Array(chef_repo_path).flatten # Go through the expected object paths and figure out the local paths for each. case repo_mode when 'hosted_everything' object_names = %w(acls clients cookbooks containers data_bags environments groups nodes roles) else object_names = %w(clients cookbooks data_bags environments nodes roles users) end object_paths = {} object_names.each do |object_name| variable_name = "#{object_name[0..-2]}_path" # cookbooks -> cookbook_path if path_config[variable_name.to_sym] paths = Array(path_config[variable_name.to_sym]).flatten else paths = chef_repo_path.map { |path| ::File.join(path, object_name) } end object_paths[object_name] = paths.map { |path| ::File.(path) } end # Set up the root dir Chef::ChefFS::FileSystem::ChefRepositoryFileSystemRootDir.new(object_paths) end |
#options ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/chef/provider/chef_mirror.rb', line 125 def result = { :purge => new_resource.purge, :freeze => new_resource.freeze, :diff => new_resource.no_diff, :dry_run => whyrun_mode? } result[:diff] = !result[:diff] result[:repo_mode] = repo_mode result[:concurrency] = new_resource.concurrency if new_resource.concurrency result end |
#remote_fs ⇒ Object
110 111 112 113 114 115 116 117 118 119 |
# File 'lib/chef/provider/chef_mirror.rb', line 110 def remote_fs config = { :chef_server_url => new_resource.chef_server[:chef_server_url], :node_name => new_resource.chef_server[:options][:client_name], :client_key => new_resource.chef_server[:options][:signing_key_filename], :repo_mode => repo_mode, :versioned_cookbooks => Chef::Config.versioned_cookbooks } Chef::ChefFS::FileSystem::ChefServerRootDir.new("remote", config) end |
#repo_mode ⇒ Object
121 122 123 |
# File 'lib/chef/provider/chef_mirror.rb', line 121 def repo_mode new_resource.chef_server[:chef_server_url] =~ /\/organizations\// ? 'hosted_everything' : 'everything' end |
#whyrun_supported? ⇒ Boolean
13 14 15 |
# File 'lib/chef/provider/chef_mirror.rb', line 13 def whyrun_supported? true end |
#with_modified_config ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/chef/provider/chef_mirror.rb', line 29 def with_modified_config # pre-Chef-12 ChefFS reads versioned_cookbooks out of Chef::Config instead of # taking it as an input, so we need to modify it for the duration of copy_to @old_versioned_cookbooks = Chef::Config.versioned_cookbooks # If versioned_cookbooks is explicitly set, set it. if !new_resource.versioned_cookbooks.nil? Chef::Config.versioned_cookbooks = new_resource.versioned_cookbooks # If new_resource.chef_repo_path is set, versioned_cookbooks defaults to true. # Otherwise, it stays at its current Chef::Config value. elsif new_resource.chef_repo_path Chef::Config.versioned_cookbooks = true end begin yield ensure Chef::Config.versioned_cookbooks = @old_versioned_cookbooks end end |