vagrant-goodhosts 1.0.9 → 1.0.14
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 +9 -0
- data/lib/vagrant-goodhosts/Action/BaseAction.rb +44 -0
- data/lib/vagrant-goodhosts/Action/RemoveHosts.rb +7 -19
- data/lib/vagrant-goodhosts/Action/UpdateHosts.rb +4 -17
- data/lib/vagrant-goodhosts/GoodHosts.rb +35 -9
- data/lib/vagrant-goodhosts/config.rb +5 -0
- data/lib/vagrant-goodhosts/plugin.rb +4 -2
- data/lib/vagrant-goodhosts/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7318e82f1a00cbc634eb59ada30fc0dac4faaec430d03cf14a18cbbab3ad47ca
|
4
|
+
data.tar.gz: b803523ef62f3678f41d326c274b797a45fac3506965c4b3faf35f2a5d6e80dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 853bc371c5cb4b11ee893c4c9d36a16f8b23a304e1b96622eb4d92798d4aeca37c1fa8e9d9888706f336613cd2b4871d2afa338ee38f07dc6e793358195e7e40
|
7
|
+
data.tar.gz: 71c07e6cb107e9bb4f28f22169deb39ae0b8656c242cb3fa559375f6f35f04ceff66f37ee978957afc248b2bb1470d9244d64fca96a12647e6a2240275759c31
|
data/README.md
CHANGED
@@ -78,6 +78,15 @@ config.goodhosts.remove_on_suspend = false
|
|
78
78
|
|
79
79
|
This disables `vagrant-goodhosts` from running on **suspend** and **halt**.
|
80
80
|
|
81
|
+
### Disable file hosts clean
|
82
|
+
|
83
|
+
If you want `/etc/hosts` file cleaned add in your `VagrantFile`:
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
config.goodhosts.disable_clean = false
|
87
|
+
```
|
88
|
+
|
89
|
+
This enable `vagrant-goodhosts` from running the clean command in every call.
|
81
90
|
|
82
91
|
## Suppressing prompts for elevating privileges
|
83
92
|
|
@@ -0,0 +1,44 @@
|
|
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
|
+
if not @@completed.key?(@machine.name)
|
30
|
+
run(env)
|
31
|
+
@@completed[@machine.name] = true
|
32
|
+
end
|
33
|
+
|
34
|
+
@app.call(env)
|
35
|
+
end
|
36
|
+
|
37
|
+
def run(env)
|
38
|
+
raise NotImplementedError.new("Must be implemented!")
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
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
8
|
if machine_action != :destroy || !@machine.id
|
17
9
|
if machine_action != :suspend || false != @machine.config.goodhosts.remove_on_suspend
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
else
|
24
|
-
@ui.info "[vagrant-goodhosts] Removing hosts on suspend disabled"
|
25
|
-
end
|
10
|
+
if machine_action != :halt || false != @machine.config.goodhosts.remove_on_suspend
|
11
|
+
@ui.info "[vagrant-goodhosts] Removing hosts"
|
12
|
+
removeHostEntries
|
13
|
+
else
|
14
|
+
@ui.info "[vagrant-goodhosts] Removing hosts on suspend disabled"
|
26
15
|
end
|
27
16
|
end
|
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"
|
@@ -79,25 +84,39 @@ module VagrantPlugins
|
|
79
84
|
|
80
85
|
return hostnames
|
81
86
|
end
|
87
|
+
|
88
|
+
def disableClean(ip_address)
|
89
|
+
unless ip_address.nil?
|
90
|
+
return @machine.config.goodhosts.disable_clean
|
91
|
+
end
|
92
|
+
return true
|
93
|
+
end
|
82
94
|
|
83
95
|
def addHostEntries
|
84
96
|
error = false
|
85
97
|
errorText = ""
|
86
98
|
cli = get_cli
|
87
99
|
hostnames_by_ips = generateHostnamesByIps
|
88
|
-
|
89
|
-
return if hostnames_by_ips.
|
100
|
+
|
101
|
+
return if not hostnames_by_ips.any?
|
90
102
|
|
91
103
|
hostnames_by_ips.each do |ip_address, hostnames|
|
92
|
-
next if hostnames.empty?
|
93
104
|
if ip_address.nil?
|
94
105
|
@ui.error "[vagrant-goodhosts] Error adding some hosts, no IP was provided for the following hostnames: #{hostnames}"
|
95
106
|
next
|
96
107
|
end
|
97
108
|
if cli.include? ".exe"
|
98
|
-
|
109
|
+
clean = "\"--clean\","
|
110
|
+
if disableClean(ip_address)
|
111
|
+
clean = ''
|
112
|
+
end
|
113
|
+
stdin, stdout, stderr, wait_thr = Open3.popen3("powershell", "-Command", "Start-Process '#{cli}' -ArgumentList \"add\",#{clean}\"#{ip_address}\",\"#{hostnames}\" -Verb RunAs")
|
99
114
|
else
|
100
|
-
|
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}")
|
101
120
|
end
|
102
121
|
if !wait_thr.value.success?
|
103
122
|
error = true
|
@@ -113,18 +132,25 @@ module VagrantPlugins
|
|
113
132
|
cli = get_cli
|
114
133
|
hostnames_by_ips = generateHostnamesByIps
|
115
134
|
|
116
|
-
return if hostnames_by_ips.
|
135
|
+
return if not hostnames_by_ips.any?
|
117
136
|
|
118
137
|
hostnames_by_ips.each do |ip_address, hostnames|
|
119
|
-
next if hostnames.empty?
|
120
138
|
if ip_address.nil?
|
121
139
|
@ui.error "[vagrant-goodhosts] Error adding some hosts, no IP was provided for the following hostnames: #{hostnames}"
|
122
140
|
next
|
123
141
|
end
|
124
142
|
if cli.include? ".exe"
|
125
|
-
|
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 \"remove\",#{clean}\"#{ip_address}\",\"#{hostnames}\" -Verb RunAs")
|
126
148
|
else
|
127
|
-
|
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}")
|
128
154
|
end
|
129
155
|
if !wait_thr.value.success?
|
130
156
|
error = true
|
@@ -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.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniele Scasciafratte
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-06 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
|
@@ -81,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
82
|
- !ruby/object:Gem::Version
|
82
83
|
version: '0'
|
83
84
|
requirements: []
|
84
|
-
rubygems_version: 3.2.
|
85
|
+
rubygems_version: 3.2.5
|
85
86
|
signing_key:
|
86
87
|
specification_version: 4
|
87
88
|
summary: Enables Vagrant to update hosts file on the host machine with goodhosts
|