vagrant-goodhosts 1.0.11 → 1.0.16
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 +4 -4
- data/README.md +4 -4
- data/lib/vagrant-goodhosts/Action/BaseAction.rb +45 -0
- data/lib/vagrant-goodhosts/Action/RemoveHosts.rb +11 -23
- data/lib/vagrant-goodhosts/Action/UpdateHosts.rb +4 -17
- data/lib/vagrant-goodhosts/GoodHosts.rb +22 -14
- data/lib/vagrant-goodhosts/config.rb +2 -1
- data/lib/vagrant-goodhosts/plugin.rb +4 -2
- data/lib/vagrant-goodhosts/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6843d62e56a2bd4b265a0b4854bcb69fba17c99b60515ad4bdb23ef1decf384b
|
4
|
+
data.tar.gz: dfb62145d87e3d1d3122a6777399d3fb41c620df68f762ed6284c3221066e72b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9476f2832c25de5c268f2bcbda6f243f784ed641143c8a5b26fd0511582e9cbd010ff99faa96f53084699c16970a9efb71964309914f4d4e4847dacae2392346
|
7
|
+
data.tar.gz: 583d8ccf7c2c5e77feed7980987facb0fe156e1325efd580d19c20518cea2141a4b80e6cb18d8f15a550f945099c9c37755c13dc703d44e72c60b14c30e75104
|
data/README.md
CHANGED
@@ -30,7 +30,7 @@ You currently only need the `hostname` and a `:private_network` network with a f
|
|
30
30
|
|
31
31
|
```ruby
|
32
32
|
config.vm.network :private_network, ip: "192.168.3.10"
|
33
|
-
config.vm.hostname = "www.testing.de"
|
33
|
+
config.vm.hostname = "www.testing.de" # This is not used by the plugin
|
34
34
|
config.goodhosts.aliases = ["alias.testing.de", "alias2.somedomain.com"]
|
35
35
|
```
|
36
36
|
|
@@ -80,13 +80,13 @@ This disables `vagrant-goodhosts` from running on **suspend** and **halt**.
|
|
80
80
|
|
81
81
|
### Disable file hosts clean
|
82
82
|
|
83
|
-
If you
|
83
|
+
If you want `/etc/hosts` file cleaned add in your `VagrantFile`:
|
84
84
|
|
85
85
|
```ruby
|
86
|
-
config.goodhosts.disable_clean =
|
86
|
+
config.goodhosts.disable_clean = false
|
87
87
|
```
|
88
88
|
|
89
|
-
This
|
89
|
+
This enable `vagrant-goodhosts` from running the clean command in every call.
|
90
90
|
|
91
91
|
## Suppressing prompts for elevating privileges
|
92
92
|
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module GoodHosts
|
3
|
+
module Action
|
4
|
+
class BaseAction
|
5
|
+
include GoodHosts
|
6
|
+
|
7
|
+
# Vagrant 2.2.14 has changed the hooks execution policy so they
|
8
|
+
# started to be triggered more than once (a lot actually) which
|
9
|
+
# is non-performant and floody. With this static property, we
|
10
|
+
# control the executions and allowing just one.
|
11
|
+
#
|
12
|
+
# - https://github.com/hashicorp/vagrant/issues/12070#issuecomment-732271918
|
13
|
+
# - https://github.com/hashicorp/vagrant/compare/v2.2.13..v2.2.14#diff-4d1af7c67af870f20d303c3c43634084bab8acc101055b2e53ddc0d07f6f64dcL176-L180
|
14
|
+
# - https://github.com/goodhosts/vagrant/issues/25
|
15
|
+
@@completed = {}
|
16
|
+
|
17
|
+
def initialize(app, env)
|
18
|
+
@app = app
|
19
|
+
@machine = env[:machine]
|
20
|
+
@ui = env[:ui]
|
21
|
+
end
|
22
|
+
|
23
|
+
def call(env)
|
24
|
+
# Check whether the plugin has been executed for a particular
|
25
|
+
# VM as it may happen that a single Vagrantfile defines multiple
|
26
|
+
# machines and having a static flag will result in a plugin being
|
27
|
+
# executed just once.
|
28
|
+
# https://github.com/goodhosts/vagrant/issues/30
|
29
|
+
@@completed[@machine.name] = [] unless @@completed.key?(@machine.name)
|
30
|
+
unless @@completed[@machine.name].include? self.class.name
|
31
|
+
run(env)
|
32
|
+
@@completed[@machine.name] << self.class.name
|
33
|
+
end
|
34
|
+
|
35
|
+
@app.call(env)
|
36
|
+
end
|
37
|
+
|
38
|
+
def run(env)
|
39
|
+
raise NotImplementedError.new("Must be implemented!")
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -1,32 +1,20 @@
|
|
1
1
|
module VagrantPlugins
|
2
2
|
module GoodHosts
|
3
3
|
module Action
|
4
|
-
class RemoveHosts
|
5
|
-
include GoodHosts
|
6
|
-
@@updated = false
|
4
|
+
class RemoveHosts < BaseAction
|
7
5
|
|
8
|
-
def
|
9
|
-
@app = app
|
10
|
-
@machine = env[:machine]
|
11
|
-
@ui = env[:ui]
|
12
|
-
end
|
13
|
-
|
14
|
-
def call(env)
|
6
|
+
def run(env)
|
15
7
|
machine_action = env[:machine_action]
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
8
|
+
|
9
|
+
return unless @machine.id
|
10
|
+
return unless [:destroy, :halt, :suspend].include? machine_action
|
11
|
+
|
12
|
+
if ([:halt, :suspend].include? machine_action) && (false == @machine.config.goodhosts.remove_on_suspend)
|
13
|
+
@ui.info "[vagrant-goodhosts] Removing hosts on suspend disabled"
|
14
|
+
else
|
15
|
+
@ui.info "[vagrant-goodhosts] Removing hosts"
|
16
|
+
removeHostEntries
|
28
17
|
end
|
29
|
-
@app.call(env)
|
30
18
|
end
|
31
19
|
|
32
20
|
end
|
@@ -1,24 +1,11 @@
|
|
1
|
-
require_relative "../GoodHosts"
|
2
1
|
module VagrantPlugins
|
3
2
|
module GoodHosts
|
4
3
|
module Action
|
5
|
-
class UpdateHosts
|
6
|
-
include GoodHosts
|
7
|
-
@@updated = false
|
4
|
+
class UpdateHosts < BaseAction
|
8
5
|
|
9
|
-
def
|
10
|
-
@
|
11
|
-
|
12
|
-
@ui = env[:ui]
|
13
|
-
end
|
14
|
-
|
15
|
-
def call(env)
|
16
|
-
unless @@updated
|
17
|
-
@@updated = true
|
18
|
-
@ui.info "[vagrant-goodhosts] Checking for host entries"
|
19
|
-
addHostEntries()
|
20
|
-
end
|
21
|
-
@app.call(env)
|
6
|
+
def run(env)
|
7
|
+
@ui.info "[vagrant-goodhosts] Checking for host entries"
|
8
|
+
addHostEntries()
|
22
9
|
end
|
23
10
|
|
24
11
|
end
|
@@ -7,6 +7,11 @@ module VagrantPlugins
|
|
7
7
|
def getIps
|
8
8
|
ips = []
|
9
9
|
|
10
|
+
if @machine.config.vm.networks.length == 0
|
11
|
+
@ui.error("[vagrant-goodhosts] No ip address found for this virtual machine")
|
12
|
+
exit
|
13
|
+
end
|
14
|
+
|
10
15
|
@machine.config.vm.networks.each do |network|
|
11
16
|
key, options = network[0], network[1]
|
12
17
|
ip = options[:ip] if (key == :private_network || key == :public_network) && options[:goodhosts] != "skip"
|
@@ -80,7 +85,7 @@ module VagrantPlugins
|
|
80
85
|
return hostnames
|
81
86
|
end
|
82
87
|
|
83
|
-
def
|
88
|
+
def disableClean(ip_address)
|
84
89
|
unless ip_address.nil?
|
85
90
|
return @machine.config.goodhosts.disable_clean
|
86
91
|
end
|
@@ -100,17 +105,18 @@ module VagrantPlugins
|
|
100
105
|
@ui.error "[vagrant-goodhosts] Error adding some hosts, no IP was provided for the following hostnames: #{hostnames}"
|
101
106
|
next
|
102
107
|
end
|
103
|
-
clean = ''
|
104
108
|
if cli.include? ".exe"
|
105
|
-
|
106
|
-
|
109
|
+
clean = "\"--clean\","
|
110
|
+
if disableClean(ip_address)
|
111
|
+
clean = ''
|
107
112
|
end
|
108
113
|
stdin, stdout, stderr, wait_thr = Open3.popen3("powershell", "-Command", "Start-Process '#{cli}' -ArgumentList \"add\",#{clean}\"#{ip_address}\",\"#{hostnames}\" -Verb RunAs")
|
109
114
|
else
|
110
|
-
|
111
|
-
|
115
|
+
clean = "--clean"
|
116
|
+
if disableClean(ip_address)
|
117
|
+
clean = ''
|
112
118
|
end
|
113
|
-
stdin, stdout, stderr, wait_thr = Open3.popen3("sudo #{cli} add #{clean} #{ip_address} #{hostnames}")
|
119
|
+
stdin, stdout, stderr, wait_thr = Open3.popen3("sudo '#{cli}' add #{clean} #{ip_address} #{hostnames}")
|
114
120
|
end
|
115
121
|
if !wait_thr.value.success?
|
116
122
|
error = true
|
@@ -134,15 +140,17 @@ module VagrantPlugins
|
|
134
140
|
next
|
135
141
|
end
|
136
142
|
if cli.include? ".exe"
|
137
|
-
|
138
|
-
|
143
|
+
clean = "\"--clean\","
|
144
|
+
if disableClean(ip_address)
|
145
|
+
clean = ''
|
139
146
|
end
|
140
147
|
stdin, stdout, stderr, wait_thr = Open3.popen3("powershell", "-Command", "Start-Process '#{cli}' -ArgumentList \"remove\",#{clean}\"#{ip_address}\",\"#{hostnames}\" -Verb RunAs")
|
141
148
|
else
|
142
|
-
|
143
|
-
|
149
|
+
clean = "\"--clean\","
|
150
|
+
if disableClean(ip_address)
|
151
|
+
clean = ''
|
144
152
|
end
|
145
|
-
stdin, stdout, stderr, wait_thr = Open3.popen3("sudo #{cli} remove #{clean} #{ip_address} #{hostnames}")
|
153
|
+
stdin, stdout, stderr, wait_thr = Open3.popen3("sudo '#{cli}' remove #{clean} #{ip_address} #{hostnames}")
|
146
154
|
end
|
147
155
|
if !wait_thr.value.success?
|
148
156
|
error = true
|
@@ -176,7 +184,7 @@ module VagrantPlugins
|
|
176
184
|
if ips.count() > 1
|
177
185
|
ips.each do |ip|
|
178
186
|
ip_address = ip
|
179
|
-
if hostnames[ip].count() >
|
187
|
+
if hostnames[ip].count() > 0
|
180
188
|
hostnames[ip].each do |hostname|
|
181
189
|
if !ip_address.nil?
|
182
190
|
@ui.info "[vagrant-goodhosts] - found entry for: #{ip_address} #{hostname}"
|
@@ -187,7 +195,7 @@ module VagrantPlugins
|
|
187
195
|
end
|
188
196
|
else
|
189
197
|
ip_address = ips[0]
|
190
|
-
if hostnames[ip_address].count() >
|
198
|
+
if hostnames[ip_address].count() > 0
|
191
199
|
hostnames[ip_address].each do |hostname|
|
192
200
|
if !ip_address.nil?
|
193
201
|
@ui.info "[vagrant-goodhosts] - found entry for: #{ip_address} #{hostname}"
|
@@ -1,5 +1,7 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require_relative "GoodHosts"
|
2
|
+
require_relative "Action/BaseAction"
|
3
|
+
require_relative "Action/UpdateHosts"
|
4
|
+
require_relative "Action/RemoveHosts"
|
3
5
|
|
4
6
|
module VagrantPlugins
|
5
7
|
module GoodHosts
|
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.16
|
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-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -51,6 +51,7 @@ files:
|
|
51
51
|
- README.md
|
52
52
|
- Rakefile
|
53
53
|
- lib/vagrant-goodhosts.rb
|
54
|
+
- lib/vagrant-goodhosts/Action/BaseAction.rb
|
54
55
|
- lib/vagrant-goodhosts/Action/RemoveHosts.rb
|
55
56
|
- lib/vagrant-goodhosts/Action/UpdateHosts.rb
|
56
57
|
- lib/vagrant-goodhosts/GoodHosts.rb
|