Class: DockerHost
- Inherits:
-
Object
show all
- Extended by:
- HTTPUtils
- Defined in:
- lib/panteras_api/docker_host.rb
Defined Under Namespace
Classes: MesosConsulCommandError
Class Method Summary
collapse
Methods included from HTTPUtils
construct_uri, get_response_with_redirect, to_j, valid_url
Class Method Details
.inspect(*keys) ⇒ Object
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/panteras_api/docker_host.rb', line 22
def self.inspect(*keys)
containers = self.running_containers
containers.map do |c|
inspect = self.command("docker inspect #{c[:container_id]}")[:output]
h = to_j(inspect.join).first
task_id = h[:Config][:Env].select { |env| env.upcase =~ /MESOS_TASK_ID=/ }.first
mesos_task_id = task_id.nil? ? '' : task_id.split(/=/)[1]
{ id: h[:Id], image: h[:Image], name: h[:Name][1..-1], mesos_task_id: mesos_task_id, chronos_job: h[:Config][:Env].join(',').include?('CHRONOS_JOB_NAME=') ? true : false }
end
end
|
.inspect_partial ⇒ Object
33
34
35
|
# File 'lib/panteras_api/docker_host.rb', line 33
def self.inspect_partial
self.inspect
end
|
.ps ⇒ Object
6
7
8
9
10
|
# File 'lib/panteras_api/docker_host.rb', line 6
def self.ps
output = self.command("docker ps")[:output]
raise MesosConsulCommandError, "Command 'docker ps' did not return an array of strings" if (output.class != Array || output.length == 0)
return output
end
|
.running_containers ⇒ Object
12
13
14
15
16
17
18
19
20
|
# File 'lib/panteras_api/docker_host.rb', line 12
def self.running_containers
output = self.ps
result = output.map.with_index do |line, i|
next if i == 0
container_id, image, *center, name = line.split
{ container_id: container_id, name: name, image: image }
end
return result.compact
end
|