Class: Inspec::Resources::ZfsDataset

Inherits:
Object
  • Object
show all
Defined in:
lib/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
# File 'lib/resources/zfs_dataset.rb', line 18

def initialize(zfs_dataset)
  return skip_resource 'The `zfs_dataset` resource is not supported on your OS yet.' if !inspec.os.bsd?
  @zfs_dataset = zfs_dataset

  @params = gather
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object

expose all parameters



56
57
58
# File 'lib/resources/zfs_dataset.rb', line 56

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

Instance Method Details

#execObject

override method



51
52
53
# File 'lib/resources/zfs_dataset.rb', line 51

def exec
  @params['exec']
end

#exists?Boolean

method called by ‘it { should exist }’

Returns:

  • (Boolean)


26
27
28
# File 'lib/resources/zfs_dataset.rb', line 26

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

#gatherObject



39
40
41
42
43
44
45
46
47
48
# File 'lib/resources/zfs_dataset.rb', line 39

def gather
  cmd = inspec.command("/sbin/zfs 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)


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

def mounted?
  return false if !exists?
  inspec.mount(@params['mountpoint']).mounted?
end

#to_sObject



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

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