Class: ShipyardClient::Shipyard

Inherits:
Object
  • Object
show all
Defined in:
lib/shipyard_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, service_key) ⇒ Shipyard

Returns a new instance of Shipyard.



8
9
10
11
# File 'lib/shipyard_client.rb', line 8

def initialize(host, service_key)
  @host = host
  @service_key = service_key
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



7
8
9
# File 'lib/shipyard_client.rb', line 7

def host
  @host
end

#service_keyObject

Returns the value of attribute service_key.



7
8
9
# File 'lib/shipyard_client.rb', line 7

def service_key
  @service_key
end

Instance Method Details

#create_container(image, options) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# 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) ⇒ Object



50
51
52
53
54
# 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_containersObject



13
14
15
16
17
# 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) ⇒ Object



56
57
58
59
60
# 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) ⇒ Object



74
75
76
77
78
# 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) ⇒ Object



62
63
64
65
66
# 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) ⇒ Object



68
69
70
71
72
# 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