vagrant-hostmanager 0.4.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,4 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'vagrant', :git => 'git://github.com/mitchellh/vagrant.git', :tag => 'v1.2.1'
3
+ group :development do
4
+ gem 'vagrant', :git => 'git://github.com/mitchellh/vagrant.git', :tag => 'v1.2.2'
5
+ end
6
+
4
7
  gemspec
data/README.md CHANGED
@@ -1,17 +1,9 @@
1
1
  Vagrant Host Manager
2
2
  ====================
3
3
  `vagrant-hostmanager` is a Vagrant 1.1+ plugin that manages the `/etc/hosts`
4
- file on guest machines. Its goal is to enable resolution of multi-machine
5
- environments deployed with a cloud provider where IP addresses are not known
6
- in advance.
7
-
8
- Status
9
- ------
10
- The current implementation is a proof-of-concept supporting the larger
11
- objective of using Vagrant as a cloud management interface for development
12
- and production environments.
13
-
14
- The plugin has been tested with Vagrant 1.1.5.
4
+ file on guest machines (and optionally the host). Its goal is to enable
5
+ resolution of multi-machine environments deployed with a cloud provider
6
+ where IP addresses are not known in advance.
15
7
 
16
8
  Installation
17
9
  ------------
@@ -32,6 +24,9 @@ machines with the same provider will have their `/etc/hosts` file updated
32
24
  accordingly. Set the `hostmanager.enabled` attribute to `true` in the
33
25
  Vagrantfile to activate this behavior.
34
26
 
27
+ To update the host's `/etc/hosts` file, set the `hostmanager.manage_host`
28
+ attribute to `true`.
29
+
35
30
  A machine's IP address is defined by either the static IP for a private
36
31
  network configuration or by the SSH host configuration. To disable
37
32
  using the private network IP address, set `config.hostmanger.ignore_private_ip`
@@ -40,9 +35,8 @@ to true.
40
35
  A machine's host name is defined by `config.vm.hostname`. If this is not
41
36
  set, it falls back to the symbol defining the machine in the Vagrantfile.
42
37
 
43
- When using include_offline set to true, only boxes that are up or have a
44
- private ip configured will be added to the hosts file. You will receive a
45
- warning on skipped boxes.
38
+ If the `hostmanager.include_offline` attribute is set to `true`, boxes that are
39
+ up or have a private ip configured will be added to the hosts file.
46
40
 
47
41
  In addition, the `hostmanager.aliases` configuration attribute can be used
48
42
  to provide aliases for your host names.
@@ -52,17 +46,18 @@ Example configuration:
52
46
  ```ruby
53
47
  Vagrant.configure("2") do |config|
54
48
  config.hostmanager.enabled = true
49
+ config.hostmanager.manage_host = true
55
50
  config.hostmanager.ignore_private_ip = false
56
51
  config.hostmanager.include_offline = true
57
- config.vm.define "example-box" do |node|
58
- node.vm.hostname = "example-box-hostname"
59
- node.vm.network :private_network, ip: "192.168.42.42"
52
+ config.vm.define 'example-box' do |node|
53
+ node.vm.hostname = 'example-box-hostname'
54
+ node.vm.network :private_network, ip: '192.168.42.42'
60
55
  node.hostmanager.aliases = %w(example-box.localdomain example-box-alias)
61
56
  end
62
57
  end
63
58
  ```
64
59
 
65
- As a last option, you can also choose hostmanager as a provisioner.
60
+ As a last option, you can use hostmanager as a provisioner.
66
61
  This allows you to use the provisioning order to ensure that hostmanager
67
62
  runs before or after provisioning. The provisioner will collect hosts from
68
63
  boxes with the same provider as the running box.
@@ -0,0 +1,31 @@
1
+ require 'vagrant-hostmanager/action/update_all'
2
+ require 'vagrant-hostmanager/action/update_guest'
3
+ require 'vagrant-hostmanager/action/update_host'
4
+
5
+ module VagrantPlugins
6
+ module HostManager
7
+ module Action
8
+ include Vagrant::Action::Builtin
9
+
10
+ def self.update_all
11
+ Vagrant::Action::Builder.new.tap do |builder|
12
+ builder.use ConfigValidate
13
+ builder.use UpdateAll
14
+ end
15
+ end
16
+
17
+ def self.update_guest
18
+ Vagrant::Action::Builder.new.tap do |builder|
19
+ builder.use ConfigValidate
20
+ builder.use UpdateGuest
21
+ end
22
+ end
23
+
24
+ def self.update_host
25
+ Vagrant::Action::Builder.new.tap do |builder|
26
+ builder.use UpdateHost
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,47 @@
1
+ require 'vagrant-hostmanager/hosts_file'
2
+
3
+ module VagrantPlugins
4
+ module HostManager
5
+ module Action
6
+ class UpdateAll
7
+ include HostsFile
8
+
9
+ def initialize(app, env)
10
+ @app = app
11
+ @machine = env[:machine]
12
+ @global_env = @machine.env
13
+ @provider = @machine.provider_name
14
+ @logger = Log4r::Logger.new('vagrant::hostmanager::update_all')
15
+ end
16
+
17
+ def call(env)
18
+ # skip if machine is already active on up action
19
+ return @app.call(env) if @machine.id && env[:machine_action] == :up
20
+ # skip if machine is not active on destroy action
21
+ return @app.call(env) if !@machine.id && env[:machine_action] == :destroy
22
+
23
+ # check config to see if the hosts file should be update automatically
24
+ return @app.call(env) unless @machine.config.hostmanager.enabled?
25
+ @logger.info 'Updating /etc/hosts file automatically'
26
+
27
+ @app.call(env)
28
+
29
+ # update /etc/hosts file on active machines
30
+ env[:ui].info I18n.t('vagrant_hostmanager.action.update_guests')
31
+ @global_env.active_machines.each do |name, p|
32
+ if p == @provider
33
+ machine = @global_env.machine(name, p)
34
+ update_guest(machine)
35
+ end
36
+ end
37
+
38
+ # update /etc/hosts files on host if enabled
39
+ if @machine.config.hostmanager.manage_host?
40
+ env[:ui].info I18n.t('vagrant_hostmanager.action.update_host')
41
+ update_host
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,28 @@
1
+ require 'vagrant-hostmanager/hosts_file'
2
+
3
+ module VagrantPlugins
4
+ module HostManager
5
+ module Action
6
+ class UpdateGuest
7
+ include HostsFile
8
+
9
+ def initialize(app, env)
10
+ @app = app
11
+ @machine = env[:machine]
12
+ @global_env = @machine.env
13
+ @provider = env[:provider]
14
+ @logger = Log4r::Logger.new('vagrant::hostmanager::update_guest')
15
+ end
16
+
17
+ def call(env)
18
+ env[:ui].info I18n.t('vagrant_hostmanager.action.update_guest', {
19
+ :name => @machine.name
20
+ })
21
+ update_guest(@machine)
22
+
23
+ @app.call(env)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ require 'vagrant-hostmanager/hosts_file'
2
+
3
+ module VagrantPlugins
4
+ module HostManager
5
+ module Action
6
+ class UpdateHost
7
+ include HostsFile
8
+
9
+ def initialize(app, env)
10
+ @app = app
11
+ @global_env = env[:global_env]
12
+ @provider = env[:provider]
13
+ @logger = Log4r::Logger.new('vagrant::hostmanager::update_host')
14
+ end
15
+
16
+ def call(env)
17
+ if @global_env.config_global.hostmanager.manage_host?
18
+ env[:ui].info I18n.t('vagrant_hostmanager.action.update_host')
19
+ update_host
20
+ end
21
+
22
+ @app.call(env)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+
@@ -18,15 +18,21 @@ module VagrantPlugins
18
18
  end
19
19
 
20
20
  argv = parse_options(opts)
21
- return if !argv
22
-
23
21
  options[:provider] ||= @env.default_provider
24
22
 
25
- generate(@env, options[:provider].to_sym)
26
-
23
+ # update /etc/hosts file for specified guest machines
27
24
  with_target_vms(argv, options) do |machine|
28
- update(machine)
25
+ @env.action_runner.run(Action.update_guest, {
26
+ :machine => machine,
27
+ :provider => options[:provider]
28
+ })
29
29
  end
30
+
31
+ # update /etc/hosts file for host
32
+ @env.action_runner.run(Action.update_host, {
33
+ :global_env => @env,
34
+ :provider => options[:provider]
35
+ })
30
36
  end
31
37
  end
32
38
  end
@@ -2,41 +2,41 @@ module VagrantPlugins
2
2
  module HostManager
3
3
  class Config < Vagrant.plugin('2', :config)
4
4
  attr_accessor :enabled
5
+ attr_accessor :manage_host
5
6
  attr_accessor :ignore_private_ip
6
7
  attr_accessor :aliases
7
8
  attr_accessor :include_offline
8
9
 
9
10
  alias_method :enabled?, :enabled
10
11
  alias_method :include_offline?, :include_offline
12
+ alias_method :manage_host?, :manage_host
11
13
 
12
14
  def initialize
13
- @enabled = false
15
+ @enabled = UNSET_VALUE
16
+ @manage_host = UNSET_VALUE
14
17
  @ignore_private_ip = UNSET_VALUE
15
- @aliases = Array.new
16
- @include_offline = false
18
+ @include_offline = UNSET_VALUE
19
+ @aliases = []
17
20
  end
18
21
 
19
22
  def finalize!
23
+ @enabled = false if @enabled == UNSET_VALUE
24
+ @manage_host = false if @managed_host == UNSET_VALUE
20
25
  @ignore_private_ip = false if @ignore_private_ip == UNSET_VALUE
26
+ @include_offline = false if @include_offline == UNSET_VALUE
21
27
  @aliases = [ @aliases ].flatten
22
28
  end
23
29
 
24
30
  def validate(machine)
25
- errors = Array.new
31
+ errors = []
26
32
 
27
- # check if enabled option is either true or false
28
- errors << validate_bool('hostmanager.enabled', enabled)
29
-
30
- # check if include_offline is either true or false
31
- errors << validate_bool('hostmanager.include_offline', include_offline)
32
-
33
- # check if ignore_private_ip option is either true or false (or UNSET_VALUE)
34
- if @ignore_private_ip != UNSET_VALUE
35
- errors << validate_bool('hostmanager.ignore_private_ip', ignore_private_ip)
36
- end
33
+ errors << validate_bool('hostmanager.enabled', @enabled)
34
+ errors << validate_bool('hostmanager.manage_host', @manage_host)
35
+ errors << validate_bool('hostmanager.ignore_private_ip', @ignore_private_ip)
36
+ errors << validate_bool('hostmanager.include_offline', @include_offline)
37
+ errors.compact!
37
38
 
38
- # check if aliases option is an Array
39
- if !machine.config.hostmanager.aliases.kind_of?(Array) and
39
+ if !machine.config.hostmanager.aliases.kind_of?(Array) and
40
40
  !machine.config.hostmanager.aliases.kind_of?(String)
41
41
  errors << I18n.t('vagrant_hostmanager.config.not_an_array_or_string', {
42
42
  :config_key => 'hostmanager.aliases',
@@ -44,22 +44,21 @@ module VagrantPlugins
44
44
  })
45
45
  end
46
46
 
47
- errors.compact!
48
- { "HostManager configuration" => errors }
47
+ { 'HostManager configuration' => errors }
49
48
  end
50
49
 
51
50
  private
51
+
52
52
  def validate_bool(key, value)
53
53
  if ![TrueClass, FalseClass].include?(value.class)
54
54
  I18n.t('vagrant_hostmanager.config.not_a_bool', {
55
55
  :config_key => key,
56
- :value => value.class.to_s,
56
+ :value => value.class.to_s
57
57
  })
58
58
  else
59
59
  nil
60
60
  end
61
61
  end
62
-
63
62
  end
64
63
  end
65
64
  end
@@ -1,86 +1,90 @@
1
+ require 'tempfile'
2
+
1
3
  module VagrantPlugins
2
4
  module HostManager
3
5
  module HostsFile
4
- # Generate a hosts file containing the the active machines
5
- # in the Vagrant environment backed by the specified provider.
6
- # The file is written to the Vagrant temporary path.
7
- def generate(env, provider)
8
- machines = []
6
+ def update_guest(machine)
7
+ return unless machine.communicate.ready?
9
8
 
10
- # define a lambda for looking up a machine's ip address
11
- get_ip_address = lambda do |machine|
12
- ip = nil
13
- if machine.config.hostmanager.ignore_private_ip != true
14
- machine.config.vm.networks.each do |network|
15
- key, options = network[0], network[1]
16
- ip = options[:ip] if key == :private_network
17
- next if ip
18
- end
9
+ # download and modify file with Vagrant-managed entries
10
+ file = @global_env.tmp_path.join("hosts.#{machine.name}")
11
+ machine.communicate.download('/etc/hosts', file)
12
+ update_file(file)
13
+
14
+ # upload modified file and remove temporary file
15
+ machine.communicate.upload(file, '/tmp/hosts')
16
+ machine.communicate.sudo('mv /tmp/hosts /etc/hosts')
17
+ FileUtils.rm(file)
18
+ end
19
+
20
+ def update_host
21
+ # copy and modify hosts file on host with Vagrant-managed entries
22
+ file = @global_env.tmp_path.join('hosts.local')
23
+ FileUtils.cp('/etc/hosts', file)
24
+ update_file(file)
25
+
26
+ # copy modified file using sudo for permission
27
+ `sudo cp #{file} /etc/hosts`
28
+ end
29
+
30
+ private
31
+
32
+ def update_file(file)
33
+ # build array of host file entries from Vagrant configuration
34
+ entries = []
35
+ get_machines.each do |name, p|
36
+ if @provider == p
37
+ machine = @global_env.machine(name, p)
38
+ host = machine.config.vm.hostname || name
39
+ id = machine.id
40
+ ip = get_ip_address(machine)
41
+ aliases = machine.config.hostmanager.aliases.join(' ').chomp
42
+ entries << "#{ip}\t#{host} #{aliases}\t# VAGRANT ID: #{id}\n"
19
43
  end
20
- ip || (machine.ssh_info ? machine.ssh_info[:host] : nil)
21
44
  end
22
45
 
23
- # create the temporary hosts file
24
- path = env.tmp_path.join('hosts')
25
- File.open(path, 'w') do |file|
26
- file << "127.0.0.1\tlocalhost\slocalhost.localdomain\n"
27
- get_machines(env, provider).each do |name, p|
28
- if provider == p
29
- machines << machine = env.machine(name, provider)
30
- host = machine.config.vm.hostname || name
31
- ip = get_ip_address.call(machine)
32
- if ip
33
- host_aliases = machine.config.hostmanager.aliases.join("\s").chomp
34
- machine.env.ui.info I18n.t('vagrant_hostmanager.action.add_host', {
35
- :ip => ip,
36
- :host => host,
37
- :aliases => host_aliases,
38
- })
39
- file << "#{ip}\t#{host}\s#{host_aliases}\n"
40
- else
41
- machine.env.ui.warn I18n.t('vagrant_hostmanager.action.host_no_ip', {
42
- :name => name,
43
- })
44
- end
45
- end
46
+ tmp_file = Tempfile.open('hostmanager', @global_env.tmp_path, 'a')
47
+ begin
48
+ # copy each line not managed by Vagrant
49
+ File.open(file).each_line do |line|
50
+ tmp_file << line unless line =~ /# VAGRANT ID:/
46
51
  end
52
+
53
+ # write a line for each Vagrant-managed entry
54
+ entries.each { |entry| tmp_file << entry }
55
+ ensure
56
+ tmp_file.close
57
+ FileUtils.cp(tmp_file, file)
58
+ tmp_file.unlink
47
59
  end
48
- machines
49
60
  end
50
61
 
51
- # Copy the temporary hosts file to the specified machine overwritting
52
- # the existing /etc/hosts file.
53
- def update(machine)
54
- path = machine.env.tmp_path.join('hosts')
55
- if machine.communicate.ready?
56
- machine.env.ui.info I18n.t('vagrant_hostmanager.action.update', {
57
- :name => machine.name
58
- })
59
- machine.communicate.upload(path, '/tmp/hosts')
60
- machine.communicate.sudo("mv /tmp/hosts /etc/hosts")
62
+ def get_ip_address(machine)
63
+ ip = nil
64
+ if machine.config.hostmanager.ignore_private_ip != true
65
+ machine.config.vm.networks.each do |network|
66
+ key, options = network[0], network[1]
67
+ ip = options[:ip] if key == :private_network
68
+ next if ip
69
+ end
61
70
  end
71
+ ip || (machine.ssh_info ? machine.ssh_info[:host] : nil)
62
72
  end
63
73
 
64
- private
65
- # Either use the active machines, or loop over all available machines and
66
- # get those with the same provider (aka, ignore boxes that throw MachineNotFound errors).
67
- #
68
- # Returns an array with the same structure as env.active_machines:
69
- # [ [:machine, :virtualbox], [:foo, :virtualbox] ]
70
- def get_machines(env, provider)
71
- if env.config_global.hostmanager.include_offline?
74
+ def get_machines
75
+ # check if offline machines should be included in host entries
76
+ if @global_env.config_global.hostmanager.include_offline?
72
77
  machines = []
73
- env.machine_names.each do |name|
78
+ @global_env.machine_names.each do |name|
74
79
  begin
75
- m = env.machine(name, provider)
76
- machines << [name, provider]
77
- rescue Vagrant::Errors::MachineNotFound => ex
78
- # ignore this box.
80
+ @global_env.machine(name, @provider)
81
+ machines << [name, @provider]
82
+ rescue Vagrant::Errors::MachineNotFound
79
83
  end
80
84
  end
81
85
  machines
82
86
  else
83
- env.active_machines
87
+ @global_env.active_machines
84
88
  end
85
89
  end
86
90
 
@@ -1,12 +1,12 @@
1
- require 'vagrant-hostmanager/action/update_hosts_file'
1
+ require 'vagrant-hostmanager/action'
2
2
 
3
3
  module VagrantPlugins
4
4
  module HostManager
5
5
  class Plugin < Vagrant.plugin('2')
6
6
  name 'HostManager'
7
7
  description <<-DESC
8
- This plugin manages the /etc/hosts file for guest machines. An entry is
9
- created for each active machine using the hostname attribute.
8
+ This plugin manages the /etc/hosts file for the host and guest machines.
9
+ An entry is created for each active machine using the hostname attribute.
10
10
 
11
11
  You can also use the hostmanager provisioner to update the hosts file.
12
12
  DESC
@@ -17,11 +17,11 @@ module VagrantPlugins
17
17
  end
18
18
 
19
19
  action_hook(:hostmanager, :machine_action_up) do |hook|
20
- hook.prepend(Action::UpdateHostsFile)
20
+ hook.prepend(Action.update_all)
21
21
  end
22
22
 
23
23
  action_hook(:hostmanager, :machine_action_destroy) do |hook|
24
- hook.append(Action::UpdateHostsFile)
24
+ hook.prepend(Action.update_all)
25
25
  end
26
26
 
27
27
  provisioner(:hostmanager) do
@@ -3,9 +3,17 @@ module VagrantPlugins
3
3
  class Provisioner < Vagrant.plugin('2', :provisioner)
4
4
  include HostsFile
5
5
 
6
+ def initialize(machine, config)
7
+ super(machine, config)
8
+ @global_env = machine.env
9
+ @provider = machine.provider_name
10
+ end
11
+
6
12
  def provision
7
- generate(@machine.env, @machine.box.provider.to_sym)
8
- update(@machine)
13
+ update_guest(@machine)
14
+ if @global_env.config_global.hostmanager.manage_host?
15
+ update_host
16
+ end
9
17
  end
10
18
  end
11
19
  end
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module HostManager
3
- VERSION = '0.4.0'
3
+ VERSION = '1.0.0'
4
4
  end
5
5
  end
@@ -1,9 +1,9 @@
1
1
  en:
2
2
  vagrant_hostmanager:
3
3
  action:
4
- add_host: "Adding /etc/hosts entry: %{ip} %{host} %{aliases}"
5
- host_no_ip: "Could not determine ip for machine '%{name}': no private ip configured or machine not up."
6
- update: "[%{name}] Updating /etc/hosts file"
4
+ update_guests: "Updating /etc/hosts file on active guest machines..."
5
+ update_guest: "[%{name}] Updating /etc/hosts file..."
6
+ update_host: "Updating /etc/hosts file on host machine (password may be required)..."
7
7
  config:
8
8
  not_a_bool: "A value for %{config_key} can only be true or false, not type '%{value}'"
9
9
  not_an_array_or_string: "A value for %{config_key} must be an Array or String, not type '%{is_class}'"
@@ -4,14 +4,16 @@
4
4
  Vagrant.require_plugin('vagrant-hostmanager')
5
5
 
6
6
  Vagrant.configure('2') do |config|
7
- config.vm.box = 'precise64-chef11.2'
8
- config.vm.box_url = 'https://opscode-vm.s3.amazonaws.com/vagrant/opscode_ubuntu-12.04_chef-11.2.0.box'
7
+ config.vm.box = 'precise64'
8
+ config.vm.box_url = 'http://cloud-images.ubuntu.com/precise/current/precise-server-cloudimg-vagrant-amd64-disk1.box'
9
9
 
10
10
  config.hostmanager.enabled = true
11
+ config.hostmanager.manage_host = true
11
12
 
12
13
  config.vm.define :server1 do |server|
13
14
  server.vm.hostname = 'fry'
14
15
  server.vm.network :private_network, :ip => '10.0.5.2'
16
+ server.hostmanager.aliases = %w(test-alias)
15
17
  end
16
18
 
17
19
  config.vm.define :server2 do |server|
@@ -1,4 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
+
2
3
  lib = File.expand_path('../lib', __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'vagrant-hostmanager/version'
@@ -14,4 +15,7 @@ Gem::Specification.new do |gem|
14
15
  gem.files = `git ls-files`.split($/)
15
16
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
17
  gem.require_paths = ['lib']
18
+
19
+ gem.add_development_dependency 'bundler', '~> 1.3'
20
+ gem.add_development_dependency 'rake'
17
21
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-hostmanager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,40 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-07 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2013-06-20 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: '1.3'
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: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
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'
14
46
  description: A Vagrant plugin that manages the /etc/hosts file within a multi-machine
15
47
  environment
16
48
  email:
@@ -25,7 +57,10 @@ files:
25
57
  - README.md
26
58
  - Rakefile
27
59
  - lib/vagrant-hostmanager.rb
28
- - lib/vagrant-hostmanager/action/update_hosts_file.rb
60
+ - lib/vagrant-hostmanager/action.rb
61
+ - lib/vagrant-hostmanager/action/update_all.rb
62
+ - lib/vagrant-hostmanager/action/update_guest.rb
63
+ - lib/vagrant-hostmanager/action/update_host.rb
29
64
  - lib/vagrant-hostmanager/command.rb
30
65
  - lib/vagrant-hostmanager/config.rb
31
66
  - lib/vagrant-hostmanager/errors.rb
@@ -1,33 +0,0 @@
1
- require 'vagrant-hostmanager/hosts_file'
2
-
3
- module VagrantPlugins
4
- module HostManager
5
- module Action
6
- class UpdateHostsFile
7
- include HostsFile
8
-
9
- def initialize(app, env)
10
- @app = app
11
- @machine = env[:machine]
12
- @logger = Log4r::Logger.new('vagrant::hostmanager::update_hosts_file')
13
- end
14
-
15
- def call(env)
16
- # check if machine is already active
17
- return @app.call(env) if @machine.id
18
-
19
- # check config to see if the hosts file should be update automatically
20
- return @app.call(env) unless @machine.config.hostmanager.enabled?
21
- @logger.info 'Updating /etc/hosts file automatically'
22
-
23
- # continue the action stack so the machine will be created
24
- @app.call(env)
25
-
26
- # update /etc/hosts file on each active machine
27
- machines = generate(@machine.env, @machine.provider_name)
28
- machines.each { |machine| update(machine) }
29
- end
30
- end
31
- end
32
- end
33
- end