Class: VagrantPlugins::HostManager::Action::UpdateAll
- Inherits:
-
Object
- Object
- VagrantPlugins::HostManager::Action::UpdateAll
- Defined in:
- lib/vagrant-hostmanager-rethinc/action/update_all.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, env) ⇒ UpdateAll
constructor
A new instance of UpdateAll.
Constructor Details
#initialize(app, env) ⇒ UpdateAll
Returns a new instance of UpdateAll.
9 10 11 12 13 14 15 16 17 |
# File 'lib/vagrant-hostmanager-rethinc/action/update_all.rb', line 9 def initialize(app, env) @app = app @machine = env[:machine] @global_env = @machine.env @provider = @machine.provider_name @config = Util.get_config(@global_env) @updater = HostsFile::Updater.new(@global_env, @provider) @logger = Log4r::Logger.new('vagrant::hostmanager-rethinc::update_all') end |
Instance Method Details
#call(env) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/vagrant-hostmanager-rethinc/action/update_all.rb', line 19 def call(env) # skip if machine is not active on destroy action return @app.call(env) if !@machine.id && env[:machine_action] == :destroy # check config to see if the hosts file should be update automatically return @app.call(env) unless @config.hostmanager.enabled? @logger.info 'Updating /etc/hosts file automatically' @app.call(env) # update /etc/hosts file on active machines if @machine.config.hostmanager.manage_guest? env[:ui].info I18n.t('vagrant_hostmanager.action.update_guests') @global_env.active_machines.each do |name, p| if p == @provider machine = @global_env.machine(name, p) state = machine.state if ['active','running'].include?(state.short_description) @updater.update_guest(machine) end end end end # update /etc/hosts files on host if enabled if @machine.config.hostmanager.manage_host? env[:ui].info I18n.t('vagrant_hostmanager.action.update_host') @updater.update_host end end |