Permalink
Browse files

[finished #46764681] Tunnel director and agent connections through SS…

…H for deployer
  • Loading branch information...
1 parent 140ab42 commit af80b4300f510c32df392d3105d85332b5046efa Alex Jackson and Vinicius Fuentes committed with Jeffrey Peckham and Vinicius Fuentes Apr 2, 2013
@@ -73,7 +73,8 @@ def cloud
def agent
uri = URI.parse(@cloud_options["properties"]["agent"]["mbus"])
- uri.host = bosh_ip
+ # We connect through a local SSH tunnel
+ uri.host = "127.0.0.1"
user, password = uri.userinfo.split(":", 2)
uri.userinfo = nil
Bosh::Agent::HTTPClient.new(uri.to_s,
@@ -407,13 +407,25 @@ def wait_until_ready(component, wait_time = 1, retries = 300)
end
end
+ def agent_port
+ uri = URI.parse(Config.cloud_options["properties"]["agent"]["mbus"])
+
+ uri.port
+ end
+
def wait_until_agent_ready #XXX >> agent_client
+ incoming_tunnel(@registry_port)
+ outgoing_tunnel(agent_port)
+
wait_until_ready("agent") { agent.ping }
end
def wait_until_director_ready
port = @apply_spec.director_port
- url = "http://#{bosh_ip}:#{port}/info"
+
+ outgoing_tunnel(port)
+
+ url = "http://127.0.0.1:#{port}/info"
wait_until_ready("director") do
info = Yajl::Parser.parse(HTTPClient.new.get(url).body)
logger.info("Director is ready: #{info.inspect}")
@@ -120,11 +120,6 @@ def stop
@registry_db.unlink if @registry_db
end
- def wait_until_agent_ready
- tunnel(@registry_port)
- super
- end
-
def discover_bosh_ip
if exists?
# choose elastic IP over public, as any agent connecting to the
@@ -120,11 +120,6 @@ def stop
@registry_db.unlink if @registry_db
end
- def wait_until_agent_ready
- tunnel(@registry_port)
- super
- end
-
def discover_bosh_ip
if exists?
server = cloud.openstack.servers.get(state.vm_cid)
@@ -35,8 +35,19 @@ def socket_readable?(ip, port)
socket.close if socket
end
- def tunnel(port)
- return if @session
+ def incoming_tunnel(port)
+ tunnel(port, :incoming)
+ end
+
+ def outgoing_tunnel(port)
+ tunnel(port, :outgoing)
+ end
+
+ private
+
+ def tunnel(port, direction)
+ @established_sessions ||= {}
+ return if @session && @established_sessions[port]
ip = discover_bosh_ip
@@ -59,9 +70,16 @@ def tunnel(port)
logger.debug("ssh start #{@ssh_user}@#{ip} failed: #{e.inspect}")
sleep 1
end
+ end unless @session
+
+ if direction == :incoming
+ @session.forward.remote(port, lo, port)
+ elsif direction == :outgoing
+ @session.forward.local(port, lo, port)
end
- @session.forward.remote(port, lo, port)
+ @established_sessions[port] = true
+
logger.info("`#{cmd}` started: OK")
Thread.new do

0 comments on commit af80b43

Please sign in to comment.