vagrant-hostsupdater 0.0.2
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 +7 -0
- data/.gitignore +17 -0
- data/Gemfile +50 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +3 -0
- data/lib/vagrant-hostsupdater.rb +11 -0
- data/lib/vagrant-hostsupdater/Action/RemoveHosts.rb +22 -0
- data/lib/vagrant-hostsupdater/Action/UpdateHosts.rb +24 -0
- data/lib/vagrant-hostsupdater/HostsUpdater.rb +89 -0
- data/lib/vagrant-hostsupdater/command.rb +30 -0
- data/lib/vagrant-hostsupdater/config.rb +11 -0
- data/lib/vagrant-hostsupdater/plugin.rb +44 -0
- data/lib/vagrant-hostsupdater/version.rb +5 -0
- data/vagrant-hostsupdater.gemspec +23 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA512:
|
3
|
+
data.tar.gz: 41d5f5dda99247f31cdfca83d319b2efc2dc5673fba3ed70b689da8eb509856a73b20f73945becd9a87749fe89548364d31ecd7b3e705f5e3f42bfc26e8f9c7e
|
4
|
+
metadata.gz: fbdae7cc3bff2600a7655198c1d8220009db57d54b0951b35dce7d30e4edc1bbf4a22bd4221c6432e58b989e46130ff2017e01a374e84ca92ab3258312201887
|
5
|
+
SHA1:
|
6
|
+
data.tar.gz: fc06b84167b3666201b9f7d78352b5e2daf08f90
|
7
|
+
metadata.gz: 7a2e5544226f6040c035bc0313786b848652fb7b
|
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
$:.unshift File.expand_path("../lib", __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "vagrant-hostsupdater"
|
5
|
+
s.version = 0.2
|
6
|
+
s.platform = Gem::Platform::RUBY
|
7
|
+
s.authors = "Falk Kühnel"
|
8
|
+
s.email = "fk@cogitatio.de"
|
9
|
+
s.homepage = "http://www.cogitatio.de"
|
10
|
+
s.summary = "Enables Vagrant to update hosts file on the host machine"
|
11
|
+
s.description = "Enables Vagrant to update hosts file on the host machine"
|
12
|
+
|
13
|
+
|
14
|
+
# s.add_development_dependency "rake"
|
15
|
+
|
16
|
+
# # The following block of code determines the files that should be included
|
17
|
+
# # in the gem. It does this by reading all the files in the directory where
|
18
|
+
# # this gemspec is, and parsing out the ignored files from the gitignore.
|
19
|
+
# # Note that the entire gitignore(5) syntax is not supported, specifically
|
20
|
+
# # the "!" syntax, but it should mostly work correctly.
|
21
|
+
# root_path = File.dirname(__FILE__)
|
22
|
+
# all_files = Dir.chdir(root_path) { Dir.glob("**/{*,.*}") }
|
23
|
+
# all_files.reject! { |file| [".", ".."].include?(File.basename(file)) }
|
24
|
+
# gitignore_path = File.join(root_path, ".gitignore")
|
25
|
+
# gitignore = File.readlines(gitignore_path)
|
26
|
+
# gitignore.map! { |line| line.chomp.strip }
|
27
|
+
# gitignore.reject! { |line| line.empty? || line =~ /^(#|!)/ }
|
28
|
+
|
29
|
+
# unignored_files = all_files.reject do |file|
|
30
|
+
# # Ignore any directories, the gemspec only cares about files
|
31
|
+
# next true if File.directory?(file)
|
32
|
+
|
33
|
+
# # Ignore any paths that match anything in the gitignore. We do
|
34
|
+
# # two tests here:
|
35
|
+
# #
|
36
|
+
# # - First, test to see if the entire path matches the gitignore.
|
37
|
+
# # - Second, match if the basename does, this makes it so that things
|
38
|
+
# # like '.DS_Store' will match sub-directories too (same behavior
|
39
|
+
# # as git).
|
40
|
+
# #
|
41
|
+
# gitignore.any? do |ignore|
|
42
|
+
# File.fnmatch(ignore, file, File::FNM_PATHNAME) ||
|
43
|
+
# File.fnmatch(ignore, File.basename(file), File::FNM_PATHNAME)
|
44
|
+
# end
|
45
|
+
# end
|
46
|
+
|
47
|
+
# s.files = unignored_files
|
48
|
+
# s.executables = unignored_files.map { |f| f[/^bin\/(.*)/, 1] }.compact
|
49
|
+
# s.require_path = 'lib'
|
50
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Falk Kühnel
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Vagrant::Hostsupdater
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'vagrant-hostsupdater'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install vagrant-hostsupdater
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module HostsUpdater
|
3
|
+
module Action
|
4
|
+
class RemoveHosts
|
5
|
+
include HostsUpdater
|
6
|
+
|
7
|
+
def initialize(app, env)
|
8
|
+
@app = app
|
9
|
+
@machine = env[:machine]
|
10
|
+
@ui = env[:ui]
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(env)
|
14
|
+
@ui.info "Removing hosts"
|
15
|
+
@app.call(env)
|
16
|
+
removeHostEntries
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative "../HostsUpdater"
|
2
|
+
module VagrantPlugins
|
3
|
+
module HostsUpdater
|
4
|
+
module Action
|
5
|
+
class UpdateHosts
|
6
|
+
include HostsUpdater
|
7
|
+
|
8
|
+
|
9
|
+
def initialize(app, env)
|
10
|
+
@app = app
|
11
|
+
@machine = env[:machine]
|
12
|
+
@ui = env[:ui]
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(env)
|
16
|
+
@ui.info "Checking for host entries"
|
17
|
+
@app.call(env)
|
18
|
+
addHostEntries()
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module HostsUpdater
|
3
|
+
module HostsUpdater
|
4
|
+
def test
|
5
|
+
puts "jawoll"
|
6
|
+
end
|
7
|
+
|
8
|
+
def getIps
|
9
|
+
ips = []
|
10
|
+
@machine.config.vm.networks.each do |network|
|
11
|
+
key, options = network[0], network[1]
|
12
|
+
ip = options[:ip] if key == :private_network
|
13
|
+
ips.push(ip) if ip
|
14
|
+
end
|
15
|
+
return ips
|
16
|
+
end
|
17
|
+
|
18
|
+
def getHostnames
|
19
|
+
hostnames = Array(@machine.config.vm.hostname)
|
20
|
+
return hostnames
|
21
|
+
end
|
22
|
+
|
23
|
+
def addHostEntries()
|
24
|
+
ips = getIps
|
25
|
+
hostnames = getHostnames
|
26
|
+
file = File.open("/etc/hosts", "rb")
|
27
|
+
hostsContents = file.read
|
28
|
+
uuid = @machine.id
|
29
|
+
name = @machine.name
|
30
|
+
entries = []
|
31
|
+
ips.each do |ip|
|
32
|
+
hostEntry = host_entry(ip, hostnames, name, uuid)
|
33
|
+
escapedEntry = Regexp.quote(hostEntry)
|
34
|
+
if !hostsContents.match(/#{escapedEntry}/)
|
35
|
+
entries.push(hostEntry)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
sudo(addToHosts(entries))
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
def removeHostEntries
|
43
|
+
file = File.open("/etc/hosts", "rb")
|
44
|
+
hostsContents = file.read
|
45
|
+
uuid = @machine.id
|
46
|
+
escapedId = Regexp.quote(uuid)
|
47
|
+
puts "#{uuid}"
|
48
|
+
puts "#{escapedId}"
|
49
|
+
if hostsContents.match(/#{escapedId}/)
|
50
|
+
puts "removing uids"
|
51
|
+
puts "#{removeFromHosts}"
|
52
|
+
sudo(removeFromHosts)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def host_entry(ip, hostnames, name, uuid = self.uuid)
|
57
|
+
%Q(#{ip} #{hostnames.join(' ')} #{signature(name, uuid)})
|
58
|
+
end
|
59
|
+
|
60
|
+
def addToHosts(entries)
|
61
|
+
return if entries.length == 0
|
62
|
+
hosts_path = '/etc/hosts'
|
63
|
+
content = entries.join("\n")
|
64
|
+
%Q(sh -c 'echo "#{content}" >>#{hosts_path}')
|
65
|
+
end
|
66
|
+
|
67
|
+
def removeFromHosts(options = {})
|
68
|
+
hosts_path = '/etc/hosts'
|
69
|
+
uuid = @machine.id
|
70
|
+
%Q(sed -e '/#{uuid}/ d' -ibak #{hosts_path})
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
def signature(name, uuid = self.uuid)
|
76
|
+
%Q(# VAGRANT: #{uuid} (#{name}))
|
77
|
+
end
|
78
|
+
|
79
|
+
def sudo(command)
|
80
|
+
return if !command
|
81
|
+
# if Util::Platform.windows?
|
82
|
+
# `#{command}`
|
83
|
+
# else
|
84
|
+
`sudo #{command}`
|
85
|
+
# end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module HostsUpdater
|
3
|
+
class Command < Vagrant.plugin('2', :command)
|
4
|
+
#include HostsFile
|
5
|
+
|
6
|
+
def execute
|
7
|
+
# options = {}
|
8
|
+
# opts = OptionParser.new do |o|
|
9
|
+
# o.banner = 'Usage: vagrant hostmanager [vm-name]'
|
10
|
+
# o.separator ''
|
11
|
+
|
12
|
+
# o.on('--provider provider', String,
|
13
|
+
# 'Update machines with the specific provider.') do |provider|
|
14
|
+
# options[:provider] = provider
|
15
|
+
# end
|
16
|
+
# end
|
17
|
+
|
18
|
+
# argv = parse_options(opts)
|
19
|
+
# options[:provider] ||= @env.default_provider
|
20
|
+
|
21
|
+
# generate(@env, options[:provider].to_sym)
|
22
|
+
|
23
|
+
# with_target_vms(argv, options) do |machine|
|
24
|
+
# update(machine)
|
25
|
+
# end
|
26
|
+
puts "ran command"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require "vagrant-hostsupdater/Action/UpdateHosts"
|
2
|
+
require "vagrant-hostsupdater/Action/RemoveHosts"
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module HostsUpdater
|
6
|
+
class Plugin < Vagrant.plugin('2')
|
7
|
+
name 'HostsUpdater'
|
8
|
+
description <<-DESC
|
9
|
+
This plugin manages the /etc/hosts file for the host machine. An entry is
|
10
|
+
created for the hostname attribute in the vm.config.
|
11
|
+
DESC
|
12
|
+
|
13
|
+
config(:hostsupdater) do
|
14
|
+
require_relative 'config'
|
15
|
+
Config
|
16
|
+
end
|
17
|
+
|
18
|
+
action_hook(:hostsupdater, :machine_action_up) do |hook|
|
19
|
+
hook.append(Action::UpdateHosts)
|
20
|
+
end
|
21
|
+
|
22
|
+
action_hook(:hostsupdater, :machine_action_halt) do |hook|
|
23
|
+
hook.append(Action::RemoveHosts)
|
24
|
+
end
|
25
|
+
|
26
|
+
action_hook(:hostsupdater, :machine_action_suspend) do |hook|
|
27
|
+
hook.append(Action::RemoveHosts)
|
28
|
+
end
|
29
|
+
|
30
|
+
action_hook(:hostsupdater, :machine_action_destroy) do |hook|
|
31
|
+
hook.prepend(Action::RemoveHosts)
|
32
|
+
end
|
33
|
+
|
34
|
+
action_hook(:hostsupdater, :machine_action_reload) do |hook|
|
35
|
+
hook.append(Action::UpdateHosts)
|
36
|
+
end
|
37
|
+
|
38
|
+
command(:hostsupdater) do
|
39
|
+
require_relative 'command'
|
40
|
+
Command
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'vagrant-hostsupdater/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "vagrant-hostsupdater"
|
8
|
+
spec.version = VagrantPlugins::HostsUpdater::VERSION
|
9
|
+
spec.authors = ["Falk Ku\314\210hnel"]
|
10
|
+
spec.email = ["fk@cogitatio.de"]
|
11
|
+
spec.description = %q{Enables Vagrant to update hosts file on the host machine}
|
12
|
+
spec.summary = %q{Enables Vagrant to update hosts file on the host machine}
|
13
|
+
spec.homepage = "http://www.cogitatio.de"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vagrant-hostsupdater
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- "Falk Ku\xCC\x88hnel"
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2013-04-30 00:00:00 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
prerelease: false
|
16
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ~>
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: "1.3"
|
21
|
+
name: bundler
|
22
|
+
type: :development
|
23
|
+
requirement: *id001
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
27
|
+
requirements:
|
28
|
+
- &id003
|
29
|
+
- ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: "0"
|
32
|
+
name: rake
|
33
|
+
type: :development
|
34
|
+
requirement: *id002
|
35
|
+
description: Enables Vagrant to update hosts file on the host machine
|
36
|
+
email:
|
37
|
+
- fk@cogitatio.de
|
38
|
+
executables: []
|
39
|
+
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files: []
|
43
|
+
|
44
|
+
files:
|
45
|
+
- .gitignore
|
46
|
+
- Gemfile
|
47
|
+
- LICENSE.txt
|
48
|
+
- README.md
|
49
|
+
- Rakefile
|
50
|
+
- lib/vagrant-hostsupdater.rb
|
51
|
+
- lib/vagrant-hostsupdater/Action/RemoveHosts.rb
|
52
|
+
- lib/vagrant-hostsupdater/Action/UpdateHosts.rb
|
53
|
+
- lib/vagrant-hostsupdater/HostsUpdater.rb
|
54
|
+
- lib/vagrant-hostsupdater/command.rb
|
55
|
+
- lib/vagrant-hostsupdater/config.rb
|
56
|
+
- lib/vagrant-hostsupdater/plugin.rb
|
57
|
+
- lib/vagrant-hostsupdater/version.rb
|
58
|
+
- vagrant-hostsupdater.gemspec
|
59
|
+
homepage: http://www.cogitatio.de
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
63
|
+
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- *id003
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- *id003
|
75
|
+
requirements: []
|
76
|
+
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 2.0.3
|
79
|
+
signing_key:
|
80
|
+
specification_version: 4
|
81
|
+
summary: Enables Vagrant to update hosts file on the host machine
|
82
|
+
test_files: []
|
83
|
+
|