Skip to content

Instantly share code, notes, and snippets.

@ianneub
Forked from kareemk/dssh
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ianneub/c9ae1788f63747d8d5f0 to your computer and use it in GitHub Desktop.
Save ianneub/c9ae1788f63747d8d5f0 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'net/http'
require 'json'
raise "Invalid arguments: dssh [container-name] [command=/bin/bash]" if ARGV.length < 1
service_name = "#{ARGV[0]}"
ARGV[1] ||= "/bin/bash"
command = ARGV[1..-1].join(' ')
uri = URI.parse("https://dashboard.tutum.co")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
headers = { "Authorization" => ENV['TUTUM_AUTH'] }
# Get list of containers that match
container = "#{service_name}-1"
response = http.get("/api/v1/container/?name=#{container}", headers)
if response.code == "200"
container_info = JSON.load(response.body)["objects"].first
if container_info
dns = container_info["public_dns"]
docker_id = container_info["docker_id"]
exec "ssh -t #{dns} sudo docker exec -i -t #{docker_id} '#{command}'"
else
puts "No conatiner found"
exit 1
end
else
puts "Error accessing tutum: #{response.body}"
exit 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment