Skip to content

Commit

Permalink
added parse ip and parsed ip set to :hostname.
Browse files Browse the repository at this point in the history
  • Loading branch information
inokappa committed Nov 24, 2013
1 parent 45ed501 commit c4afe9d
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion lib/kitchen/driver/docker.rb
Expand Up @@ -60,8 +60,10 @@ def default_platform
def create(state)
state[:image_id] = build_image(state) unless state[:image_id]
state[:container_id] = run_container(state) unless state[:container_id]
state[:hostname] = remote_socket? ? socket_uri.host : 'localhost'
state[:port] = container_ssh_port(state)
state[:ip] = container_ssh_ip(state)
state[:hostname] = remote_socket? ? socket_uri.host : state[:ip]
wait_for_sshd(state[:hostname], :port => state[:port])
end

def destroy(state)
Expand Down Expand Up @@ -185,6 +187,23 @@ def container_ssh_port(state)
parse_container_ssh_port(output)
end

def parse_container_ssh_ip(output)
begin
info = Array(::JSON.parse(output)).first
ip = info['NetworkSettings']['Gateway']
ip.to_s
rescue
raise ActionFailed,
'Could not parse Docker inspect output for container SSH ipaddress.'
end
end

def container_ssh_ip(state)
container_id = state[:container_id]
output = docker_command("inspect #{container_id}")
parse_container_ssh_ip(output)
end

def rm_container(state)
container_id = state[:container_id]
docker_command("stop #{container_id}")
Expand Down

0 comments on commit c4afe9d

Please sign in to comment.