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

  • :package_metadata


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

def initialize(convergence_options, config)
  convergence_options = Cheffish::MergedConfig.new(convergence_options.to_hash, {
    :client_rb_path => '/etc/chef/client.rb',
    :client_pem_path => '/etc/chef/client.pem'
  })
  super(convergence_options, config)
  @client_rb_path ||= convergence_options[:client_rb_path]
  @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
  @package_metadata ||= convergence_options[:package_metadata]
end

Instance Attribute Details

#chef_versionObject (readonly)

Returns the value of attribute chef_version


44
45
46
# File 'lib/chef/provisioning/convergence_strategy/install_cached.rb', line 44

def chef_version
  @chef_version
end

#client_pem_pathObject (readonly)

Returns the value of attribute client_pem_path


43
44
45
# File 'lib/chef/provisioning/convergence_strategy/install_cached.rb', line 43

def client_pem_path
  @client_pem_path
end

#client_rb_pathObject (readonly)

Returns the value of attribute client_rb_path


42
43
44
# File 'lib/chef/provisioning/convergence_strategy/install_cached.rb', line 42

def client_rb_path
  @client_rb_path
end

#prereleaseObject (readonly)

Returns the value of attribute prerelease


45
46
47
# File 'lib/chef/provisioning/convergence_strategy/install_cached.rb', line 45

def prerelease
  @prerelease
end

Instance Method Details

#converge(action_handler, machine) ⇒ Object


78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/chef/provisioning/convergence_strategy/install_cached.rb', line 78

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 << " -c #{@client_rb_path} -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


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/chef/provisioning/convergence_strategy/install_cached.rb', line 47

def setup_convergence(action_handler, machine)
  super

  # Check for existing chef client.
  version = machine.execute_always('chef-client -v')

  # Don't do install/upgrade if a chef client exists and
  # no chef version is defined by user configs or
  # the chef client's version already matches user config
  if version.exitstatus == 0
    version = version.stdout.strip
    if !chef_version
      return
    elsif version =~ /Chef: #{chef_version}$/
      Chef::Log.debug "Already installed chef version #{version}"
      return
    elsif version.include?(chef_version)
      Chef::Log.warn "Installed chef version #{version} contains desired version #{chef_version}.  " +
        "If you see this message on consecutive chef runs tighten your desired version constraint to prevent " +
        "multiple convergence."
    end
  end

  # Install chef client
  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, platform, remote_package_file)
end