vagrant-butcher 2.1.2 → 2.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4b46329a612f8d0f161712048c32fba14802b03c
4
- data.tar.gz: 0ab3292af71617e4ae15f0c55fb15a9f3a9888dc
3
+ metadata.gz: 179d7410197d7530eec83448494a0b51944d3b16
4
+ data.tar.gz: 9807b4d078972eacf729e064651e3056e4b9b940
5
5
  SHA512:
6
- metadata.gz: 158685b6ce6ecd797885b083e49e910183f96dd174680124d21b31de63b0281ecb19c292b7d65e65df0c8d318c970c24cdade2902a2d9bfeec1f42f0415348d7
7
- data.tar.gz: a3270d329466138996e5fa3c87761e7a0b2fd35d33e8cc6ddfd03d80148e325b31803a9644687b68aa634d46870a70872326fb182a088e469ccf3d6e8bea7c6a
6
+ metadata.gz: a2319cc363933b06ef5bb69529b4c0fcfca61a8523a1256357a49f0d0467ff6082c84708bc813260425c1a59f88d245491f59b7cd31ded7a29b8ea7471224d39
7
+ data.tar.gz: 76f86e961f9e835d0572e837494f75067b46c84d720a06b1b129de09cd601a025887fbf7a7e44ca3a89c31f5fff3900aedc25527ef0f0569a1fb42de0f27dce9
@@ -3,7 +3,7 @@ module Vagrant
3
3
  class Config < ::Vagrant.plugin('2', :config)
4
4
  attr_accessor :enabled
5
5
  attr_accessor :guest_key_path
6
- attr_accessor :cache_dir
6
+ attr_reader :cache_dir
7
7
  attr_accessor :verify_ssl
8
8
  attr_accessor :retries
9
9
  attr_accessor :retry_interval
@@ -15,7 +15,7 @@ module Vagrant
15
15
  super
16
16
  @enabled = UNSET_VALUE
17
17
  @guest_key_path = UNSET_VALUE
18
- @cache_dir = UNSET_VALUE
18
+ @cache_dir = ".vagrant/butcher"
19
19
  @verify_ssl = UNSET_VALUE
20
20
  @retries = UNSET_VALUE
21
21
  @retry_interval = UNSET_VALUE
@@ -24,14 +24,9 @@ module Vagrant
24
24
  @client_key = UNSET_VALUE
25
25
  end
26
26
 
27
- def cache_dir=(value)
28
- @cache_dir = File.expand_path(value)
29
- end
30
-
31
27
  def finalize!
32
28
  @enabled = true if @enabled == UNSET_VALUE
33
29
  @guest_key_path = '/etc/chef/client.pem' if @guest_key_path == UNSET_VALUE
34
- @cache_dir = File.expand_path ".vagrant/butcher" if @cache_dir == UNSET_VALUE
35
30
  @verify_ssl = true if @verify_ssl == UNSET_VALUE
36
31
  @retries = 0 if @retries == UNSET_VALUE
37
32
  @retry_interval = 0 if @retry_interval == UNSET_VALUE
@@ -12,6 +12,10 @@ module Vagrant
12
12
  @machine ||= env[:machine]
13
13
  end
14
14
 
15
+ def root_path(env)
16
+ @root_path ||= env[:root_path]
17
+ end
18
+
15
19
  end
16
20
  end
17
21
  end
@@ -10,26 +10,23 @@ module Vagrant
10
10
  include ::Vagrant::Butcher::Helpers::KeyFiles
11
11
 
12
12
  def setup_connection(env)
13
- unless @conn
14
- begin
15
- @conn = ::Ridley.new(
16
- server_url: chef_provisioner(env).chef_server_url,
17
- client_name: client_name(env),
18
- client_key: client_key(env),
19
- ssl: {
20
- verify: butcher_config(env).verify_ssl
21
- },
22
- retries: butcher_config(env).retries,
23
- retry_interval: butcher_config(env).retry_interval,
24
- proxy: butcher_config(env).proxy
25
- )
26
- rescue Ridley::Errors::ClientKeyFileNotFoundOrInvalid
27
- ui(env).error "Chef client key not found at #{client_key(env)}"
28
- rescue Exception => e
29
- ui(env).error "Could not connect to Chef Server: #{e}"
30
- end
13
+ begin
14
+ @conn = ::Ridley.new(
15
+ server_url: chef_provisioner(env).chef_server_url,
16
+ client_name: client_name(env),
17
+ client_key: client_key_path(env),
18
+ ssl: {
19
+ verify: butcher_config(env).verify_ssl
20
+ },
21
+ retries: butcher_config(env).retries,
22
+ retry_interval: butcher_config(env).retry_interval,
23
+ proxy: butcher_config(env).proxy
24
+ )
25
+ rescue Ridley::Errors::ClientKeyFileNotFoundOrInvalid
26
+ ui(env).error "Chef client key not found at #{client_key_path(env)}"
27
+ rescue Exception => e
28
+ ui(env).error "Could not connect to Chef Server: #{e}"
31
29
  end
32
- @conn
33
30
  end
34
31
 
35
32
  def delete_resource(resource, env)
@@ -6,53 +6,19 @@ module Vagrant
6
6
  module KeyFiles
7
7
 
8
8
  def cache_dir(env)
9
- @cache_dir ||= butcher_config(env).cache_dir
10
- end
11
-
12
- def cache_dir_mapping(env)
13
- unless @cache_dir_mapping
14
- # Grab all enabled synced_folders
15
- synced_folders = vm_config(env).synced_folders.values.find_all { |f| !f[:disabled] }
16
-
17
- # Expand the hostpath of each folder
18
- synced_folders.each { |f| f[:hostpath] = File.expand_path(f[:hostpath]) }
19
-
20
- # Select the folder wherein the cache_dir is contained
21
- cache_dir_mappings = synced_folders.select { |f| cache_dir(env) =~ /^#{f[:hostpath]}/ }
22
- @cache_dir_mapping = cache_dir_mappings.first if cache_dir_mappings.any?
23
- end
24
- @cache_dir_mapping
25
- end
26
-
27
- def guest_cache_dir(env)
28
- unless @guest_cache_dir
29
- if cache_dir_mapping(env)
30
- # Return the path to the cache dir inside the VM
31
- @guest_cache_dir = cache_dir(env).gsub(cache_dir_mapping(env)[:hostpath], cache_dir_mapping(env)[:guestpath])
32
- ui(env).info "Guest cache dir at #{@guest_cache_dir}"
33
- else
34
- ui(env).error "We couldn't find a synced folder to access the cache dir on the guest."
35
- ui(env).error "Did you disable the /vagrant folder or set a butcher.cache_path that isn't shared with the guest?"
36
- raise ::Vagrant::Butcher::Errors::NoSyncedFolder
37
- end
38
- end
39
- @guest_cache_dir
9
+ @cache_dir ||= File.expand_path(File.join(root_path(env), butcher_config(env).cache_dir))
40
10
  end
41
11
 
42
12
  def guest_key_path(env)
43
13
  @guest_key_path ||= butcher_config(env).guest_key_path
44
14
  end
45
15
 
46
- def guest_key_filename(env)
47
- @guest_key ||= "#{env[:machine].name}-client.pem"
48
- end
49
-
50
- def guest_cache_key_path(env)
51
- @guest_cache_key_path ||= "#{guest_cache_dir(env)}/#{guest_key_filename(env)}"
16
+ def key_filename(env)
17
+ @key_filename ||= "#{env[:machine].name}-client.pem"
52
18
  end
53
19
 
54
- def client_key(env)
55
- @client_key ||= butcher_config(env).client_key || "#{cache_dir(env)}/#{guest_key_filename(env)}"
20
+ def client_key_path(env)
21
+ @client_key_path ||= butcher_config(env).client_key || "#{cache_dir(env)}/#{key_filename(env)}"
56
22
  end
57
23
 
58
24
  def create_cache_dir(env)
@@ -62,35 +28,31 @@ module Vagrant
62
28
  end
63
29
  end
64
30
 
65
- def copy_key_file(env)
31
+ def grab_key_from_guest(env)
66
32
  create_cache_dir(env)
67
33
 
68
- begin
69
- machine(env).communicate.execute "mkdir -p `dirname #{guest_cache_key_path(env)}` ; cp #{guest_key_path(env)} #{guest_cache_key_path(env)}", :sudo => true
70
- ui(env).info "Copied #{guest_key_path(env)} to #{guest_cache_key_path(env)}"
71
- rescue Exception => e
72
- ui(env).error "Failed to copy #{guest_key_path(env)} to #{guest_cache_key_path(env)}"
73
- ui(env).error e
74
- raise ::Vagrant::Butcher::Errors::KeyCopyFailure
34
+ machine(env).communicate.execute("cat #{guest_key_path(env)}", sudo: true) do |type,data|
35
+ File.open("#{cache_dir(env)}/#{key_filename(env)}", "w") { |f| f << data } if type == :stdout
75
36
  end
37
+
38
+ ui(env).info "Saved client key to #{cache_dir(env)}/#{key_filename(env)}"
76
39
  end
77
40
 
78
41
  def cleanup_cache_dir(env)
79
42
  unless @failed_deletions
80
- key_file = "#{cache_dir(env)}/#{guest_key_filename(env)}"
43
+ key_file = "#{cache_dir(env)}/#{key_filename(env)}"
81
44
  File.delete(key_file) if File.exists?(key_file)
82
45
  Dir.delete(cache_dir(env)) if (Dir.entries(cache_dir(env)) - %w{ . .. }).empty?
83
46
  else
84
- ui(env).warn "#{@failed_deletions} not butchered from the Chef Server. Client key was left at #{client_key(env)}"
47
+ ui(env).warn "#{@failed_deletions} not butchered from the Chef Server. Client key was left at #{client_key_path(env)}"
85
48
  end
86
49
  end
87
50
 
88
51
  def copy_guest_key(env)
89
52
  begin
90
- guest_cache_dir(env)
91
- copy_key_file(env)
53
+ grab_key_from_guest(env)
92
54
  rescue ::Vagrant::Errors::VagrantError => e
93
- ui(env).error "Failed to copy Chef client key from the guest: #{e.class}"
55
+ ui(env).error "Failed to create #{cache_dir(env)}/#{key_filename(env)}: #{e.class} - #{e}"
94
56
  end
95
57
  end
96
58
 
@@ -1,5 +1,5 @@
1
1
  module Vagrant
2
2
  module Butcher
3
- VERSION = "2.1.2"
3
+ VERSION = "2.1.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-butcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cassiano Leal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-10 00:00:00.000000000 Z
11
+ date: 2013-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ridley