Class: Vagrant::IpShow::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-ip-show/command.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.synopsisObject



5
6
7
# File 'lib/vagrant-ip-show/command.rb', line 5

def self.synopsis
    "show all VM ip addresses"
end

Instance Method Details

#executeObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/vagrant-ip-show/command.rb', line 9

def execute
    options = {}
    opts = OptionParser.new do |o|
        o.banner = "Usage: vagrant ip-show [vmname]"
        o.separator ""
        o.separator "Options:"
        o.separator ""
    end

    # Parse the options and return if we don't have any target.
    argv = parse_options(opts)
    return if !argv

    # Execute the actual SSH
    with_target_vms(argv, single_target: true) do |vm|
        @logger.info("Getting ips of vm networks")
        ssh_opts = {extra_args: ['-q']} # make it quiet
        env = vm.action(:ssh_run, ssh_run_command: "ip a | grep 'inet ' | awk '{ print $2}'  | grep -v 127.0.0.1 | cut -d/ -f1", ssh_opts: ssh_opts)
        status = env[:ssh_run_exit_status] || 0
        return status
    end
end