Class: Chef::Provisioning::ConvergenceStrategy::PrecreateChefObjects

Inherits:
Chef::Provisioning::ConvergenceStrategy show all
Defined in:
lib/chef/provisioning/convergence_strategy/precreate_chef_objects.rb

Direct Known Subclasses

InstallCached, InstallMsi, InstallSh

Instance Attribute Summary

Attributes inherited from Chef::Provisioning::ConvergenceStrategy

#config, #convergence_options

Instance Method Summary collapse

Constructor Details

#initialize(convergence_options, config) ⇒ PrecreateChefObjects

Returns a new instance of PrecreateChefObjects.



12
13
14
15
16
17
# File 'lib/chef/provisioning/convergence_strategy/precreate_chef_objects.rb', line 12

def initialize(convergence_options, config)
  super
  if convergence_options[:ignore_failure]
    extend IgnoreConvergenceFailure
  end
end

Instance Method Details

#chef_serverObject



19
20
21
# File 'lib/chef/provisioning/convergence_strategy/precreate_chef_objects.rb', line 19

def chef_server
  @chef_server ||= convergence_options[:chef_server] || Cheffish.default_chef_server(config)
end

#cleanup_convergence(action_handler, machine_spec) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/chef/provisioning/convergence_strategy/precreate_chef_objects.rb', line 46

def cleanup_convergence(action_handler, machine_spec)
  _self = self
  Chef::Provisioning.inline_resource(action_handler) do
    chef_node machine_spec.name do
      chef_server _self.chef_server
      action :delete
    end
    chef_client machine_spec.name do
      chef_server _self.chef_server
      action :delete
    end
  end
end

#converge(action_handler, machine) ⇒ Object



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

def converge(action_handler, machine)
  machine.make_url_available_to_remote(chef_server[:chef_server_url])
end

#setup_convergence(action_handler, machine) ⇒ Object



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

def setup_convergence(action_handler, machine)
  # Create keys on machine
  private_key, public_key = create_keys(action_handler, machine)
  # Create node and client on chef server
  create_chef_objects(action_handler, machine, private_key, public_key)

  # If the chef server lives on localhost, tunnel the port through to the guest
  # (we need to know what got tunneled!)
  chef_server_url = chef_server[:chef_server_url]
  chef_server_url = machine.make_url_available_to_remote(chef_server_url)

  # Support for multiple ohai hints, required on some platforms
  create_ohai_files(action_handler, machine)

  # Create client.rb and client.pem on machine
  content = client_rb_content(chef_server_url, machine.node['name'])
  machine.write_file(action_handler, convergence_options[:client_rb_path], content, :ensure_dir => true)
end