Merge pull request #19 from cloudnautique/add_hostname

Added Hostname capability
This commit is contained in:
Ivan Mikushin 2015-07-29 10:27:02 +05:00
commit f81057963c
2 changed files with 31 additions and 7 deletions

1
Vagrantfile vendored
View File

@ -29,6 +29,7 @@ Vagrant.configure(2) do |config|
ip = "172.19.8.#{i+100}" ip = "172.19.8.#{i+100}"
node.vm.network "private_network", ip: ip node.vm.network "private_network", ip: ip
node.vm.hostname = hostname
# Disabling compression because OS X has an ancient version of rsync installed. # Disabling compression because OS X has an ancient version of rsync installed.
# Add -z or remove rsync__args below if you have a newer version of rsync on your machine. # Add -z or remove rsync__args below if you have a newer version of rsync on your machine.

View File

@ -12,14 +12,21 @@ end
module VagrantPlugins module VagrantPlugins
module GuestLinux module GuestLinux
class Plugin < Vagrant.plugin("2") class Plugin < Vagrant.plugin("2")
guest_capability("linux", "change_host_name") do
Cap::ChangeHostName
end
guest_capability("linux", "configure_networks") do guest_capability("linux", "configure_networks") do
Cap::ConfigureNetworks Cap::ConfigureNetworks
end end
end end
end
end
module VagrantPlugins
module GuestLinux
module Cap module Cap
class ConfigureNetworks class ConfigureNetworks
def self.configure_networks(machine, networks) def self.configure_networks(machine, networks)
machine.communicate.tap do |comm| machine.communicate.tap do |comm|
interfaces = [] interfaces = []
@ -48,3 +55,19 @@ module VagrantPlugins
end end
end end
end end
module VagrantPlugins
module GuestLinux
module Cap
class ChangeHostName
def self.change_host_name(machine, name)
machine.communicate.tap do |comm|
if !comm.test("sudo hostname --fqdn | grep '#{name}'")
comm.sudo("hostname #{name.split('.')[0]}")
end
end
end
end
end
end
end