vagrant-hostmanager 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -40,6 +40,23 @@ to true.
40
40
  A machine's host name is defined by `config.vm.hostname`. If this is not
41
41
  set, it falls back to the symbol defining the machine in the Vagrantfile.
42
42
 
43
+ In addition, the `hostmanager.aliases` configuration attribute can be used
44
+ to provide aliases for your host names.
45
+
46
+ Example configuration:
47
+
48
+ ```ruby
49
+ Vagrant.configure("2") do |config|
50
+ config.hostmanager.auto_update = true
51
+ config.hostmanager.ignore_private_ip = false
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"
55
+ node.hostmanager.aliases = %w(example-box.localdomain example-box-alias)
56
+ end
57
+ end
58
+ ```
59
+
43
60
  Contribute
44
61
  ----------
45
62
  Contributions are welcome.
@@ -3,16 +3,45 @@ module VagrantPlugins
3
3
  class Config < Vagrant.plugin('2', :config)
4
4
  attr_accessor :auto_update
5
5
  attr_accessor :ignore_private_ip
6
+ attr_accessor :aliases
6
7
 
7
8
  def initialize
8
9
  @auto_update = UNSET_VALUE
9
10
  @ignore_private_ip = UNSET_VALUE
11
+ @aliases = Array.new
10
12
  end
11
13
 
12
14
  def finalize!
13
15
  @auto_update = true if @auto_update == UNSET_VALUE
14
16
  @ignore_private_ip = false if @ignore_private_ip == UNSET_VALUE
15
17
  end
18
+
19
+ def validate(machine)
20
+ errors = Array.new
21
+
22
+ # check if auto_update option is defined in Vagrantfile
23
+ # and check if is either true or false accordingly
24
+ if (machine.config.hostmanager.auto_update &&
25
+ ![TrueClass, FalseClass].include?(auto_update.class))
26
+ errors << "A value for hostmanager.auto_update can be true or false."
27
+ end
28
+
29
+ # check if ignore_private_ip option is defined in Vagrantfile
30
+ # and check if is either true or false accordingly
31
+ if (machine.config.hostmanager.ignore_private_ip &&
32
+ ![TrueClass, FalseClass].include?(ignore_private_ip.class))
33
+ errors << "A value for hostmanager.ignore_private_ip can be true or false."
34
+ end
35
+
36
+ # check if aliases option is defined in Vagrantfile
37
+ # and check if is an Array accordingly
38
+ if (machine.config.hostmanager.aliases &&
39
+ !machine.config.hostmanager.aliases.kind_of?(Array))
40
+ errors << "A value for hostmanager.aliases must be an Array."
41
+ end
42
+
43
+ { "HostManager configuration" => errors }
44
+ end
16
45
  end
17
46
  end
18
47
  end
@@ -10,7 +10,7 @@ module VagrantPlugins
10
10
  # define a lambda for looking up a machine's ip address
11
11
  get_ip_address = lambda do |machine|
12
12
  ip = nil
13
- unless machine.config.hostmanager.ignore_private_ip
13
+ if machine.config.hostmanager.ignore_private_ip != true
14
14
  machine.config.vm.networks.each do |network|
15
15
  key, options = network[0], network[1]
16
16
  ip = options[:ip] if key == :private_network
@@ -23,7 +23,7 @@ module VagrantPlugins
23
23
  # create the temporary hosts file
24
24
  path = env.tmp_path.join('hosts')
25
25
  File.open(path, 'w') do |file|
26
- file << "127.0.0.1\tlocalhost\n"
26
+ file << "127.0.0.1\tlocalhost\slocalhost.localdomain\n"
27
27
 
28
28
  # add a hosts entry for each active machine matching the provider
29
29
  env.active_machines.each do |name, p|
@@ -31,8 +31,9 @@ module VagrantPlugins
31
31
  machines << machine = env.machine(name, provider)
32
32
  host = machine.config.vm.hostname || name
33
33
  ip = get_ip_address.call(machine)
34
- @logger.info "Adding /etc/hosts entry: #{ip} #{host}"
35
- file << "#{ip}\t#{host}\n"
34
+ host_aliases = machine.config.hostmanager.aliases.join("\s").chomp
35
+ @logger.info "Adding /etc/hosts entry: #{ip} #{host} #{host_aliases}"
36
+ file << "#{ip}\t#{host}\s#{host_aliases}\n"
36
37
  end
37
38
  end
38
39
  end
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module HostManager
3
- VERSION = '0.1.0'
3
+ VERSION = '0.1.1'
4
4
  end
5
5
  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.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-12 00:00:00.000000000 Z
12
+ date: 2013-04-17 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A Vagrant plugin that manages the /etc/hosts file within a multi-machine
15
15
  environment