Class: Inspec::Resources::PodmanNetwork

Inherits:
Object
  • Object
show all
Includes:
Utils::Podman
Defined in:
lib/inspec/resources/podman_network.rb

Constant Summary collapse

LABELS =
{
  id: "ID",
  name: "Name",
  driver: "Driver",
  labels: "Labels",
  options: "Options",
  ipam_options: "IPAMOptions",
  internal: "Internal",
  created: "Created",
  ipv6_enabled: "IPv6Enabled",
  dns_enabled: "DNSEnabled",
  network_interface: "NetworkInterface",
  subnets: "Subnets",
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::Podman

#generate_go_template, #parse_command_output, #podman_running?

Constructor Details

#initialize(param) ⇒ PodmanNetwork

Returns a new instance of PodmanNetwork.



38
39
40
41
42
43
44
45
# File 'lib/inspec/resources/podman_network.rb', line 38

def initialize(param)
  skip_resource "The `podman_network` resource is not yet available on your OS." unless inspec.os.unix?

  @param = param
  raise Inspec::Exceptions::ResourceFailed, "Podman is not running. Please make sure it is installed and running." unless podman_running?

  @network_info = get_network_info
end

Instance Attribute Details

#network_infoObject (readonly)

Returns the value of attribute network_info.



37
38
39
# File 'lib/inspec/resources/podman_network.rb', line 37

def network_info
  @network_info
end

#paramObject (readonly)

Returns the value of attribute param.



37
38
39
# File 'lib/inspec/resources/podman_network.rb', line 37

def param
  @param
end

Instance Method Details

#exist?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/inspec/resources/podman_network.rb', line 54

def exist?
  !network_info.empty?
end

#kObject

This creates all the required properties methods dynamically.



48
49
50
51
52
# File 'lib/inspec/resources/podman_network.rb', line 48

LABELS.each do |k, v|
  define_method(k) do
    network_info[k.to_s]
  end
end

#resource_idObject



58
59
60
# File 'lib/inspec/resources/podman_network.rb', line 58

def resource_id
  id || param || ""
end

#to_sObject



62
63
64
# File 'lib/inspec/resources/podman_network.rb', line 62

def to_s
  "podman_network #{resource_id}"
end