vagrant-goodhosts 1.0.17 → 1.0.18
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74e9466d2e64e39de992c9940235deb31e8d64fd4e17e92d8b271392306dcabf
|
4
|
+
data.tar.gz: 918fb30d3de3daf04492cd8850d5cd1fc5bb2187f9a985f048b401301c527409
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 396c9ad919d3abaea678b2042f57a9ef02dac89d4212ceb5e18887c5be190ae86a3112fa28664fe6e7483fcf6f9e969eda012d891a4d828622b6fc15b671a050
|
7
|
+
data.tar.gz: f1d14ef933bfe527f6d0297300abf1cc3ed9a87f542b1ac5dc0ff017c71a52b32203984e1c04d37988fdbbe1d4f99343255f9ced3dd3a750ec1ded7b06870231
|
@@ -12,7 +12,6 @@ module VagrantPlugins
|
|
12
12
|
if ([:halt, :suspend].include? machine_action) && (false == @machine.config.goodhosts.remove_on_suspend)
|
13
13
|
@ui.info "[vagrant-goodhosts] Removing hosts on suspend disabled"
|
14
14
|
else
|
15
|
-
@ui.info "[vagrant-goodhosts] Removing hosts"
|
16
15
|
removeHostEntries
|
17
16
|
end
|
18
17
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require "rbconfig"
|
2
2
|
require "open3"
|
3
|
+
require "resolv"
|
3
4
|
|
4
5
|
module VagrantPlugins
|
5
6
|
module GoodHosts
|
@@ -8,17 +9,17 @@ module VagrantPlugins
|
|
8
9
|
ips = []
|
9
10
|
|
10
11
|
if @machine.config.vm.networks.length == 0
|
11
|
-
@ui.error("[vagrant-goodhosts] No
|
12
|
-
|
12
|
+
@ui.error("[vagrant-goodhosts] No networks are available yet for this virtual machine to add IP/hosts for")
|
13
|
+
return ips
|
13
14
|
end
|
14
|
-
|
15
|
+
|
15
16
|
@machine.config.vm.networks.each do |network|
|
16
17
|
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
18
|
if options[:goodhosts] == "skip"
|
20
19
|
@ui.info '[vagrant-goodhosts] Skipped adding host entries (config.vm.network goodhosts: "skip" is set)'
|
21
20
|
end
|
21
|
+
ip = options[:ip] if (key == :private_network || key == :public_network) && options[:goodhosts] != "skip"
|
22
|
+
ips.push(ip) if ip
|
22
23
|
|
23
24
|
@machine.config.vm.provider :hyperv do |v|
|
24
25
|
timeout = @machine.provider_config.ip_address_timeout
|
@@ -37,7 +38,6 @@ module VagrantPlugins
|
|
37
38
|
end
|
38
39
|
end
|
39
40
|
|
40
|
-
|
41
41
|
end
|
42
42
|
return ips
|
43
43
|
end
|
@@ -45,16 +45,16 @@ module VagrantPlugins
|
|
45
45
|
# https://stackoverflow.com/a/13586108/1902215
|
46
46
|
def get_os_binary
|
47
47
|
return os ||= (host_os = RbConfig::CONFIG["host_os"]
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
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
58
|
end
|
59
59
|
|
60
60
|
def get_cli
|
@@ -84,7 +84,7 @@ module VagrantPlugins
|
|
84
84
|
|
85
85
|
return hostnames
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
def disableClean(ip_address)
|
89
89
|
unless ip_address.nil?
|
90
90
|
return @machine.config.goodhosts.disable_clean
|
@@ -97,27 +97,22 @@ module VagrantPlugins
|
|
97
97
|
errorText = ""
|
98
98
|
cli = get_cli
|
99
99
|
hostnames_by_ips = generateHostnamesByIps
|
100
|
-
|
100
|
+
|
101
101
|
return if not hostnames_by_ips.any?
|
102
102
|
|
103
|
+
@ui.info "[vagrant-goodhosts] Checking for host entries"
|
104
|
+
|
103
105
|
hostnames_by_ips.each do |ip_address, hostnames|
|
104
106
|
if ip_address.nil?
|
105
107
|
@ui.error "[vagrant-goodhosts] Error adding some hosts, no IP was provided for the following hostnames: #{hostnames}"
|
106
108
|
next
|
107
109
|
end
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
else
|
115
|
-
clean = "--clean"
|
116
|
-
if disableClean(ip_address)
|
117
|
-
clean = ''
|
118
|
-
end
|
119
|
-
stdin, stdout, stderr, wait_thr = Open3.popen3("sudo '#{cli}' add #{clean} #{ip_address} #{hostnames}")
|
120
|
-
end
|
110
|
+
|
111
|
+
# filter out the hosts we've already added
|
112
|
+
hosts_to_add = check_hostnames_to_add( ip_address, hostnames)
|
113
|
+
next if not hosts_to_add.any?
|
114
|
+
|
115
|
+
stdin, stdout, stderr, wait_thr = add_goodhost_entries(ip_address, hosts_to_add)
|
121
116
|
if !wait_thr.value.success?
|
122
117
|
error = true
|
123
118
|
errorText = stderr.read.strip
|
@@ -126,6 +121,40 @@ module VagrantPlugins
|
|
126
121
|
printReadme(error, errorText)
|
127
122
|
end
|
128
123
|
|
124
|
+
def check_hostnames_to_add(ip_address, hostnames)
|
125
|
+
hostnames_to_add = Array.new
|
126
|
+
|
127
|
+
# check which hostnames actually need adding
|
128
|
+
hostnames.each do |hostname|
|
129
|
+
begin
|
130
|
+
address = Resolv.getaddress(hostname)
|
131
|
+
if address != ip_address
|
132
|
+
hostnames_to_add.append( hostname )
|
133
|
+
end
|
134
|
+
rescue => exception
|
135
|
+
hostnames_to_add.append(hostname)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
return hostnames_to_add
|
139
|
+
end
|
140
|
+
|
141
|
+
def add_goodhost_entries(ip_address, hostnames)
|
142
|
+
if cli.include? ".exe"
|
143
|
+
clean = "\"--clean\","
|
144
|
+
if disableClean(ip_address)
|
145
|
+
clean = ''
|
146
|
+
end
|
147
|
+
stdin, stdout, stderr, wait_thr = Open3.popen3("powershell", "-Command", "Start-Process '#{cli}' -ArgumentList \"add\",#{clean}\"#{ip_address}\",\"#{hostnames}\" -Verb RunAs")
|
148
|
+
else
|
149
|
+
clean = "--clean"
|
150
|
+
if disableClean(ip_address)
|
151
|
+
clean = ''
|
152
|
+
end
|
153
|
+
stdin, stdout, stderr, wait_thr = Open3.popen3("sudo '#{cli}' add #{clean} #{ip_address} #{hostnames}")
|
154
|
+
end
|
155
|
+
return stdin, stdout, stderr, wait_thr
|
156
|
+
end
|
157
|
+
|
129
158
|
def removeHostEntries
|
130
159
|
error = false
|
131
160
|
errorText = ""
|
@@ -134,24 +163,15 @@ module VagrantPlugins
|
|
134
163
|
|
135
164
|
return if not hostnames_by_ips.any?
|
136
165
|
|
166
|
+
@ui.info "[vagrant-goodhosts] Removing hosts"
|
167
|
+
|
137
168
|
hostnames_by_ips.each do |ip_address, hostnames|
|
138
169
|
if ip_address.nil?
|
139
170
|
@ui.error "[vagrant-goodhosts] Error adding some hosts, no IP was provided for the following hostnames: #{hostnames}"
|
140
171
|
next
|
141
172
|
end
|
142
|
-
|
143
|
-
|
144
|
-
if disableClean(ip_address)
|
145
|
-
clean = ''
|
146
|
-
end
|
147
|
-
stdin, stdout, stderr, wait_thr = Open3.popen3("powershell", "-Command", "Start-Process '#{cli}' -ArgumentList \"remove\",#{clean}\"#{ip_address}\",\"#{hostnames}\" -Verb RunAs")
|
148
|
-
else
|
149
|
-
clean = "\"--clean\","
|
150
|
-
if disableClean(ip_address)
|
151
|
-
clean = ''
|
152
|
-
end
|
153
|
-
stdin, stdout, stderr, wait_thr = Open3.popen3("sudo '#{cli}' remove #{clean} #{ip_address} #{hostnames}")
|
154
|
-
end
|
173
|
+
|
174
|
+
stdin, stdout, stderr, wait_thr = remove_goodhost_entries(ip_address, hostnames)
|
155
175
|
if !wait_thr.value.success?
|
156
176
|
error = true
|
157
177
|
errorText = stderr.read.strip
|
@@ -160,6 +180,23 @@ module VagrantPlugins
|
|
160
180
|
printReadme(error, errorText)
|
161
181
|
end
|
162
182
|
|
183
|
+
def remove_goodhost_entries(ip_address, hostnames)
|
184
|
+
if cli.include? ".exe"
|
185
|
+
clean = "\"--clean\","
|
186
|
+
if disableClean(ip_address)
|
187
|
+
clean = ''
|
188
|
+
end
|
189
|
+
stdin, stdout, stderr, wait_thr = Open3.popen3("powershell", "-Command", "Start-Process '#{cli}' -ArgumentList \"remove\",#{clean}\"#{ip_address}\",\"#{hostnames}\" -Verb RunAs")
|
190
|
+
else
|
191
|
+
clean = "\"--clean\","
|
192
|
+
if disableClean(ip_address)
|
193
|
+
clean = ''
|
194
|
+
end
|
195
|
+
stdin, stdout, stderr, wait_thr = Open3.popen3("sudo '#{cli}' remove #{clean} #{ip_address} #{hostnames}")
|
196
|
+
end
|
197
|
+
return stdin, stdout, stderr, wait_thr
|
198
|
+
end
|
199
|
+
|
163
200
|
def printReadme(error, errorText)
|
164
201
|
if error
|
165
202
|
cli = get_cli
|
@@ -21,6 +21,10 @@ module VagrantPlugins
|
|
21
21
|
hook.append(Action::UpdateHosts)
|
22
22
|
end
|
23
23
|
|
24
|
+
action_hook(:goodhosts, :machine_action_boot) do |hook|
|
25
|
+
hook.append(Action::UpdateHosts)
|
26
|
+
end
|
27
|
+
|
24
28
|
action_hook(:goodhosts, :machine_action_provision) do |hook|
|
25
29
|
hook.before(Vagrant::Action::Builtin::Provision, Action::UpdateHosts)
|
26
30
|
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.
|
4
|
+
version: 1.0.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniele Scasciafratte
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-10-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -82,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
84
|
requirements: []
|
85
|
-
rubygems_version: 3.2.
|
85
|
+
rubygems_version: 3.2.27
|
86
86
|
signing_key:
|
87
87
|
specification_version: 4
|
88
88
|
summary: Enables Vagrant to update hosts file on the host machine with goodhosts
|