Built-in hostname middleware for setting hostname
This commit is contained in:
parent
21c218e32f
commit
c9ad55d9e7
|
@ -19,6 +19,7 @@ module Vagrant
|
||||||
autoload :Lock, "vagrant/action/builtin/lock"
|
autoload :Lock, "vagrant/action/builtin/lock"
|
||||||
autoload :NFS, "vagrant/action/builtin/nfs"
|
autoload :NFS, "vagrant/action/builtin/nfs"
|
||||||
autoload :Provision, "vagrant/action/builtin/provision"
|
autoload :Provision, "vagrant/action/builtin/provision"
|
||||||
|
autoload :SetHostname, "vagrant/action/builtin/set_hostname"
|
||||||
autoload :SSHExec, "vagrant/action/builtin/ssh_exec"
|
autoload :SSHExec, "vagrant/action/builtin/ssh_exec"
|
||||||
autoload :SSHRun, "vagrant/action/builtin/ssh_run"
|
autoload :SSHRun, "vagrant/action/builtin/ssh_run"
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
require "log4r"
|
||||||
|
|
||||||
|
module Vagrant
|
||||||
|
module Action
|
||||||
|
module Builtin
|
||||||
|
# This middleware sets the hostname of the guest according to the
|
||||||
|
# "vm.hostname" configuration parameter if it is set. This middleware
|
||||||
|
# should be placed such that the after the @app.call, a booted machine
|
||||||
|
# is available (this generally means BEFORE the boot middleware).
|
||||||
|
class SetHostname
|
||||||
|
def initialize(app, env)
|
||||||
|
@app = app
|
||||||
|
end
|
||||||
|
|
||||||
|
def call(env)
|
||||||
|
@app.call(env)
|
||||||
|
|
||||||
|
hostname = env[:machine].config.vm.hostname
|
||||||
|
if !hostname.nil?
|
||||||
|
env[:ui].info I18n.t("vagrant.actions.vm.hostname.setting")
|
||||||
|
env[:machine].guest.change_host_name(hostname)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -22,7 +22,6 @@ module VagrantPlugins
|
||||||
autoload :Export, File.expand_path("../action/export", __FILE__)
|
autoload :Export, File.expand_path("../action/export", __FILE__)
|
||||||
autoload :ForcedHalt, File.expand_path("../action/forced_halt", __FILE__)
|
autoload :ForcedHalt, File.expand_path("../action/forced_halt", __FILE__)
|
||||||
autoload :ForwardPorts, File.expand_path("../action/forward_ports", __FILE__)
|
autoload :ForwardPorts, File.expand_path("../action/forward_ports", __FILE__)
|
||||||
autoload :HostName, File.expand_path("../action/host_name", __FILE__)
|
|
||||||
autoload :Import, File.expand_path("../action/import", __FILE__)
|
autoload :Import, File.expand_path("../action/import", __FILE__)
|
||||||
autoload :IsPaused, File.expand_path("../action/is_paused", __FILE__)
|
autoload :IsPaused, File.expand_path("../action/is_paused", __FILE__)
|
||||||
autoload :IsRunning, File.expand_path("../action/is_running", __FILE__)
|
autoload :IsRunning, File.expand_path("../action/is_running", __FILE__)
|
||||||
|
@ -68,7 +67,7 @@ module VagrantPlugins
|
||||||
b.use ClearNetworkInterfaces
|
b.use ClearNetworkInterfaces
|
||||||
b.use Network
|
b.use Network
|
||||||
b.use ForwardPorts
|
b.use ForwardPorts
|
||||||
b.use HostName
|
b.use SetHostname
|
||||||
b.use SaneDefaults
|
b.use SaneDefaults
|
||||||
b.use Customize
|
b.use Customize
|
||||||
b.use Boot
|
b.use Boot
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
module VagrantPlugins
|
|
||||||
module ProviderVirtualBox
|
|
||||||
module Action
|
|
||||||
class HostName
|
|
||||||
def initialize(app, env)
|
|
||||||
@app = app
|
|
||||||
end
|
|
||||||
|
|
||||||
def call(env)
|
|
||||||
@app.call(env)
|
|
||||||
|
|
||||||
host_name = env[:machine].config.vm.host_name
|
|
||||||
if !host_name.nil?
|
|
||||||
env[:ui].info I18n.t("vagrant.actions.vm.host_name.setting")
|
|
||||||
env[:machine].guest.change_host_name(host_name)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -665,7 +665,7 @@ en:
|
||||||
Forcing shutdown of VM...
|
Forcing shutdown of VM...
|
||||||
graceful: |-
|
graceful: |-
|
||||||
Attempting graceful shutdown of VM...
|
Attempting graceful shutdown of VM...
|
||||||
host_name:
|
hostname:
|
||||||
setting: "Setting hostname..."
|
setting: "Setting hostname..."
|
||||||
import:
|
import:
|
||||||
importing: Importing base box '%{name}'...
|
importing: Importing base box '%{name}'...
|
||||||
|
|
Loading…
Reference in New Issue