class Dockerlib::Remote::Client

Public Class Methods

new(socket: nil) click to toggle source
# File lib/dockerlib/remote/client.rb, line 4
def initialize(socket: nil)
  @socket = socket || '/var/run/docker.sock'
end

Public Instance Methods

containers(all: true) click to toggle source
# File lib/dockerlib/remote/client.rb, line 30
def containers(all: true)
  get('/containers/json'.tap {|path|
    path << "?all=1" if all
  })
end
get(path) click to toggle source
# File lib/dockerlib/remote/client.rb, line 36
def get(path)
  resp = connection.request(method: :get, path: path)
  if resp.status == 200
    {data: load_body(resp)}
  else
    to_server_error resp
  end
end
inspect_container(name) click to toggle source
# File lib/dockerlib/remote/client.rb, line 19
def inspect_container(name)
  resp = connection.request(method: :get, path: "/containers/#{name}/json")
  if resp.status == 200
    {data: load_body(resp)}
  elsif resp.status == 404
    {code: :no_such_container}
  else
    to_server_error resp
  end
end
inspect_image(name) click to toggle source
# File lib/dockerlib/remote/client.rb, line 8
def inspect_image(name)
  resp = connection.request(method: :get, path: "/images/#{name}/json")
  if resp.status == 200
    {data: load_body(resp)}
  elsif resp.status == 404
    {code: :no_such_image}
  else
    to_server_error resp
  end
end

Protected Instance Methods

connection() click to toggle source
# File lib/dockerlib/remote/client.rb, line 47
def connection
  Excon.new('unix:///', socket: @socket)
end
load_body(resp) click to toggle source
# File lib/dockerlib/remote/client.rb, line 51
def load_body(resp)
  JSON.load(resp.body)
end
to_server_error(resp) click to toggle source
# File lib/dockerlib/remote/client.rb, line 55
def to_server_error(resp)
  {error: :server_error, data: {http_status: resp.status,
                                http_body: resp.body}}
end