Class: Inspec::Resources::DockerContainer
- Inherits:
-
Object
- Object
- Inspec::Resources::DockerContainer
- Defined in:
- lib/resources/docker_container.rb
Instance Method Summary collapse
- #command ⇒ Object
- #exist? ⇒ Boolean
-
#id ⇒ Object
is allways returning the full id.
- #image ⇒ Object
-
#initialize(opts = {}) ⇒ DockerContainer
constructor
A new instance of DockerContainer.
- #labels ⇒ Object
- #ports ⇒ Object
- #repo ⇒ Object
- #running? ⇒ Boolean
- #status ⇒ Object
- #tag ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ DockerContainer
Returns a new instance of DockerContainer.
31 32 33 34 35 36 37 38 |
# File 'lib/resources/docker_container.rb', line 31 def initialize(opts = {}) # if a string is provided, we expect it is the name if opts.is_a?(String) @opts = { name: opts } else @opts = opts end end |
Instance Method Details
#command ⇒ Object
65 66 67 68 69 70 |
# File 'lib/resources/docker_container.rb', line 65 def command if container_info.entries.length == 1 cmd = container_info.commands[0] cmd.slice(1, cmd.length - 2) end end |
#exist? ⇒ Boolean
40 41 42 |
# File 'lib/resources/docker_container.rb', line 40 def exist? container_info.exists? end |
#id ⇒ Object
is allways returning the full id
45 46 47 |
# File 'lib/resources/docker_container.rb', line 45 def id container_info.ids[0] if container_info.entries.length == 1 end |
#image ⇒ Object
72 73 74 |
# File 'lib/resources/docker_container.rb', line 72 def image container_info.images[0] if container_info.entries.length == 1 end |
#labels ⇒ Object
57 58 59 |
# File 'lib/resources/docker_container.rb', line 57 def labels container_info.labels[0] if container_info.entries.length == 1 end |
#ports ⇒ Object
61 62 63 |
# File 'lib/resources/docker_container.rb', line 61 def ports container_info.ports[0] if container_info.entries.length == 1 end |
#repo ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'lib/resources/docker_container.rb', line 76 def repo return if image.nil? || image_name_from_image.nil? if image.include?('/') # host:port/ubuntu:latest repo_part, image_part = image.split('/') # host:port, ubuntu:latest repo_part + '/' + image_part.split(':')[0] # host:port + / + ubuntu else image_name_from_image.split(':')[0] end end |
#running? ⇒ Boolean
49 50 51 |
# File 'lib/resources/docker_container.rb', line 49 def running? status.downcase.start_with?('up') if container_info.entries.length == 1 end |
#status ⇒ Object
53 54 55 |
# File 'lib/resources/docker_container.rb', line 53 def status container_info.status[0] if container_info.entries.length == 1 end |
#tag ⇒ Object
86 87 88 89 |
# File 'lib/resources/docker_container.rb', line 86 def tag return if image_name_from_image.nil? image_name_from_image.split(':')[1] end |
#to_s ⇒ Object
91 92 93 94 |
# File 'lib/resources/docker_container.rb', line 91 def to_s name = @opts[:name] || @opts[:id] "Docker Container #{name}" end |