Class: ChefMetal::ConvergenceStrategy::PrecreateChefObjects

Inherits:
ChefMetal::ConvergenceStrategy show all
Defined in:
lib/chef_metal/convergence_strategy/precreate_chef_objects.rb

Direct Known Subclasses

InstallCached, InstallMsi, InstallSh

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ChefMetal::ConvergenceStrategy

#converge

Constructor Details

#initialize(options = {}) ⇒ PrecreateChefObjects

Returns a new instance of PrecreateChefObjects.



8
9
10
11
12
# File 'lib/chef_metal/convergence_strategy/precreate_chef_objects.rb', line 8

def initialize(options = {})
  super
  @client_rb_path = options[:client_rb_path]
  @client_pem_path = options[:client_pem_path]
end

Instance Attribute Details

#client_pem_pathObject (readonly)

Returns the value of attribute client_pem_path.



15
16
17
# File 'lib/chef_metal/convergence_strategy/precreate_chef_objects.rb', line 15

def client_pem_path
  @client_pem_path
end

#client_rb_pathObject (readonly)

Returns the value of attribute client_rb_path.



14
15
16
# File 'lib/chef_metal/convergence_strategy/precreate_chef_objects.rb', line 14

def client_rb_path
  @client_rb_path
end

Instance Method Details

#cleanup_convergence(action_handler, node) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/chef_metal/convergence_strategy/precreate_chef_objects.rb', line 32

def cleanup_convergence(action_handler, node)
  ChefMetal.inline_resource(action_handler) do
    chef_node node['name'] do
      action :delete
    end
    chef_client node['name'] do
      action :delete
    end
  end
end

#setup_convergence(action_handler, machine, machine_resource) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/chef_metal/convergence_strategy/precreate_chef_objects.rb', line 17

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

  # If the chef server lives on localhost, tunnel the port through to the guest
  chef_server_url = machine_resource.chef_server[:chef_server_url]
  chef_server_url = machine.make_url_available_to_remote(chef_server_url)

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