Class: VagrantPlugins::ManagedServers::Action::DownloadStatus

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-managed-servers/action/download_status.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, _env) ⇒ DownloadStatus

Returns a new instance of DownloadStatus.



7
8
9
10
# File 'lib/vagrant-managed-servers/action/download_status.rb', line 7

def initialize(app, _env)
  @app    = app
  @logger = Log4r::Logger.new("vagrant_managed_servers::action::print_status")
end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
# File 'lib/vagrant-managed-servers/action/download_status.rb', line 12

def call(env)
  download_status(env[:machine], env[:local_file_path], env[:remote_file_path], env[:ui])

  @app.call(env)
end

#download_status(machine, local, remote, ui) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/vagrant-managed-servers/action/download_status.rb', line 18

def download_status(machine, local, remote, ui)
  machine.communicate.wait_for_ready(5)
  @logger.debug("Downloading orchestrate status for #{machine.name}")
  ui.info("Downloading orchestrate status from #{remote}")
  @logger.debug("  remote file: #{remote}")
  @logger.debug("  local file: #{local}")
  machine.communicate.download(remote, local)
  content = File.read(local)
  @logger.debug("File content:")
  @logger.debug(content)
  status = JSON.parse(content)
  ENV["VAGRANT_ORCHESTRATE_STATUS"] += machine.name.to_s + "   " + status["last_sync"] + \
                                       "  " + status["ref"] + "  " + status["user"] + "\n"
rescue => ex
  ui.warn("Error downloading status for #{machine.name}.")
  ui.warn(ex.message)
  ENV["VAGRANT_ORCHESTRATE_STATUS"] += machine.name.to_s + "   Status unavailable.\n"
end