Class: VMCTunnel::Tunnel

Inherits:
VMC::CLI
  • Object
show all
Defined in:
lib/tunnel-vmc-plugin/plugin.rb

Constant Summary collapse

CLIENTS_FILE =
"#{VMC::CONFIG_DIR}/tunnel-clients.yml"
STOCK_CLIENTS =
File.expand_path("../../../config/clients.yml", __FILE__)

Instance Method Summary collapse

Instance Method Details

#tunnelObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/tunnel-vmc-plugin/plugin.rb', line 27

def tunnel
  instances = client.service_instances
  fail "No services available for tunneling." if instances.empty?

  instance = input[:instance, instances.sort_by(&:name)]
  vendor = v2? ? instance.service_plan.service.label : instance.vendor
  clients = tunnel_clients[vendor] || {}
  client_name = input[:client, clients]

  tunnel = CFTunnel.new(client, instance)
  port = tunnel.pick_port!(input[:port])

  conn_info =
    with_progress("Opening tunnel on port #{c(port, :name)}") do
      tunnel.open!
    end

  if client_name == "none"
    unless quiet?
      line
      display_tunnel_connection_info(conn_info)

      line
      line "Open another shell to run command-line clients or"
      line "use a UI tool to connect using the displayed information."
      line "Press Ctrl-C to exit..."
    end

    tunnel.wait_for_end
  else
    with_progress("Waiting for local tunnel to become available") do
      tunnel.wait_for_start
    end

    unless start_local_prog(clients, client_name, conn_info, port)
      fail "'#{client_name}' execution failed; is it in your $PATH?"
    end
  end
end

#tunnel_clientsObject



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/tunnel-vmc-plugin/plugin.rb', line 67

def tunnel_clients
  return @tunnel_clients if @tunnel_clients
  stock_config = YAML.load_file(STOCK_CLIENTS)
  custom_config_file = File.expand_path(CLIENTS_FILE)
  if File.exists?(custom_config_file)
    custom_config = YAML.load_file(custom_config_file)
    @tunnel_clients = deep_merge(stock_config, custom_config)
  else
    @tunnel_clients = stock_config
  end
end