Class: Centurion::DockerServer
- Inherits:
-
Object
- Object
- Centurion::DockerServer
show all
- Extended by:
- Forwardable
- Includes:
- Logging
- Defined in:
- lib/centurion/docker_server.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Logging
#debug, #error, #info, #warn
Constructor Details
#initialize(host, docker_path, tls_params = {}) ⇒ DockerServer
Returns a new instance of DockerServer.
21
22
23
24
25
26
|
# File 'lib/centurion/docker_server.rb', line 21
def initialize(host, docker_path, tls_params = {})
@docker_path = docker_path
@hostname, @port = host.split(':')
@port ||= '2375'
@tls_params = tls_params
end
|
Instance Attribute Details
#hostname ⇒ Object
Returns the value of attribute hostname.
14
15
16
|
# File 'lib/centurion/docker_server.rb', line 14
def hostname
@hostname
end
|
#port ⇒ Object
Returns the value of attribute port.
14
15
16
|
# File 'lib/centurion/docker_server.rb', line 14
def port
@port
end
|
Instance Method Details
28
29
30
31
32
33
|
# File 'lib/centurion/docker_server.rb', line 28
def current_tags_for(image)
running_containers = ps.select { |c| c['Image'] =~ /#{image}/ }
return [] if running_containers.empty?
parse_image_tags_for(running_containers)
end
|
#find_container_by_id(container_id) ⇒ Object
53
54
55
|
# File 'lib/centurion/docker_server.rb', line 53
def find_container_by_id(container_id)
ps.find { |container| container && container['Id'] == container_id }
end
|
#find_containers_by_name(wanted_name) ⇒ Object
44
45
46
47
48
49
50
51
|
# File 'lib/centurion/docker_server.rb', line 44
def find_containers_by_name(wanted_name)
ps.select do |container|
next unless container && container['Names']
container['Names'].find do |name|
name =~ /\A\/#{wanted_name}(-[a-f0-9]{14})?\Z/
end
end
end
|
#find_containers_by_public_port(public_port, type = 'tcp') ⇒ Object
35
36
37
38
39
40
41
42
|
# File 'lib/centurion/docker_server.rb', line 35
def find_containers_by_public_port(public_port, type='tcp')
ps.select do |container|
next unless container && container['Ports']
container['Ports'].find do |port|
port['PublicPort'] == public_port.to_i && port['Type'] == type
end
end
end
|
#old_containers_for_name(wanted_name) ⇒ Object
57
58
59
60
61
|
# File 'lib/centurion/docker_server.rb', line 57
def old_containers_for_name(wanted_name)
find_containers_by_name(wanted_name).select do |container|
container["Status"] =~ /^(Exit |Exited)/
end
end
|