Class: ChefMetal::ConvergenceStrategy::InstallCached

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

Instance Attribute Summary

Attributes inherited from PrecreateChefObjects

#client_pem_path, #client_rb_path

Instance Method Summary collapse

Methods inherited from PrecreateChefObjects

#cleanup_convergence

Methods inherited from ChefMetal::ConvergenceStrategy

#cleanup_convergence

Constructor Details

#initialize(options = {}) ⇒ InstallCached

Returns a new instance of InstallCached.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/chef_metal/convergence_strategy/install_cached.rb', line 10

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

Instance Method Details

#converge(action_handler, machine, chef_server) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/chef_metal/convergence_strategy/install_cached.rb', line 36

def converge(action_handler, machine, chef_server)
  super

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

#setup_convergence(action_handler, machine, machine_resource) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/chef_metal/convergence_strategy/install_cached.rb', line 23

def setup_convergence(action_handler, machine, machine_resource)
  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