class Inspec::Resources::ZfsDataset

Public Class Methods

new(zfs_dataset) click to toggle source
# File lib/inspec/resources/zfs_dataset.rb, line 18
def initialize(zfs_dataset)
  return skip_resource "The `zfs_dataset` resource is not supported on your OS yet." unless inspec.os.bsd? || inspec.os.linux?

  @zfs_dataset = zfs_dataset
  find_zfs = inspec.command("which zfs")
  @zfs_cmd = find_zfs.stdout.strip

  return skip_resource "zfs is not installed" if find_zfs.exit_status != 0

  @params = gather
end

Public Instance Methods

exec() click to toggle source

override method

# File lib/inspec/resources/zfs_dataset.rb, line 57
def exec
  @params["exec"]
end
exists?() click to toggle source

method called by 'it { should exist }'

# File lib/inspec/resources/zfs_dataset.rb, line 31
def exists?
  inspec.command("#{@zfs_cmd} get -Hp all #{@zfs_dataset}").exit_status == 0
end
gather() click to toggle source
# File lib/inspec/resources/zfs_dataset.rb, line 45
def gather
  cmd = inspec.command("#{@zfs_cmd} get -Hp all #{@zfs_dataset}")
  return nil if cmd.exit_status.to_i != 0

  # parse data
  cmd.stdout.chomp.split("\n").each_with_object(Hash.new(0)) do |line, h|
    t = line.split("\t")
    h[t[1].to_s] = t[2].to_s
  end
end
method_missing(name) click to toggle source

expose all parameters

# File lib/inspec/resources/zfs_dataset.rb, line 62
def method_missing(name)
  @params[name.to_s]
end
mounted?() click to toggle source
# File lib/inspec/resources/zfs_dataset.rb, line 35
def mounted?
  return false unless exists?

  inspec.mount(@params["mountpoint"]).mounted?
end
to_s() click to toggle source
# File lib/inspec/resources/zfs_dataset.rb, line 41
def to_s
  "ZFS Dataset #{@zfs_dataset}"
end