Class: PodmanContainer

Inherits:
Object
  • Object
show all
Includes:
PodmanObject
Defined in:
lib/inspec-podman-resources/resources/podman_container.rb

Instance Method Summary collapse

Methods included from PodmanObject

#exist?, #id

Constructor Details

#initialize(opts = {}) ⇒ PodmanContainer

Returns a new instance of PodmanContainer.



28
29
30
31
32
33
34
35
36
37
# File 'lib/inspec-podman-resources/resources/podman_container.rb', line 28

def initialize(opts = {})
  skip_resource "The `podman_container` resource is not yet available on your OS." unless inspec.os.unix?

  # 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

#commandObject



55
56
57
58
59
# File 'lib/inspec-podman-resources/resources/podman_container.rb', line 55

def command
  return unless object_info.entries.length == 1

  object_info.commands[0]
end

#imageObject



61
62
63
# File 'lib/inspec-podman-resources/resources/podman_container.rb', line 61

def image
  object_info.images[0] if object_info.entries.length == 1
end

#labelsObject



47
48
49
# File 'lib/inspec-podman-resources/resources/podman_container.rb', line 47

def labels
  object_info.labels
end

#portsObject



51
52
53
# File 'lib/inspec-podman-resources/resources/podman_container.rb', line 51

def ports
  object_info.ports[0] if object_info.entries.length == 1
end

#resource_idObject



65
66
67
# File 'lib/inspec-podman-resources/resources/podman_container.rb', line 65

def resource_id
  object_info.ids[0] || @opts[:id] || @opts[:name] || ""
end

#running?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/inspec-podman-resources/resources/podman_container.rb', line 39

def running?
  status.downcase.start_with?("up") if object_info.entries.length == 1
end

#statusObject



43
44
45
# File 'lib/inspec-podman-resources/resources/podman_container.rb', line 43

def status
  object_info.status[0] if object_info.entries.length == 1
end

#to_sObject



69
70
71
72
# File 'lib/inspec-podman-resources/resources/podman_container.rb', line 69

def to_s
  name = @opts[:name] || @opts[:id]
  "Podman Container #{name}"
end