Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions lib/vSphere/command/ip_status.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
require 'optparse'

module VagrantPlugins
module VSphere
module Command
class IpStatus < Vagrant.plugin('2', :command)
def execute
opts = OptionParser.new do |o|
o.banner = 'Usage: vagrant ip-status [name]'
end

argv = parse_options(opts)
return unless argv

@env.ui.info('Current machine states with IP addresses:')
@env.ui.info('')
@env.ui.info(format('%-25s %-15s %s', 'Name', 'State', 'IP Address'))

with_target_vms(argv, single_target: false) do |machine|
state = machine.state
ip = ip_address_for(machine)

@env.ui.info(format(
'%-25s %-15s %s',
machine.name.to_s,
state.short_description.to_s,
ip || '-'
))
end

0
end

private

def ip_address_for(machine)
return nil unless machine.provider_name.to_s == 'vsphere'
return nil if machine.state.id == :not_created

ssh_info = machine.ssh_info
return nil if ssh_info.nil?

ssh_info[:host]
rescue StandardError
nil
end
end
end
end
end
5 changes: 5 additions & 0 deletions lib/vSphere/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ class Plugin < Vagrant.plugin('2')
Provider
end

command('ip-status') do
require_relative 'command/ip_status'
Command::IpStatus
end

provider_capability('vsphere', 'public_address') do
require_relative 'cap/public_address'
Cap::PublicAddress
Expand Down