Class: VagrantPlugins::GPIICi::Action::UpdateHosts
- Inherits:
-
Object
- Object
- VagrantPlugins::GPIICi::Action::UpdateHosts
- Defined in:
- lib/vagrant-gpii-ci/action/update_hosts.rb
Instance Method Summary collapse
-
#initialize(app, env) ⇒ UpdateHosts
constructor
A new instance of UpdateHosts.
- #update_guest(machine) ⇒ Object
Constructor Details
#initialize(app, env) ⇒ UpdateHosts
Returns a new instance of UpdateHosts.
6 7 8 9 10 11 12 |
# File 'lib/vagrant-gpii-ci/action/update_hosts.rb', line 6 def initialize(app, env) @global_env = global_env @config = Util.get_config(@global_env) @provider = provider @logger = Log4r::Logger.new('vagrant::hostmanager::updater') @logger.debug("init updater") end |
Instance Method Details
#update_guest(machine) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/vagrant-gpii-ci/action/update_hosts.rb', line 14 def update_guest(machine) return unless machine.communicate.ready? if machine.config.vm.communicator == :winrm windir = "" machine.communicate.execute("echo %SYSTEMROOT%", {:shell => :cmd}) do |type, contents| windir << contents.gsub("\r\n", '') if type == :stdout end realhostfile = "#{windir}\\System32\\drivers\\etc\\hosts.tmp" else realhostfile = '/tmp/hosts' end # download and modify file with Vagrant-managed entries file = @global_env.tmp_path.join("hosts.#{machine.name}") machine.communicate.download(realhostfile, file) @logger.debug("file is: #{file.to_s}") @logger.debug("class of file is: #{file.class}") if update_file(file, machine, false) if windir machine.communicate.sudo("mv -force /tmp/hosts/hosts.#{machine.name} #{realhostfile}") else machine.communicate.sudo("cat /tmp/hosts >> #{realhostfile}") end end end |