Class: Chef::Provisioning::ConvergenceStrategy::InstallCached

Inherits:
PrecreateChefObjects show all
Defined in:
lib/chef/provisioning/convergence_strategy/install_cached.rb

Instance Attribute Summary collapse

Attributes inherited from Chef::Provisioning::ConvergenceStrategy

#config, #convergence_options

Instance Method Summary collapse

Methods inherited from PrecreateChefObjects

#chef_server, #cleanup_convergence

Methods inherited from Chef::Provisioning::ConvergenceStrategy

#cleanup_convergence

Constructor Details

#initialize(convergence_options, config) ⇒ InstallCached

convergence_options is a hash of setup convergence_options, including:

  • :chef_server

  • :allow_overwrite_keys

  • :source_key, :source_key_path, :source_key_pass_phrase

  • :private_key_options

  • :ohai_hints

  • :public_key_path, :public_key_format

  • :admin, :validator

  • :chef_client_timeout

  • :client_rb_path, :client_pem_path

  • :chef_version, :prerelease, :package_cache_path


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/chef/provisioning/convergence_strategy/install_cached.rb', line 23

def initialize(convergence_options, config)
  convergence_options = Cheffish::MergedConfig.new(convergence_options, {
    :client_rb_path => '/etc/chef/client.rb',
    :client_pem_path => '/etc/chef/client.pem'
  })
  super(convergence_options, config)
  @chef_version ||= convergence_options[:chef_version]
  @prerelease ||= convergence_options[:prerelease]
  @package_cache_path ||= convergence_options[:package_cache_path] || "#{ENV['HOME']}/.chef/package_cache"
  @package_cache = {}
  @tmp_dir = '/tmp'
  @chef_client_timeout = convergence_options.has_key?(:chef_client_timeout) ? convergence_options[:chef_client_timeout] : 120*60 # Default: 2 hours
  FileUtils.mkdir_p(@package_cache_path)
  @package_cache_lock = Mutex.new
end

Instance Attribute Details

#client_pem_pathObject (readonly)

Returns the value of attribute client_pem_path


40
41
42
# File 'lib/chef/provisioning/convergence_strategy/install_cached.rb', line 40

def client_pem_path
  @client_pem_path
end

#client_rb_pathObject (readonly)

Returns the value of attribute client_rb_path


39
40
41
# File 'lib/chef/provisioning/convergence_strategy/install_cached.rb', line 39

def client_rb_path
  @client_rb_path
end

Instance Method Details

#converge(action_handler, machine) ⇒ Object


55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/chef/provisioning/convergence_strategy/install_cached.rb', line 55

def converge(action_handler, machine)
  super

  action_handler.open_stream(machine.node['name']) do |stdout|
    action_handler.open_stream(machine.node['name']) do |stderr|
      command_line = "chef-client"
      command_line << " -l #{config[:log_level].to_s}" if config[:log_level]
      machine.execute(action_handler, command_line,
        :stream_stdout => stdout,
        :stream_stderr => stderr,
        :timeout => @chef_client_timeout)
    end
  end
end

#setup_convergence(action_handler, machine) ⇒ Object


42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/chef/provisioning/convergence_strategy/install_cached.rb', line 42

def setup_convergence(action_handler, machine)
  super

  # Install chef-client.  TODO check and update version if not latest / not desired
  if machine.execute_always('chef-client -v').exitstatus != 0
    platform, platform_version, machine_architecture = machine.detect_os(action_handler)
    package_file = download_package_for_platform(action_handler, machine, platform, platform_version, machine_architecture)
    remote_package_file = "#{@tmp_dir}/#{File.basename(package_file)}"
    machine.upload_file(action_handler, package_file, remote_package_file)
    install_package(action_handler, machine, remote_package_file)
  end
end