Sha256: eeedc73856e0e638c957a078a79804702e4272c1b012601e3a9e5f97726afbd4

Contents?: true

Size: 1.48 KB

Versions: 39

Compression:

Stored size: 1.48 KB

Contents

require 'json'

class PEBuild::Command::Facts < Vagrant.plugin(2, :command)

  def self.synopsis
    'Load facts from running VMs'
  end

  def execute
    argv = parse_options(parser)
    argv.shift # Remove 'facts' subcommand.

    running = @env.active_machines.map do |name, provider|
      @env.machine(name, provider)
    end.select do |vm|
      begin
        vm.communicate.ready?
      rescue Vagrant::Errors::VagrantError
        # WinRM will raise an error if the VM isn't running instead of
        # returning false (GH-6356).
        false
      end
    end

    # Filter the list of VMs for inspection down to just those passed on the
    # command line. Warn if the user passed a VM that was not running.
    unless argv.empty?
      running_vms = running.map {|vm| vm.name.to_s}
      argv.each do |name|
        @env.ui.warn I18n.t('pebuild.command.facts.vm_not_running', :vm_name => name) unless running_vms.include? name
      end

      running.select! {|vm| argv.include? vm.name.to_s}
    end

    running.each do |vm|
      facts = vm.guest.capability(:pebuild_facts)

      @env.ui.machine('guest-facts', facts, {:target => vm.name.to_s})
      @env.ui.info(JSON.pretty_generate(facts))
    end

    return 0
  end

  private

  def parser
    OptionParser.new do |o|
      o.banner = <<-BANNER
      Usage: vagrant pe-build facts [vm-name]
      BANNER

      o.separator ''

      o.on('-h', '--help', 'Display this help') do
        puts o
        exit(0)
      end
    end
  end

end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
vagrant-pe_build-0.19.2 lib/pe_build/command/facts.rb
vagrant-pe_build-0.19.1 lib/pe_build/command/facts.rb
vagrant-pe_build-0.19.0 lib/pe_build/command/facts.rb
vagrant-pe_build-0.18.2 lib/pe_build/command/facts.rb
vagrant-pe_build-0.18.1 lib/pe_build/command/facts.rb
vagrant-pe_build-0.18.0 lib/pe_build/command/facts.rb
vagrant-pe_build-0.17.14 lib/pe_build/command/facts.rb
vagrant-pe_build-0.17.13 lib/pe_build/command/facts.rb
vagrant-pe_build-0.17.12 lib/pe_build/command/facts.rb
vagrant-pe_build-0.17.11 lib/pe_build/command/facts.rb
vagrant-pe_build-0.17.10 lib/pe_build/command/facts.rb
vagrant-pe_build-0.17.9 lib/pe_build/command/facts.rb
vagrant-pe_build-0.17.8 lib/pe_build/command/facts.rb
vagrant-pe_build-0.17.7 lib/pe_build/command/facts.rb
vagrant-pe_build-0.17.6 lib/pe_build/command/facts.rb
vagrant-pe_build-0.17.5 lib/pe_build/command/facts.rb
vagrant-pe_build-0.17.4 lib/pe_build/command/facts.rb
vagrant-pe_build-0.17.3 lib/pe_build/command/facts.rb
vagrant-pe_build-0.17.2 lib/pe_build/command/facts.rb
vagrant-pe_build-0.17.1 lib/pe_build/command/facts.rb