vagrant-goodhosts 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d57ccc464161aae46b772cf48cebb81d5dd397a01910ef46cbb49f59da6018e6
4
- data.tar.gz: ae7c977400c970df2a0685f2ec5ffafa1c3c4276eabdd1c60e7c522874f4201d
3
+ metadata.gz: 2a413f4af6b28126f7bfa544c51fd1861d6809d3f2092ca512f4f3cb92b66a98
4
+ data.tar.gz: 278595e91fb77a7f0b1e9a439f21718c3c89c88d6cba2642cc15fc41f063c959
5
5
  SHA512:
6
- metadata.gz: 9aeeb25fd2974a73558f3380727b885038ff2a22a151ee216dbca37c47eddbd86cc07cacdd7ff1d7ab049a93b0b9316fae77b9231f95b153d2a81e534f8afddc
7
- data.tar.gz: 48e57ad4c315c39f75f454616b5aa2af6402988294f2d006df8448c1e48b919e4743ab64a28663c50c85cc5627d6dae6e608e3094fa3a9e6cfccd20f78368b6f
6
+ metadata.gz: e23da17547129d300c21c3c4850994ff34f936feb65cfb06d102cca35051ed679d22c535f4e7d0edb9019687b7816c9e755b64f4cef871c063aa00a7d2fa615a
7
+ data.tar.gz: db90290bfcfa853afc27f4993ab87cf0bafe81b2ad094888b1dafb83664cb3837847f6e814211b22676ede0f4ed3f24debfe3ba56490d8efdb4b7450c3ba9ac5
data/README.md CHANGED
@@ -87,7 +87,7 @@ If you understand the risks that go with supressing them, here's how to do it.
87
87
  ### Linux/OS X: Passwordless sudo
88
88
 
89
89
  To allow vagrant to automatically update the hosts file without asking for a sudo password, add one of the following snippets to a new sudoers file include, i.e. `sudo visudo -f /etc/sudoers.d/vagrant_goodhosts`.
90
- Change the cli path as printed in the vagrant output.
90
+ The command path is printed when there are errors with sudo.
91
91
 
92
92
  For Ubuntu and most Linux environments:
93
93
 
@@ -96,6 +96,8 @@ For Ubuntu and most Linux environments:
96
96
  For MacOS:
97
97
 
98
98
  %admin ALL=(root) NOPASSWD: [the-path]
99
+
100
+ Replace in both %sudo/%admin with the username it if it is not working for you.
99
101
 
100
102
  ### Windows: UAC Prompt
101
103
 
@@ -1,69 +1,66 @@
1
- require 'rbconfig'
2
- require 'open3'
1
+ require "rbconfig"
2
+ require "open3"
3
3
 
4
4
  module VagrantPlugins
5
5
  module GoodHosts
6
6
  module GoodHosts
7
-
8
7
  def getIps
9
8
  if Vagrant.has_plugin?("vagrant-hostsupdater")
10
- @ui.warn "[vagrant-goodhosts] Warning: The vagrant-hostsupdater plugin is installed, hostsupdater always adds the VM name even if the VagrantFile says not to. This shouldn't cause issues, but if it does, uninstall hostsupdater"
9
+ @ui.warn "[vagrant-goodhosts] Warning: The vagrant-hostsupdater plugin is installed, hostsupdater always adds the VM name even if the VagrantFile says not to. This shouldn't cause issues, but if it does, uninstall hostsupdater"
11
10
  end
12
-
11
+
13
12
  ips = []
14
13
 
15
- @machine.config.vm.networks.each do |network|
16
- key, options = network[0], network[1]
17
- ip = options[:ip] if (key == :private_network || key == :public_network) && options[:goodhosts] != "skip"
18
- ips.push(ip) if ip
19
- if options[:goodhosts] == 'skip'
20
- @ui.info '[vagrant-goodhosts] Skipping adding host entries (config.vm.network goodhosts: "skip" is set)'
21
- end
22
-
23
- @machine.config.vm.provider :hyperv do |v|
24
- timeout = @machine.provider_config.ip_address_timeout
25
- @ui.output("[vagrant-goodhosts] Waiting for the guest machine to report its IP address ( this might take some time, have patience )...")
26
- @ui.detail("Timeout: #{timeout} seconds")
27
-
28
- options = {
29
- vmm_server_address: @machine.provider_config.vmm_server_address,
30
- proxy_server_address: @machine.provider_config.proxy_server_address,
31
- timeout: timeout,
32
- machine: @machine
33
- }
34
- network = @machine.provider.driver.read_guest_ip(options)
35
- if network["ip"]
36
- ips.push( network["ip"] ) unless ips.include? network["ip"]
37
- end
14
+ @machine.config.vm.networks.each do |network|
15
+ key, options = network[0], network[1]
16
+ ip = options[:ip] if (key == :private_network || key == :public_network) && options[:goodhosts] != "skip"
17
+ ips.push(ip) if ip
18
+ if options[:goodhosts] == "skip"
19
+ @ui.info '[vagrant-goodhosts] Skipping adding host entries (config.vm.network goodhosts: "skip" is set)'
20
+ end
21
+
22
+ @machine.config.vm.provider :hyperv do |v|
23
+ timeout = @machine.provider_config.ip_address_timeout
24
+ @ui.output("[vagrant-goodhosts] Waiting for the guest machine to report its IP address ( this might take some time, have patience )...")
25
+ @ui.detail("Timeout: #{timeout} seconds")
26
+
27
+ options = {
28
+ vmm_server_address: @machine.provider_config.vmm_server_address,
29
+ proxy_server_address: @machine.provider_config.proxy_server_address,
30
+ timeout: timeout,
31
+ machine: @machine,
32
+ }
33
+ network = @machine.provider.driver.read_guest_ip(options)
34
+ if network["ip"]
35
+ ips.push(network["ip"]) unless ips.include? network["ip"]
38
36
  end
39
-
40
- return ips
37
+ end
38
+
39
+ return ips
41
40
  end
42
41
  end
43
-
42
+
44
43
  # https://stackoverflow.com/a/13586108/1902215
45
44
  def get_OS
46
- return os ||= (
47
- host_os = RbConfig::CONFIG['host_os']
48
- case host_os
49
- when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
50
- :'cli.exe'
51
- when /darwin|mac os/
52
- :'cli_osx'
53
- when /linux/
54
- :'cli'
55
- else
56
- raise Error::WebDriverError, "unknown os: #{host_os.inspect}"
57
- end
58
- )
45
+ return os ||= (host_os = RbConfig::CONFIG["host_os"]
46
+ case host_os
47
+ when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
48
+ :'cli.exe'
49
+ when /darwin|mac os/
50
+ :'cli_osx'
51
+ when /linux/
52
+ :'cli'
53
+ else
54
+ raise Error::WebDriverError, "unknown os: #{host_os.inspect}"
55
+ end)
59
56
  end
60
-
57
+
61
58
  def get_cli
62
- cli = get_OS
63
- path = File.expand_path(File.dirname(File.dirname(__FILE__))) + '/vagrant-goodhosts/bundle/'
64
- path = "#{path}#{cli}"
65
-
66
- return path
59
+ cli = get_OS
60
+ path = File.expand_path(File.dirname(File.dirname(__FILE__))) + "/vagrant-goodhosts/bundle/"
61
+ path = "#{path}#{cli}"
62
+
63
+ return path
67
64
  end
68
65
 
69
66
  # Get a hash of hostnames indexed by ip, e.g. { 'ip1': ['host1'], 'ip2': ['host2', 'host3'] }
@@ -96,67 +93,83 @@ module VagrantPlugins
96
93
  end
97
94
 
98
95
  def addHostEntries
99
- ips = getIps
100
- hostnames = getHostnames(ips)
101
96
  error = false
102
97
  errorText = ""
103
98
  cli = get_cli
104
- ips.each do |ip|
105
- hostnames[ip].each do |hostname|
106
- ip_address = ip
107
- if !ip_address.nil?
108
- @ui.info "[vagrant-goodhosts] - found entry for: #{ip_address} #{hostname}"
109
- if cli.include? ".exe"
110
- stdin, stdout, stderr, wait_thr = Open3.popen3(cli, "a", ip_address, hostname)
111
- else
112
- stdin, stdout, stderr, wait_thr = Open3.popen3('sudo', cli, "a", ip_address, hostname)
113
- end
114
- if !wait_thr.value.success?
115
- error = true
116
- errorText = stderr.read.strip
117
- end
118
- end
99
+ hostnames_by_ips = generateHostnamesByIps
100
+ hostnames_by_ips.each do |hostnames, ip_address|
101
+ if cli.include? ".exe"
102
+ stdin, stdout, stderr, wait_thr = Open3.popen3(cli, "a", ip_address, hostnames)
103
+ else
104
+ stdin, stdout, stderr, wait_thr = Open3.popen3("sudo", cli, "a", ip_address, hostnames)
105
+ end
106
+ if !wait_thr.value.success?
107
+ error = true
108
+ errorText = stderr.read.strip
119
109
  end
120
110
  end
121
111
  printReadme(error, errorText)
122
112
  end
123
113
 
124
114
  def removeHostEntries
125
- ips = getIps
126
- hostnames = getHostnames(ips)
127
115
  error = false
128
116
  errorText = ""
129
117
  cli = get_cli
130
- ips.each do |ip|
131
- hostnames[ip].each do |hostname|
132
- ip_address = ip
133
- if !ip_address.nil?
134
- @ui.info "[vagrant-goodhosts] - remove entry for: #{ip_address} #{hostname}"
135
- if cli.include? ".exe"
136
- stdin, stdout, stderr, wait_thr = Open3.popen3(cli, "r", ip_address, hostname)
137
- else
138
- stdin, stdout, stderr, wait_thr = Open3.popen3('sudo', cli, "r", ip_address, hostname)
139
- end
140
- if !wait_thr.value.success?
141
- error = true
142
- errorText = stderr.read.strip
143
- end
144
- end
118
+ hostnames_by_ips = generateHostnamesByIps
119
+ hostnames_by_ips.each do |hostnames, ip_address|
120
+ if cli.include? ".exe"
121
+ stdin, stdout, stderr, wait_thr = Open3.popen3(cli, "r", ip_address, hostnames)
122
+ else
123
+ stdin, stdout, stderr, wait_thr = Open3.popen3("sudo", cli, "r", ip_address, hostnames)
124
+ end
125
+ if !wait_thr.value.success?
126
+ error = true
127
+ errorText = stderr.read.strip
145
128
  end
146
129
  end
147
130
  printReadme(error, errorText)
148
131
  end
149
-
132
+
150
133
  def printReadme(error, errorText)
151
134
  if error
152
- cli = get_cli
153
- @ui.error "[vagrant-goodhosts] Issue executing goodhosts CLI: #{errorText}"
154
- @ui.error "[vagrant-goodhosts] Cli path: #{cli}"
135
+ cli = get_cli
136
+ @ui.error "[vagrant-goodhosts] Issue executing goodhosts CLI: #{errorText}"
137
+ @ui.error "[vagrant-goodhosts] Cli path: #{cli}"
138
+ if cli.include? ".exe"
139
+ @ui.error "[vagrant-goodhosts] Check the readme at https://github.com/goodhosts/vagrant#windows-uac-prompt"
140
+ exit
141
+ else
155
142
  @ui.error "[vagrant-goodhosts] Check the readme at https://github.com/goodhosts/vagrant#passwordless-sudo"
143
+ end
156
144
  end
157
-
158
145
  end
159
146
 
147
+ def generateHostnamesByIps()
148
+ hostnames_by_ips = []
149
+ ips = getIps
150
+ hostnames = getHostnames(ips)
151
+ if ips.count() > 1
152
+ ips.each do |ip|
153
+ ip_address = ip
154
+ hostnames[ip].each do |hostname|
155
+ if !ip_address.nil?
156
+ @ui.info "[vagrant-goodhosts] - remove entry for: #{ip_address} #{hostname}"
157
+ end
158
+ end
159
+ hostnames_by_ips = { ip_address => hostnames[ip].join(" ") }
160
+ end
161
+ else
162
+ ip_address = ips[0]
163
+ hostnames[ip_address].each do |hostname|
164
+ if !ip_address.nil?
165
+ @ui.info "[vagrant-goodhosts] - remove entry for: #{ip_address} #{hostname}"
166
+ end
167
+ end
168
+ hostnames_by_ips = { ip_address => hostnames[ip_address].join(" ") }
169
+ end
170
+
171
+ return hostnames_by_ips
172
+ end
160
173
  end
161
174
  end
162
- end
175
+ end
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module GoodHosts
3
- VERSION = '1.0.1'
3
+ VERSION = '1.0.2'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-goodhosts
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniele Scasciafratte
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-19 00:00:00.000000000 Z
11
+ date: 2020-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler