vagrant-hostsupdater 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 +4 -4
- data/.gitignore +1 -0
- data/LICENSE.txt +1 -1
- data/README.md +15 -1
- data/lib/vagrant-hostsupdater/Action/RemoveHosts.rb +6 -4
- data/lib/vagrant-hostsupdater/Action/UpdateHosts.rb +1 -1
- data/lib/vagrant-hostsupdater/HostsUpdater.rb +38 -17
- data/lib/vagrant-hostsupdater/plugin.rb +1 -2
- data/lib/vagrant-hostsupdater/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87d31195aa3a4364f58076f77881ec0d1a638622
|
4
|
+
data.tar.gz: d22efc10a7f881792bb32312d844cf6df7cf09b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0207909fa1335e2a9eab4d049b2a27d3e821667243280fe50dccc580f13c9325982dcc9323ccda52f0cc764b5a306e4f36a253e9ff81e8520ad6a58cb76d26b3
|
7
|
+
data.tar.gz: 9fbdd20e07f2c0c1c2f6b085915fed97acdbd7c7469f29d49fcc6b121640e2adf9a78e6a0ed0348390925a82fd84a7b86b770b87b22a3aa8a01b6b390b771c35
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -13,7 +13,7 @@ This plugin adds an entry to your /etc/hosts file on the host system.
|
|
13
13
|
On **up**, **resume** and **reload** commands, it tries to add the information, if its not already existant in your hosts file. If it needs to be added, you will be asked for an administrator password, since it uses sudo to edit the file.
|
14
14
|
|
15
15
|
On **halt**, **destroy**, and **suspend**, those entries will be removed again.
|
16
|
-
By setting the `config.hostsupdater.remove_on_suspend = false`, **suspend** will not remove them.
|
16
|
+
By setting the `config.hostsupdater.remove_on_suspend = false`, **suspend** and **halt** will not remove them.
|
17
17
|
|
18
18
|
|
19
19
|
## Installation
|
@@ -52,6 +52,14 @@ Example:
|
|
52
52
|
netmask: "255.255.240.0",
|
53
53
|
hostsupdater: "skip"
|
54
54
|
|
55
|
+
### Keeping Host Entries After Suspend/Halt
|
56
|
+
|
57
|
+
To keep your /etc/hosts file unchanged simply add the line below to your `VagrantFile`:
|
58
|
+
|
59
|
+
config.hostsupdater.resume_on_suspend = false
|
60
|
+
|
61
|
+
This disables vagrant-hostsupdater from running on **suspend** and **halt**.
|
62
|
+
|
55
63
|
|
56
64
|
## Passwordless sudo
|
57
65
|
|
@@ -88,6 +96,12 @@ vagrant plugin install vagrant-hostsupdater-*.gem
|
|
88
96
|
|
89
97
|
## Versions
|
90
98
|
|
99
|
+
### 1.0.2
|
100
|
+
* Feature: Added `remove_on_suspend` for `vagrant_halt` [#71](/../../issues/71)
|
101
|
+
* Feature: Skip entries if they already exist [#69](/../../issues/69)
|
102
|
+
* Bugfix: Fixing extra lines in /etc/hosts file [#87](/../../pull/87)
|
103
|
+
* Misc: Fix yellow text on UI [#39](/../../issues/39)
|
104
|
+
|
91
105
|
### 1.0.1
|
92
106
|
* Bugfix: Fixing `up` issue on initialize [#28](/../../issues/28)
|
93
107
|
|
@@ -14,10 +14,12 @@ module VagrantPlugins
|
|
14
14
|
machine_action = env[:machine_action]
|
15
15
|
if machine_action != :destroy || !@machine.id
|
16
16
|
if machine_action != :suspend || false != @machine.config.hostsupdater.remove_on_suspend
|
17
|
-
@
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
if machine_action != :halt || false != @machine.config.hostsupdater.remove_on_suspend
|
18
|
+
@ui.info "[vagrant-hostsupdater] Removing hosts"
|
19
|
+
removeHostEntries
|
20
|
+
else
|
21
|
+
@ui.info "[vagrant-hostsupdater] Removing hosts on suspend disabled"
|
22
|
+
end
|
21
23
|
end
|
22
24
|
end
|
23
25
|
@app.call(env)
|
@@ -10,7 +10,7 @@ module VagrantPlugins
|
|
10
10
|
ip = options[:ip] if (key == :private_network || key == :public_network) && options[:hostsupdater] != "skip"
|
11
11
|
ips.push(ip) if ip
|
12
12
|
if options[:hostsupdater] == 'skip'
|
13
|
-
@ui.info 'Skipping adding host entries (config.vm.network hostsupdater: "skip" is set)'
|
13
|
+
@ui.info '[vagrant-hostsupdater] Skipping adding host entries (config.vm.network hostsupdater: "skip" is set)'
|
14
14
|
end
|
15
15
|
end
|
16
16
|
return ips
|
@@ -33,11 +33,13 @@ module VagrantPlugins
|
|
33
33
|
name = @machine.name
|
34
34
|
entries = []
|
35
35
|
ips.each do |ip|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
if
|
40
|
-
@ui.info "
|
36
|
+
hostnames.each do |hostname|
|
37
|
+
entryPattern = hostEntryPattern(ip, hostname)
|
38
|
+
|
39
|
+
if hostsContents.match(/#{entryPattern}/)
|
40
|
+
@ui.info "[vagrant-hostsupdater] found entry for: #{ip} #{hostname}"
|
41
|
+
else
|
42
|
+
hostEntry = createHostEntry(ip, hostname, name, uuid)
|
41
43
|
entries.push(hostEntry)
|
42
44
|
end
|
43
45
|
end
|
@@ -51,7 +53,7 @@ module VagrantPlugins
|
|
51
53
|
|
52
54
|
def removeHostEntries
|
53
55
|
if !@machine.id and !@machine.config.hostsupdater.id
|
54
|
-
@ui.
|
56
|
+
@ui.info "[vagrant-hostsupdater] No machine id, nothing removed from #@@hosts_path"
|
55
57
|
return
|
56
58
|
end
|
57
59
|
file = File.open(@@hosts_path, "rb")
|
@@ -67,19 +69,30 @@ module VagrantPlugins
|
|
67
69
|
%Q(#{ip} #{hostnames.join(' ')} #{signature(name, uuid)})
|
68
70
|
end
|
69
71
|
|
70
|
-
def
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
72
|
+
def createHostEntry(ip, hostname, name, uuid = self.uuid)
|
73
|
+
%Q(#{ip} #{hostname} #{signature(name, uuid)})
|
74
|
+
end
|
75
|
+
|
76
|
+
# Create a regular expression that will match *any* entry describing the
|
77
|
+
# given IP/hostname pair. This is intentionally generic in order to
|
78
|
+
# recognize entries created by the end user.
|
79
|
+
def hostEntryPattern(ip, hostname)
|
80
|
+
Regexp.new('^\s*' + ip + '\s+' + hostname + '\s*(#.*)?$')
|
76
81
|
end
|
77
82
|
|
78
83
|
def addToHosts(entries)
|
79
84
|
return if entries.length == 0
|
80
|
-
content = entries.join("\n").strip
|
85
|
+
content = entries.join("\n").strip
|
86
|
+
|
87
|
+
@ui.info "[vagrant-hostsupdater] Writing the following entries to (#@@hosts_path)"
|
88
|
+
@ui.info "[vagrant-hostsupdater] " + entries.join("\n[vagrant-hostsupdater] ")
|
89
|
+
@ui.info "[vagrant-hostsupdater] This operation requires administrative access. You may " +
|
90
|
+
"skip it by manually adding equivalent entries to the hosts file."
|
81
91
|
if !File.writable_real?(@@hosts_path)
|
82
|
-
sudo(%Q(sh -c 'echo "#{content}" >> #@@hosts_path'))
|
92
|
+
if !sudo(%Q(sh -c 'echo "#{content}" >> #@@hosts_path'))
|
93
|
+
@ui.error "[vagrant-hostsupdater] Failed to add hosts, could not use sudo"
|
94
|
+
adviseOnSudo
|
95
|
+
end
|
83
96
|
else
|
84
97
|
content = "\n" + content
|
85
98
|
hostsFile = File.open(@@hosts_path, "a")
|
@@ -92,7 +105,10 @@ module VagrantPlugins
|
|
92
105
|
uuid = @machine.id || @machine.config.hostsupdater.id
|
93
106
|
hashedId = Digest::MD5.hexdigest(uuid)
|
94
107
|
if !File.writable_real?(@@hosts_path)
|
95
|
-
sudo(%Q(sed -i -e '/#{hashedId}/ d' #@@hosts_path))
|
108
|
+
if !sudo(%Q(sed -i -e '/#{hashedId}/ d' #@@hosts_path))
|
109
|
+
@ui.error "[vagrant-hostsupdater] Failed to remove hosts, could not use sudo"
|
110
|
+
adviseOnSudo
|
111
|
+
end
|
96
112
|
else
|
97
113
|
hosts = ""
|
98
114
|
File.open(@@hosts_path).each do |line|
|
@@ -116,9 +132,14 @@ module VagrantPlugins
|
|
116
132
|
if Vagrant::Util::Platform.windows?
|
117
133
|
`#{command}`
|
118
134
|
else
|
119
|
-
|
135
|
+
return system("sudo #{command}")
|
120
136
|
end
|
121
137
|
end
|
138
|
+
|
139
|
+
def adviseOnSudo
|
140
|
+
@ui.error "[vagrant-hostsupdater] Consider adding the following to your sudoers file:"
|
141
|
+
@ui.error "[vagrant-hostsupdater] https://github.com/cogitatio/vagrant-hostsupdater#passwordless-sudo"
|
142
|
+
end
|
122
143
|
end
|
123
144
|
end
|
124
145
|
end
|
@@ -17,8 +17,7 @@ module VagrantPlugins
|
|
17
17
|
end
|
18
18
|
|
19
19
|
action_hook(:hostsupdater, :machine_action_up) do |hook|
|
20
|
-
hook.
|
21
|
-
hook.after(Vagrant::Action::Builtin::SetHostname, Action::UpdateHosts)
|
20
|
+
hook.append(Action::UpdateHosts)
|
22
21
|
end
|
23
22
|
|
24
23
|
action_hook(:hostsupdater, :machine_action_provision) do |hook|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-hostsupdater
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Falk Kühnel
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-01-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|