vagrant-hostentriess 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # A sample Gemfile
2
+ source "https://rubygems.org"
3
+
4
+ gemspec
5
+
6
+ # gem "rails"
7
+
8
+ group :development do
9
+ gem 'vagrant', :git => 'https://github.com/mitchellh/vagrant.git'
10
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,41 @@
1
+ GIT
2
+ remote: https://github.com/mitchellh/vagrant.git
3
+ revision: 4f563e3be6d927b814ad7f3a9d3069259b841eac
4
+ specs:
5
+ vagrant (1.2.3.dev)
6
+ childprocess (~> 0.3.7)
7
+ erubis (~> 2.7.0)
8
+ i18n (~> 0.6.0)
9
+ json (>= 1.5.1, < 1.8.0)
10
+ log4r (~> 1.1.9)
11
+ net-scp (~> 1.1.0)
12
+ net-ssh (~> 2.6.6)
13
+
14
+ PATH
15
+ remote: .
16
+ specs:
17
+ vagrant-hostentriess (0.5.0)
18
+
19
+ GEM
20
+ remote: https://rubygems.org/
21
+ specs:
22
+ childprocess (0.3.9)
23
+ ffi (~> 1.0, >= 1.0.11)
24
+ erubis (2.7.0)
25
+ ffi (1.8.1)
26
+ i18n (0.6.4)
27
+ json (1.7.7)
28
+ log4r (1.1.10)
29
+ net-scp (1.1.0)
30
+ net-ssh (>= 2.6.5)
31
+ net-ssh (2.6.7)
32
+ rake (10.0.4)
33
+
34
+ PLATFORMS
35
+ ruby
36
+
37
+ DEPENDENCIES
38
+ bundler
39
+ rake
40
+ vagrant!
41
+ vagrant-hostentriess!
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ vagrant-hosts
2
+ =============
3
+
4
+ A Vagrant 1.2-compatible plugin for managing host file entries on hosts and guests
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ Bundler::GemHelper.install_tasks
data/Vagrantfile ADDED
@@ -0,0 +1,114 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ Vagrant.require_plugin('vagrant-hosts')
5
+
6
+ Vagrant.configure("2") do |config|
7
+ # All Vagrant configuration is done here. The most common configuration
8
+ # options are documented and commented below. For a complete reference,
9
+ # please see the online documentation at vagrantup.com.
10
+
11
+ # Every Vagrant virtual environment requires a box to build off of.
12
+ config.vm.box = "precise64"
13
+
14
+ # The url from where the 'config.vm.box' box will be fetched if it
15
+ # doesn't already exist on the user's system.
16
+ config.vm.box_url = "http://vagrantup.com/boxes/precise64.box"
17
+
18
+ # Create a forwarded port mapping which allows access to a specific port
19
+ # within the machine from a port on the host machine. In the example below,
20
+ # accessing "localhost:8080" will access port 80 on the guest machine.
21
+ # config.vm.network :forwarded_port, guest: 80, host: 8080
22
+
23
+ # Create a private network, which allows host-only access to the machine
24
+ # using a specific IP.
25
+ # config.vm.network :private_network, ip: "192.168.33.10"
26
+
27
+ # Create a public network, which generally matched to bridged network.
28
+ # Bridged networks make the machine appear as another physical device on
29
+ # your network.
30
+ # config.vm.network :public_network
31
+
32
+ # Share an additional folder to the guest VM. The first argument is
33
+ # the path on the host to the actual folder. The second argument is
34
+ # the path on the guest to mount the folder. And the optional third
35
+ # argument is a set of non-required options.
36
+ # config.vm.synced_folder "../data", "/vagrant_data"
37
+
38
+ # Provider-specific configuration so you can fine-tune various
39
+ # backing providers for Vagrant. These expose provider-specific options.
40
+ # Example for VirtualBox:
41
+ #
42
+ config.vm.hostname = "test1.test.vagrantup.local"
43
+ # config.vm.provider :virtualbox do |vb|
44
+ # # Don't boot with headless mode
45
+ # vb.gui = true
46
+ #
47
+ # # Use VBoxManage to customize the VM. For example to change memory:
48
+ # vb.customize ["modifyvm", :id, "--memory", "1024"]
49
+ # end
50
+ #
51
+ # View the documentation for the provider you're using for more
52
+ # information on available options.
53
+
54
+ # Enable provisioning with Puppet stand alone. Puppet manifests
55
+ # are contained in a directory path relative to this Vagrantfile.
56
+ # You will need to create the manifests directory and a manifest in
57
+ # the file base.pp in the manifests_path directory.
58
+ #
59
+ # An example Puppet manifest to provision the message of the day:
60
+ #
61
+ # # group { "puppet":
62
+ # # ensure => "present",
63
+ # # }
64
+ # #
65
+ # # File { owner => 0, group => 0, mode => 0644 }
66
+ # #
67
+ # # file { '/etc/motd':
68
+ # # content => "Welcome to your Vagrant-built virtual machine!
69
+ # # Managed by Puppet.\n"
70
+ # # }
71
+ #
72
+ # config.vm.provision :puppet do |puppet|
73
+ # puppet.manifests_path = "manifests"
74
+ # puppet.manifest_file = "init.pp"
75
+ # end
76
+
77
+ # Enable provisioning with chef solo, specifying a cookbooks path, roles
78
+ # path, and data_bags path (all relative to this Vagrantfile), and adding
79
+ # some recipes and/or roles.
80
+ #
81
+ # config.vm.provision :chef_solo do |chef|
82
+ # chef.cookbooks_path = "../my-recipes/cookbooks"
83
+ # chef.roles_path = "../my-recipes/roles"
84
+ # chef.data_bags_path = "../my-recipes/data_bags"
85
+ # chef.add_recipe "mysql"
86
+ # chef.add_role "web"
87
+ #
88
+ # # You may also specify custom JSON attributes:
89
+ # chef.json = { :mysql_password => "foo" }
90
+ # end
91
+
92
+ # Enable provisioning with chef server, specifying the chef server URL,
93
+ # and the path to the validation key (relative to this Vagrantfile).
94
+ #
95
+ # The Opscode Platform uses HTTPS. Substitute your organization for
96
+ # ORGNAME in the URL and validation key.
97
+ #
98
+ # If you have your own Chef Server, use the appropriate URL, which may be
99
+ # HTTP instead of HTTPS depending on your configuration. Also change the
100
+ # validation key to validation.pem.
101
+ #
102
+ # config.vm.provision :chef_client do |chef|
103
+ # chef.chef_server_url = "https://api.opscode.com/organizations/ORGNAME"
104
+ # chef.validation_key_path = "ORGNAME-validator.pem"
105
+ # end
106
+ #
107
+ # If you're using the Opscode platform, your validator client is
108
+ # ORGNAME-validator, replacing ORGNAME with your organization name.
109
+ #
110
+ # If you have your own Chef Server, the default validation client name is
111
+ # chef-validator, unless you changed the configuration.
112
+ #
113
+ # chef.validation_client_name = "ORGNAME-validator"
114
+ end
@@ -0,0 +1,38 @@
1
+ require 'pathname'
2
+
3
+ require 'vagrant-hosts/plugin'
4
+
5
+ module VagrantPlugins
6
+ module Hosts
7
+
8
+ autoload :Action, 'vagrant-hosts/action'
9
+ # This sets up our log level to be whatever VAGRANT_LOG is.
10
+ def self.setup_logging
11
+ require "log4r"
12
+
13
+ level = nil
14
+ begin
15
+ level = Log4r.const_get(ENV["VAGRANT_LOG"].upcase)
16
+ rescue NameError
17
+ # This means that the logging constant wasn't found,
18
+ # which is fine. We just keep `level` as `nil`. But
19
+ # we tell the user.
20
+ level = nil
21
+ end
22
+
23
+ # Some constants, such as "true" resolve to booleans, so the
24
+ # above error checking doesn't catch it. This will check to make
25
+ # sure that the log level is an integer, as Log4r requires.
26
+ level = nil if !level.is_a?(Integer)
27
+
28
+ # Set the logging level on all "vagrant" namespaced
29
+ # logs as long as we have a valid level.
30
+ if level
31
+ logger = Log4r::Logger.new("vagrant_aws")
32
+ logger.outputters = Log4r::Outputter.stderr
33
+ logger.level = level
34
+ logger = nil
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,24 @@
1
+ module VagrantPlugins
2
+ module Hosts
3
+ module Action
4
+ autoload :RemoveHostsEntry, 'vagrant-hosts/action/remove_hosts_entry'
5
+ autoload :UpdateHostsEntry, 'vagrant-hosts/action/update_hosts_entry'
6
+
7
+ class << self
8
+ def update_hosts_entry
9
+ #@update_hosts_entry ||= ::
10
+ Vagrant::Action::Builder.new.tap do |b|
11
+ b.use VagrantPlugins::Hosts::Action::UpdateHostsEntry
12
+ end
13
+ end
14
+
15
+ def remove_hosts_entry
16
+ @remove_hosts_entry ||= ::Vagrant::Action::Builder.new.tap do |b|
17
+ b.use VagrantPlugins::Hosts::Action::RemoveHostsEntry
18
+ end
19
+ end
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,27 @@
1
+ module VagrantPlugins
2
+ module Hosts
3
+ module Action
4
+ class RemoveHostsEntry
5
+ def initialize(app, env)
6
+ @app = app
7
+ @logger = Log4r::Logger.new("VagrantPlugins::Hosts")
8
+ end
9
+
10
+ def call(env)
11
+ env[:host].remove_hosts_entry(env[:machine].config.vm.hostname)
12
+ env[:machine].env.active_machines.each do |machine|
13
+ if !machine.guest.capability?(:remove_hosts_entry)
14
+ @logger.warn "Unsupported machine #{machine.config.name}"
15
+ next
16
+ end
17
+ env[:machine].env.active_machines.each do |m|
18
+ m_hostname = m.config.hostname
19
+ machine.guest.capability(:remove_hosts_entry, m_hostname)
20
+ end
21
+ end
22
+ return @app.call(env)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,33 @@
1
+ require 'log4r'
2
+
3
+ module VagrantPlugins
4
+ module Hosts
5
+ module Action
6
+ class UpdateHostsEntry
7
+ def initialize(app, env)
8
+ @app = app
9
+ @logger = Log4r::Logger.new("VagrantPlugins::Hosts")
10
+ end
11
+
12
+ def call(env)
13
+ env[:host].update_hosts_entry(env[:machine].guest.capability(:read_ip_address), env[:machine].config.vm.hostname)
14
+ env[:machine].env.active_machines.each do |machine|
15
+ m = env[:machine].env.machine(machine[0], machine[1])
16
+ if !m.guest.capability?(:update_hosts_entry)
17
+ @logger.warn "Unsupported machine #{machine.config.name}"
18
+ next
19
+ end
20
+ env[:machine].env.active_machines.each do |machine2|
21
+ m2 = env[:machine].env.machine(machine2[0], machine2[1])
22
+ m2_ip = m2.guest.capability(:read_ip_address)
23
+ m2_hostname = m2.config.vm.hostname
24
+ env[:ui].info "Adding IP: #{m2_ip} -> Hostname: #{m2_hostname}"
25
+ m.guest.capability(:update_hosts_entry, m2_ip, m2_hostname)
26
+ end
27
+ end
28
+ return @app.call(env)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module Hosts
3
+ module GuestCapability
4
+ module Linux
5
+ module RemoveHostsEntry
6
+ def self.remove_hosts_entry(machine, name)
7
+ machine.communicate.tap do |comm|
8
+ comm.sudo("cat /etc/hosts | grep -v '#{name} \#VAGRANTHOSTS$' >>/etc/hosts.tmp">)
9
+ comm.sudo("mv /etc/hosts.tmp /etc/hosts")
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+ module VagrantPlugins
2
+ module Hosts
3
+ module GuestCapability
4
+ module Linux
5
+ module UpdateHostsEntry
6
+ def self.update_hosts_entry(machine, ip, name)
7
+ machine.communicate.tap do |comm|
8
+ comm.sudo("cat /etc/hosts | grep -v '#{name} \#VAGRANTHOSTS$' >>/etc/hosts.tmp")
9
+ comm.sudo("mv /etc/hosts.tmp /etc/hosts")
10
+ comm.sudo("echo '#{ip} #{name} \#VAGRANTHOSTS' >>/etc/hosts")
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,37 @@
1
+ require 'vagrant'
2
+ require 'vagrant/util/platform'
3
+
4
+ module VagrantPlugins
5
+ module Hosts
6
+ module BSD
7
+ class Host < Vagrant.plugin("2", :host)
8
+ include Vagrant::Util
9
+
10
+ def self.match?
11
+ Vagrant::Util::Platform.darwin? || Vagrant::Util::Platform.bsd?
12
+ end
13
+
14
+ def self.precedence
15
+ # Set a lower precedence, since we're supposed to override
16
+ # Vagrant's built-in BSD Host, but don't implement everything
17
+ 3
18
+ end
19
+
20
+ def initialize(*args)
21
+ super
22
+ end
23
+
24
+ def update_hosts_entry(ip, name)
25
+ `cat /etc/hosts | grep -v '#{name} \#VAGRANTHOSTS$' >/tmp/hosts.tmp`
26
+ `sudo mv /tmp/hosts.tmp /etc/hosts`
27
+ `sudo echo '#{ip} #{name} \#VAGRANTHOSTS' >>/etc/hosts`
28
+ end
29
+
30
+ def remove_hosts_entry(name)
31
+ `cat /etc/hosts | grep -v '#{name} \#VAGRANTHOSTS$' >/tmp/hosts.tmp`
32
+ `sudo mv /tmp/hosts.tmp /etc/hosts`
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,34 @@
1
+ require 'vagrant'
2
+
3
+ module VagrantPlugins
4
+ module Hosts
5
+ class Plugin < Vagrant.plugin("2")
6
+ name "Vagrant Hosts"
7
+ description "Manages host files on guest and host OSes"
8
+
9
+ host("bsd") do
10
+ require_relative 'hosts/bsd/host'
11
+ Hosts::BSD::Host
12
+ end
13
+
14
+ guest_capability("linux", "update_hosts_entry") do
15
+ require_relative "guest_capability/linux/update_hosts_entry"
16
+ GuestCapability::Linux::UpdateHostsEntry
17
+ end
18
+
19
+ guest_capability("linux", "remove_hosts_entry") do
20
+ require_relative "guest_capability/linux/remove_hosts_entry"
21
+ GuestCapability::Linux::RemoveHostsEntry
22
+ end
23
+
24
+ action_hook(:update_hosts_entry) do |hook|
25
+ hook.after(::VagrantPlugins::ProviderVirtualBox::Action::Boot, Action.update_hosts_entry)
26
+ end
27
+
28
+ action_hook(:remove_hosts_entry) do |hook|
29
+ hook.after(::VagrantPlugins::ProviderVirtualBox::Action::Destroy, Action.remove_hosts_entry)
30
+ end
31
+
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,19 @@
1
+ require 'log4r'
2
+ require 'vagrant'
3
+
4
+ module VagrantPlugins
5
+ module Hosts
6
+ class Provisioner < Vagrant.plugin("2", :provisioner)
7
+ def provision
8
+ @logger = Log4r::Logger.new("vagrant::plugins::hosts")
9
+
10
+ @logger.info("Adding host entries to guest.")
11
+ @machine.env.active_machines.each do |machine|
12
+ @machine.guest_capability :add_hosts_entry, machine.config.ssh.host, machine.config.hostname
13
+ @logger.info("Added entry for #{machine.config.hostname} to #{@machine.config.hostname}")
14
+ machine.guest_capability :add_hosts_entry, @machine.config.ssh.host, @machine.config.hostname
15
+ @logger.info("Added entry for #{@machine.config.hostname} to #{machine.config.hostname}")
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #require File.expand_path('../lib/vagrant/hostmaster/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Mike Geggie"]
6
+ gem.email = ["mikegeggie@gmail.com"]
7
+ gem.description = %q{vagrant-hosts is a Vagrant plugin to manage /etc/hosts entries on both the host OS and guest VMs.}
8
+ gem.summary = %q{Vagrant plugin to manage /etc/hosts entries.}
9
+ gem.homepage = "https://github.com/trigren/vagrant-hosts"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "vagrant-hostentriess"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = "0.5.0"
17
+
18
+ gem.add_development_dependency 'bundler'
19
+ gem.add_development_dependency 'vagrant'
20
+ gem.add_development_dependency 'rake'
21
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-hostentriess
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mike Geggie
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: vagrant
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: vagrant-hosts is a Vagrant plugin to manage /etc/hosts entries on both
63
+ the host OS and guest VMs.
64
+ email:
65
+ - mikegeggie@gmail.com
66
+ executables: []
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - .gitignore
71
+ - Gemfile
72
+ - Gemfile.lock
73
+ - README.md
74
+ - Rakefile
75
+ - Vagrantfile
76
+ - lib/vagrant-hosts.rb
77
+ - lib/vagrant-hosts/action.rb
78
+ - lib/vagrant-hosts/action/remove_hosts_entry.rb
79
+ - lib/vagrant-hosts/action/update_hosts_entry.rb
80
+ - lib/vagrant-hosts/guest_capability/linux/remove_hosts_entry.rb
81
+ - lib/vagrant-hosts/guest_capability/linux/update_hosts_entry.rb
82
+ - lib/vagrant-hosts/hosts/bsd/host.rb
83
+ - lib/vagrant-hosts/plugin.rb
84
+ - lib/vagrant-hosts/provisioner.rb
85
+ - vagrant-hosts.gemspec
86
+ homepage: https://github.com/trigren/vagrant-hosts
87
+ licenses: []
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ segments:
99
+ - 0
100
+ hash: 411734004694120775
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ segments:
108
+ - 0
109
+ hash: 411734004694120775
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 1.8.24
113
+ signing_key:
114
+ specification_version: 3
115
+ summary: Vagrant plugin to manage /etc/hosts entries.
116
+ test_files: []