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
# 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'
  FileUtils.mkdir_p(@package_cache_path)
  @package_cache_lock = Mutex.new
end

Instance Method Details

#converge(action_handler, machine) ⇒ Object



35
36
37
# File 'lib/chef_metal/convergence_strategy/install_cached.rb', line 35

def converge(action_handler, machine)
  machine.execute(action_handler, "chef-client -l #{Chef::Config.log_level.to_s}", :stream => true)
end

#setup_convergence(action_handler, machine, machine_resource) ⇒ Object



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

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