vagrant-multi-hostsupdater 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/vagrant-multi-hostsupdater.rb +1 -1
- data/lib/vagrant-multi-hostsupdater/Action/CacheHosts.rb +2 -2
- data/lib/vagrant-multi-hostsupdater/Action/RemoveHosts.rb +3 -3
- data/lib/vagrant-multi-hostsupdater/Action/UpdateHosts.rb +5 -4
- data/lib/vagrant-multi-hostsupdater/HostsUpdater.rb +8 -8
- data/lib/vagrant-multi-hostsupdater/command.rb +1 -1
- data/lib/vagrant-multi-hostsupdater/config.rb +1 -1
- data/lib/vagrant-multi-hostsupdater/plugin.rb +11 -11
- data/lib/vagrant-multi-hostsupdater/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 525bc4999260ee40ed1d7f3126df0c71b82c9e4b
|
4
|
+
data.tar.gz: 14c86c1da0060ef2e67560229765c3c83ffe923c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 956dd624474534c5b6abe3eb81667637177445aec2691c601887c1d8bb273d5b16d3b849d9eb119016d523d39165be4b882fa34e0a8f3f0d5d6ff2bc1a7e0c48
|
7
|
+
data.tar.gz: fe7df8850a24b426612f8517c266b5cd32ab7d2c833af453e28af93bb5f45e62913e10359cd770a87f1cfa29834841196a1e2965eff47c9d5bae4f33f2c8e969
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Vagrant::
|
1
|
+
# Vagrant::MultiHostsUpdater
|
2
2
|
|
3
3
|
This plugin adds an entry to your /etc/hosts file on the host system.
|
4
4
|
|
@@ -7,7 +7,7 @@ On **up**, **resume** and **reload** commands, it tries to add the information,
|
|
7
7
|
On **halt** and **destroy**, those entries will be removed again.
|
8
8
|
By setting the remove\_on\_suspend option, you can have them removed on **suspend**, too:
|
9
9
|
|
10
|
-
config.
|
10
|
+
config.multihostsupdater.remove_on_suspend = true
|
11
11
|
|
12
12
|
|
13
13
|
|
@@ -25,7 +25,7 @@ At the moment, the only things you need, are the hostname and a :private_network
|
|
25
25
|
|
26
26
|
config.vm.network :private_network, ip: "192.168.3.10"
|
27
27
|
config.vm.hostname = "www.testing.de"
|
28
|
-
config.
|
28
|
+
config.multihostsupdater.aliases = ["alias.testing.de", "alias2.somedomain.com"]
|
29
29
|
|
30
30
|
This ip and the hostname will be used for the entry in the /etc/hosts file.
|
31
31
|
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module VagrantPlugins
|
2
|
-
module
|
2
|
+
module MultiHostsUpdater
|
3
3
|
module Action
|
4
4
|
class RemoveHosts
|
5
|
-
include
|
5
|
+
include MultiHostsUpdater
|
6
6
|
|
7
7
|
def initialize(app, env)
|
8
8
|
@app = app
|
@@ -13,7 +13,7 @@ module VagrantPlugins
|
|
13
13
|
def call(env)
|
14
14
|
machine_action = env[:machine_action]
|
15
15
|
if machine_action != :destroy || !@machine.id
|
16
|
-
if machine_action != :suspend || @machine.config.
|
16
|
+
if machine_action != :suspend || @machine.config.multihostsupdater.remove_on_suspend
|
17
17
|
@ui.info "Removing hosts"
|
18
18
|
removeHostEntries
|
19
19
|
else
|
@@ -1,9 +1,9 @@
|
|
1
|
-
require_relative "../
|
1
|
+
require_relative "../MultiHostsUpdater"
|
2
2
|
module VagrantPlugins
|
3
|
-
module
|
3
|
+
module MultiHostsUpdater
|
4
4
|
module Action
|
5
5
|
class UpdateHosts
|
6
|
-
include
|
6
|
+
include MultiHostsUpdater
|
7
7
|
|
8
8
|
|
9
9
|
def initialize(app, env)
|
@@ -13,8 +13,9 @@ module VagrantPlugins
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def call(env)
|
16
|
-
@ui.info "Checking for host entries"
|
16
|
+
@ui.info "Checking for host entries with env #{env}"
|
17
17
|
@app.call(env)
|
18
|
+
puts "about to call addhostentries"
|
18
19
|
addHostEntries()
|
19
20
|
end
|
20
21
|
|
@@ -15,15 +15,15 @@ module VagrantPlugins
|
|
15
15
|
|
16
16
|
# Get hostnames by specific IP.
|
17
17
|
# This option is only valid if a Hash is provided
|
18
|
-
# from the `config.
|
18
|
+
# from the `config.multihostsupdater.aliases` parameter
|
19
19
|
def getHostnames(ip=nil)
|
20
20
|
|
21
21
|
hostnames = []
|
22
|
-
if @machine.config.
|
23
|
-
hostnames = @machine.config.
|
22
|
+
if @machine.config.multihostsupdater.aliases.is_a?(Hash)
|
23
|
+
hostnames = @machine.config.multihostsupdater.aliases[ip] || hostnames
|
24
24
|
else
|
25
25
|
hostnames = Array(@machine.config.vm.hostname)
|
26
|
-
hostnames.concat(@machine.config.
|
26
|
+
hostnames.concat(@machine.config.multihostsupdater.aliases)
|
27
27
|
end
|
28
28
|
|
29
29
|
return hostnames
|
@@ -51,17 +51,17 @@ module VagrantPlugins
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def cacheHostEntries
|
54
|
-
@machine.config.
|
54
|
+
@machine.config.multihostsupdater.id = @machine.id
|
55
55
|
end
|
56
56
|
|
57
57
|
def removeHostEntries
|
58
|
-
if !@machine.id and !@machine.config.
|
58
|
+
if !@machine.id and !@machine.config.multihostsupdater.id
|
59
59
|
@ui.warn "No machine id, nothing removed from #@@hosts_path"
|
60
60
|
return
|
61
61
|
end
|
62
62
|
file = File.open(@@hosts_path, "rb")
|
63
63
|
hostsContents = file.read
|
64
|
-
uuid = @machine.id || @machine.config.
|
64
|
+
uuid = @machine.id || @machine.config.multihostsupdater.id
|
65
65
|
hashedId = Digest::MD5.hexdigest(uuid)
|
66
66
|
if hostsContents.match(/#{hashedId}/)
|
67
67
|
removeFromHosts
|
@@ -94,7 +94,7 @@ module VagrantPlugins
|
|
94
94
|
end
|
95
95
|
|
96
96
|
def removeFromHosts(options = {})
|
97
|
-
uuid = @machine.id || @machine.config.
|
97
|
+
uuid = @machine.id || @machine.config.multihostsupdater.id
|
98
98
|
hashedId = Digest::MD5.hexdigest(uuid)
|
99
99
|
if !File.writable?(@@hosts_path)
|
100
100
|
sudo(%Q(sed -i -e '/#{hashedId}/ d' #@@hosts_path))
|
@@ -3,48 +3,48 @@ require "vagrant-multi-hostsupdater/Action/CacheHosts"
|
|
3
3
|
require "vagrant-multi-hostsupdater/Action/RemoveHosts"
|
4
4
|
|
5
5
|
module VagrantPlugins
|
6
|
-
module
|
6
|
+
module MultiHostsUpdater
|
7
7
|
class Plugin < Vagrant.plugin('2')
|
8
|
-
name '
|
8
|
+
name 'MultiHostsUpdater'
|
9
9
|
description <<-DESC
|
10
10
|
This plugin manages the /etc/hosts file for the host machine. An entry is
|
11
11
|
created for the hostname attribute in the vm.config.
|
12
12
|
DESC
|
13
13
|
|
14
|
-
config(:
|
14
|
+
config(:multihostsupdater) do
|
15
15
|
require_relative 'config'
|
16
16
|
Config
|
17
17
|
end
|
18
18
|
|
19
|
-
action_hook(:
|
19
|
+
action_hook(:multihostsupdater, :machine_action_up) do |hook|
|
20
20
|
hook.append(Action::UpdateHosts)
|
21
21
|
end
|
22
22
|
|
23
|
-
action_hook(:
|
23
|
+
action_hook(:multihostsupdater, :machine_action_halt) do |hook|
|
24
24
|
hook.append(Action::RemoveHosts)
|
25
25
|
end
|
26
26
|
|
27
|
-
action_hook(:
|
27
|
+
action_hook(:multihostsupdater, :machine_action_suspend) do |hook|
|
28
28
|
hook.append(Action::RemoveHosts)
|
29
29
|
end
|
30
30
|
|
31
|
-
action_hook(:
|
31
|
+
action_hook(:multihostsupdater, :machine_action_destroy) do |hook|
|
32
32
|
hook.prepend(Action::CacheHosts)
|
33
33
|
end
|
34
34
|
|
35
|
-
action_hook(:
|
35
|
+
action_hook(:multihostsupdater, :machine_action_destroy) do |hook|
|
36
36
|
hook.append(Action::RemoveHosts)
|
37
37
|
end
|
38
38
|
|
39
|
-
action_hook(:
|
39
|
+
action_hook(:multihostsupdater, :machine_action_reload) do |hook|
|
40
40
|
hook.append(Action::UpdateHosts)
|
41
41
|
end
|
42
42
|
|
43
|
-
action_hook(:
|
43
|
+
action_hook(:multihostsupdater, :machine_action_resume) do |hook|
|
44
44
|
hook.append(Action::UpdateHosts)
|
45
45
|
end
|
46
46
|
|
47
|
-
command(:
|
47
|
+
command(:multihostsupdater) do
|
48
48
|
require_relative 'command'
|
49
49
|
Command
|
50
50
|
end
|