class Chef::Resource::ChefMirror
Public Instance Methods
copy_to(src_root, dest_root)
click to toggle source
# File lib/chef/resource/chef_mirror.rb, line 96 def copy_to(src_root, dest_root) if new_resource.concurrency <= 0 raise "chef_mirror.concurrency must be above 0! Was set to #{new_resource.concurrency}" end # Honor concurrency ChefUtils::DefaultThreadPool.instance.threads = new_resource.concurrency - 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, options, ui, proc { |p| p.path }) if error raise "Errors while copying:#{ui.errors.map { |e| "#{e}\n" }.join("")}" end end
freeze(arg = nil)
click to toggle source
`freeze` is an already-existing instance method on Object, so we can't use it or we'll throw a deprecation warning. `freeze` has been renamed to `freeze_on_upload` and this method is here to log a deprecation warning.
# File lib/chef/resource/chef_mirror.rb, line 43 def freeze(arg = nil) Chef::Log.warn("Property `freeze` on the `chef_mirror` resource has changed to `freeze_on_upload`." \ "Please use `freeze_on_upload` instead. This will raise an exception in a future version of the cheffish gem.") set_or_return( :freeze_on_upload, arg, kind_of: [TrueClass, FalseClass] ) end
load_current_resource()
click to toggle source
# File lib/chef/resource/chef_mirror.rb, line 186 def load_current_resource; end
local_fs()
click to toggle source
# File lib/chef/resource/chef_mirror.rb, line 120 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.expand_path(path) } end # Set up the root dir Chef::ChefFS::FileSystem::Repository::ChefRepositoryFileSystemRootDir.new(object_paths) end
options()
click to toggle source
# File lib/chef/resource/chef_mirror.rb, line 173 def options result = { purge: new_resource.purge, freeze: new_resource.freeze_on_upload, 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()
click to toggle source
# File lib/chef/resource/chef_mirror.rb, line 158 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::ChefServer::ChefServerRootDir.new("remote", config) end
repo_mode()
click to toggle source
# File lib/chef/resource/chef_mirror.rb, line 169 def repo_mode %r{/organizations/}.match?(new_resource.chef_server[:chef_server_url]) ? "hosted_everything" : "everything" end
with_modified_config() { || ... }
click to toggle source
# File lib/chef/resource/chef_mirror.rb, line 75 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