class ShipyardClient::Shipyard

Attributes

host[RW]
service_key[RW]

Public Class Methods

new(host, service_key) click to toggle source
# File lib/shipyard_client.rb, line 8
def initialize(host, service_key)
  @host = host
  @service_key = service_key
end

Public Instance Methods

create_container(image, options) click to toggle source
# File lib/shipyard_client.rb, line 19
def create_container(image, options)
  create_template = {
    AttachStdin: false,
    CpuShares: nil,
    Env: [],
    Cmd: [],
    ExposedPorts: {},
    HostConfig: {
      Binds: [],
      Links: [],
      PortBindings: {},
      Privileged: false,
      PublishAllPorts: false,
      RestartPolicy: {
        Name: 'no'
      }
    },
    Image: '',
    Links: [],
    Memory: nil,
    Tty: true,
    Volumes: {}
  }
  create_template[:Image] = image
  create_template.merge!(options)
  res = HTTP.headers('X-Service-Key' => @service_key)
            .post("#{host}/containers/create?name=",
                  json: create_template)
  handle_response(res)
end
inspect_container(id) click to toggle source
# File lib/shipyard_client.rb, line 50
def inspect_container(id)
  res = HTTP.headers('X-Service-Key' => @service_key)
            .get("#{host}/containers/#{id}/json")
  handle_response(res)
end
list_containers() click to toggle source
# File lib/shipyard_client.rb, line 13
def list_containers
  res = HTTP.headers('X-Service-Key' => @service_key)
            .get("#{host}/containers/json")
  handle_response(res)
end
remove_container(id) click to toggle source
# File lib/shipyard_client.rb, line 56
def remove_container(id)
  res = HTTP.headers('X-Service-Key' => @service_key)
            .delete("#{host}/containers/#{id}?force=1")
  handle_response(res)
end
restart_container(id) click to toggle source
# File lib/shipyard_client.rb, line 74
def restart_container(id)
  res = HTTP.headers('X-Service-Key' => @service_key)
            .post("#{host}/containers/#{id}/restart")
  handle_response(res)
end
start_container(id) click to toggle source
# File lib/shipyard_client.rb, line 62
def start_container(id)
  res = HTTP.headers('X-Service-Key' => @service_key)
            .post("#{host}/containers/#{id}/start")
  handle_response(res)
end
stop_container(id) click to toggle source
# File lib/shipyard_client.rb, line 68
def stop_container(id)
  res = HTTP.headers('X-Service-Key' => @service_key)
            .post("#{host}/containers/#{id}/stop")
  handle_response(res)
end

Private Instance Methods

handle_response(res) click to toggle source
# File lib/shipyard_client.rb, line 82
def handle_response(res)
  if res.code < 200 || res.code >= 300
    raise "FAILED with status code: #{res.code} #{res}"
  end
  # Do not parse JSON if there is no content
  res.code == 204 ? nil : JSON.load(res.to_s)
end