Module: Vagrant::Butcher::Helpers::Connection

Includes:
KeyFiles
Included in:
Action::Cleanup
Defined in:
lib/vagrant-butcher/helpers/connection.rb

Instance Method Summary collapse

Methods included from KeyFiles

#cache_dir, #cleanup_cache_dir, #client_key_path, #copy_guest_key, #create_cache_dir, #grab_key_from_guest, #guest_key_path, #key_filename

Instance Method Details

#cleanup(env) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/vagrant-butcher/helpers/connection.rb', line 43

def cleanup(env)
  if chef_client?(env)
    setup_connection(env)
    %w(node client).each { |resource| delete_resource(resource, env) }
    cleanup_cache_dir(env)
  end
end

#delete_resource(resource, env) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/vagrant-butcher/helpers/connection.rb', line 32

def delete_resource(resource, env)
  begin
    @conn.send(resource.to_sym).delete(victim(env))
    ui(env).success "Chef #{resource} '#{victim(env)}' successfully butchered from the server..."
  rescue Exception => e
    ui(env).warn "Could not butcher #{resource} #{victim(env)}: #{e.message}"
    @failed_deletions ||= []
    @failed_deletions << resource
  end
end

#setup_connection(env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/vagrant-butcher/helpers/connection.rb', line 12

def setup_connection(env)
  begin
    @conn = ::Ridley.new(
      server_url: chef_provisioner(env).chef_server_url,
      client_name: client_name(env),
      client_key: client_key_path(env),
      ssl: {
        verify: butcher_config(env).verify_ssl
      },
      retries: butcher_config(env).retries,
      retry_interval: butcher_config(env).retry_interval,
      proxy: butcher_config(env).proxy
    )
  rescue Ridley::Errors::ClientKeyFileNotFoundOrInvalid
    ui(env).error "Chef client key not found at #{client_key_path(env)}"
  rescue Exception => e
    ui(env).error "Could not connect to Chef Server: #{e}"
  end
end