From 0d7ecf5f4aeaca78a7e63e8aea6d0df6c08308cd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miros=C5=82aw=20Naga=C5=9B?= <mgolden@smoczus.pl>
Date: Wed, 17 Apr 2013 11:34:47 +0200
Subject: [PATCH 1/2] add simple host aliases implementation and configuration
 options validation

---
 lib/vagrant-hostmanager/config.rb     | 29 +++++++++++++++++++++++++++
 lib/vagrant-hostmanager/hosts_file.rb |  5 +++--
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/lib/vagrant-hostmanager/config.rb b/lib/vagrant-hostmanager/config.rb
index 1ba915b..7b8475a 100644
--- a/lib/vagrant-hostmanager/config.rb
+++ b/lib/vagrant-hostmanager/config.rb
@@ -3,16 +3,45 @@ module VagrantPlugins
     class Config < Vagrant.plugin('2', :config)
       attr_accessor :auto_update
       attr_accessor :ignore_private_ip
+      attr_accessor :aliases
 
       def initialize
         @auto_update = UNSET_VALUE
         @ignore_private_ip = UNSET_VALUE
+        @aliases = Array.new 
       end
 
       def finalize!
         @auto_update = true if @auto_update == UNSET_VALUE
         @ignore_private_ip = false if @ignore_private_ip == UNSET_VALUE
       end
+
+      def validate(machine)
+        errors = Array.new
+
+        # check if auto_update option is defined in Vagrantfile
+        # and check if is either true or false accordingly
+        if (machine.config.hostmanager.auto_update &&
+            ![TrueClass, FalseClass].include?(auto_update.class))
+          errors << "A value for hostmanager.auto_update can be true or false."
+        end
+
+        # check if ignore_private_ip option is defined in Vagrantfile
+        # and check if is either true or false accordingly
+        if (machine.config.hostmanager.ignore_private_ip &&
+            ![TrueClass, FalseClass].include?(ignore_private_ip.class))
+          errors << "A value for hostmanager.ignore_private_ip can be true or false."
+        end
+
+        # check if aliases option is defined in Vagrantfile
+        # and check if is an Array accordingly
+        if (machine.config.hostmanager.aliases &&
+            !machine.config.hostmanager.aliases.kind_of?(Array))
+          errors << "A value for hostmanager.aliases must be an Array."
+        end
+        
+        { "HostManager configuration" => errors }
+      end
     end
   end
 end
diff --git a/lib/vagrant-hostmanager/hosts_file.rb b/lib/vagrant-hostmanager/hosts_file.rb
index fb9af39..9c7b4fe 100644
--- a/lib/vagrant-hostmanager/hosts_file.rb
+++ b/lib/vagrant-hostmanager/hosts_file.rb
@@ -31,8 +31,9 @@ module VagrantPlugins
               machines << machine = env.machine(name, provider)
               host = machine.config.vm.hostname || name
               ip = get_ip_address.call(machine)
-              @logger.info "Adding /etc/hosts entry: #{ip} #{host}"
-              file << "#{ip}\t#{host}\n"
+              host_aliases = machine.config.hostmanager.aliases.join("\s").chomp
+              @logger.info "Adding /etc/hosts entry: #{ip} #{host} #{host_aliases}"
+              file << "#{ip}\t#{host}\s#{host_aliases}\n"
             end
           end
         end

From 5f384570ca56c8952f54f65e31d395ac01e72861 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miros=C5=82aw=20Naga=C5=9B?= <mgolden@smoczus.pl>
Date: Wed, 17 Apr 2013 12:24:45 +0200
Subject: [PATCH 2/2] update README

---
 README.md | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/README.md b/README.md
index 0026a9f..44aa9c1 100644
--- a/README.md
+++ b/README.md
@@ -40,6 +40,20 @@ to true.
 A machine's host name is defined by `config.vm.hostname`. If this is not
 set, it falls back to the symbol defining the machine in the Vagrantfile.
 
+In addition, the hostmanager.aliases configuration option can be used to provide aliases for your host names.
+
+Example configuration:
+
+  Vagrant.configure("2") do |config|
+    config.hostmanager.auto_update = true
+    config.hostmanager.ignore_private_ip = false
+    config.vm.define "example-box" do |node|
+       node.vm.hostname = "example-box-hostname"
+       node.vm.network :private_network, ip: "192.168.42.42"
+       node.hostmanager.aliases = %w(example-box.localdomain example-box-alias)
+    end
+  end
+
 Contribute
 ----------
 Contributions are welcome.