Class: Inspec::Resources::ZfsDataset

Inherits:
Object
  • Object
show all
Defined in:
lib/inspec/resources/zfs_dataset.rb

Instance Method Summary collapse

Constructor Details

#initialize(zfs_dataset) ⇒ ZfsDataset

Returns a new instance of ZfsDataset.



18
19
20
21
22
23
24
25
26
27
28
# 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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object

expose all parameters



66
67
68
# File 'lib/inspec/resources/zfs_dataset.rb', line 66

def method_missing(name)
  @params[name.to_s]
end

Instance Method Details

#execObject

override method



61
62
63
# File 'lib/inspec/resources/zfs_dataset.rb', line 61

def exec
  @params["exec"]
end

#exists?Boolean

method called by ‘it { should exist }’

Returns:

  • (Boolean)


31
32
33
# File 'lib/inspec/resources/zfs_dataset.rb', line 31

def exists?
  inspec.command("#{@zfs_cmd} get -Hp all #{@zfs_dataset}").exit_status == 0
end

#gatherObject



49
50
51
52
53
54
55
56
57
58
# File 'lib/inspec/resources/zfs_dataset.rb', line 49

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

#mounted?Boolean

Returns:

  • (Boolean)


35
36
37
38
39
# File 'lib/inspec/resources/zfs_dataset.rb', line 35

def mounted?
  return false unless exists?

  inspec.mount(@params["mountpoint"]).mounted?
end

#resource_idObject



41
42
43
# File 'lib/inspec/resources/zfs_dataset.rb', line 41

def resource_id
  @zfs_dataset || "ZFS Dataset"
end

#to_sObject



45
46
47
# File 'lib/inspec/resources/zfs_dataset.rb', line 45

def to_s
  "ZFS Dataset #{@zfs_dataset}"
end