Class: VagrantPlugins::VCenter::Action::ReadSSHInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-vcenter/action/read_ssh_info.rb

Overview

This class reads the IP info for the VM that the Vagrant provider is managing using VMware Tools.

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ ReadSSHInfo

FIXME: More work needed here for vCenter logic (vApp, VM IPs, etc.)



9
10
11
12
# File 'lib/vagrant-vcenter/action/read_ssh_info.rb', line 9

def initialize(app, env)
  @app = app
  @logger = Log4r::Logger.new('vagrant_vcenter::action::read_ssh_info')
end

Instance Method Details

#call(env) ⇒ Object



14
15
16
17
18
# File 'lib/vagrant-vcenter/action/read_ssh_info.rb', line 14

def call(env)
  env[:machine_ssh_info] = read_ssh_info(env)

  @app.call env
end

#read_ssh_info(env) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/vagrant-vcenter/action/read_ssh_info.rb', line 20

def read_ssh_info(env)
  return nil if env[:machine].id.nil?

  config = env[:machine].provider_config
  # FIXME: Raise a correct exception
  dc = config.vcenter_cnx.serviceInstance.find_datacenter(
       config.datacenter_name) or abort 'datacenter not found'
  root_vm_folder = dc.vmFolder
  vm = root_vm_folder.findByUuid(env[:machine].id)

  address = vm.guest.ipAddress
  if not address or address == ''
    address = vm.guest_ip
  end

  if not address or address == ''
    # if we can't find it right away just return nil.  it will retry
    # till the vmware tools supplies the ip address back to vcenter
    @logger.debug('could not find booted guest ipaddress')
    return nil
  end

  @logger.debug("Setting nfs_machine_ip to #{address}")
  env[:nfs_machine_ip] = address

  { :host => address, :port => 22 }
end