Class: ChefMetal::ConvergenceStrategy::InstallMsi

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

Constant Summary collapse

@@install_msi_cache =
{}

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) ⇒ InstallMsi

Returns a new instance of InstallMsi.



9
10
11
12
13
14
# File 'lib/chef_metal/convergence_strategy/install_msi.rb', line 9

def initialize(convergence_options, config)
  super
  @install_msi_url = convergence_options[:install_msi_url] || 'http://www.opscode.com/chef/install.msi'
  @install_msi_path = convergence_options[:install_msi_path] || "%TEMP%\\#{File.basename(@install_msi_url)}"
  @chef_client_timeout = convergence_options.has_key?(:chef_client_timeout) ? convergence_options[:chef_client_timeout] : 120*60 # Default: 2 hours
end

Instance Attribute Details

#install_msi_pathObject (readonly)

Returns the value of attribute install_msi_path.



17
18
19
# File 'lib/chef_metal/convergence_strategy/install_msi.rb', line 17

def install_msi_path
  @install_msi_path
end

#install_msi_urlObject (readonly)

Returns the value of attribute install_msi_url.



16
17
18
# File 'lib/chef_metal/convergence_strategy/install_msi.rb', line 16

def install_msi_url
  @install_msi_url
end

Instance Method Details

#converge(action_handler, machine) ⇒ Object



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

def converge(action_handler, machine)
  super

  # TODO For some reason I get a 500 back if I don't do -l debug
  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 debug",
        :stream_stdout => stdout,
        :stream_stderr => stderr,
        :timeout => @chef_client_timeout)
    end
  end
end

#setup_convergence(action_handler, machine) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/chef_metal/convergence_strategy/install_msi.rb', line 19

def setup_convergence(action_handler, machine)
  if !convergence_options.has_key?(:client_rb_path) || !convergence_options.has_key?(:client_pem_path)
    system_drive = machine.execute_always('$env:SystemDrive').stdout.strip
    @convergence_options = Cheffish::MergedConfig.new(convergence_options, {
      :client_rb_path => "#{system_drive}\\chef\\client.rb",
      :client_pem_path => "#{system_drive}\\chef\\client.pem"
    })
  end

  super

  # Install chef-client.  TODO check and update version if not latest / not desired
  if machine.execute_always('chef-client -v').exitstatus != 0
    # TODO ssh verification of install.msi before running arbtrary code would be nice?
    # TODO find a way to cache this on the host like with the Unix stuff.
    # Limiter is we don't know how to efficiently upload large files to
    # the remote machine with WMI.
    machine.execute(action_handler, "(New-Object System.Net.WebClient).DownloadFile(#{machine.escape(install_msi_url)}, #{machine.escape(install_msi_path)})")
    machine.execute(action_handler, "msiexec /qn /i #{machine.escape(install_msi_path)}")
  end
end