Class: VagrantPlugins::WinAzure::Action::ReadSSHInfo

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

Instance Method Summary collapse

Constructor Details

#initialize(app, env, port = 22) ⇒ ReadSSHInfo

Returns a new instance of ReadSSHInfo.



12
13
14
15
16
# File 'lib/vagrant-azure/action/read_ssh_info.rb', line 12

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

Instance Method Details

#call(env) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/vagrant-azure/action/read_ssh_info.rb', line 18

def call(env)
  env[:ui].detail "Looking for local port #{@port}"

  env[:machine_ssh_info] = read_ssh_info(
    env[:azure_vm_service],
    env[:machine]
  )

  env[:ui].detail "Found port mapping #{env[:machine_ssh_info][:port]} --> #{@port}"

  @app.call(env)
end

#read_ssh_info(azure, machine) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/vagrant-azure/action/read_ssh_info.rb', line 31

def read_ssh_info(azure, machine)
  return nil if machine.id.nil?
  machine.id =~ /@/
  vm = azure.get_virtual_machine($`, $')

  if vm.nil? || !vm.instance_of?(Azure::VirtualMachineManagement::VirtualMachine)
    # Machine cannot be found
    @logger.info 'Machine not found. Assuming it was destroyed'
    machine.id = nil
    return nil
  end

  vm.tcp_endpoints.each do |endpoint|
    if endpoint[:local_port] == "#{@port}"
      return { :host => "#{vm.cloud_service_name}.cloudapp.net", :port => endpoint[:public_port] }
    end
  end

  return nil
end