Class: ChefMetal::ConvergenceStrategy::InstallCached

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

Instance Attribute Summary collapse

Attributes inherited from ChefMetal::ConvergenceStrategy

#config, #convergence_options

Instance Method Summary collapse

Methods inherited from PrecreateChefObjects

#chef_server, #cleanup_convergence

Methods inherited from ChefMetal::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



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

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.



38
39
40
# File 'lib/chef_metal/convergence_strategy/install_cached.rb', line 38

def client_pem_path
  @client_pem_path
end

#client_rb_pathObject (readonly)

Returns the value of attribute client_rb_path.



37
38
39
# File 'lib/chef_metal/convergence_strategy/install_cached.rb', line 37

def client_rb_path
  @client_rb_path
end

Instance Method Details

#converge(action_handler, machine) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/chef_metal/convergence_strategy/install_cached.rb', line 53

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



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/chef_metal/convergence_strategy/install_cached.rb', line 40

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