Class: Inspec::Resources::ZfsPool

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

Instance Method Summary collapse

Constructor Details

#initialize(zfs_pool) ⇒ ZfsPool

Returns a new instance of ZfsPool.



17
18
19
20
21
22
23
# File 'lib/inspec/resources/zfs_pool.rb', line 17

def initialize(zfs_pool)
  return skip_resource "The `zfs_pool` resource is not supported on your OS yet." unless inspec.os.bsd?

  @zfs_pool = zfs_pool

  @params = gather
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object

expose all parameters



46
47
48
# File 'lib/inspec/resources/zfs_pool.rb', line 46

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

Instance Method Details

#exists?Boolean

method called by ‘it { should exist }’

Returns:

  • (Boolean)


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

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

#gatherObject



34
35
36
37
38
39
40
41
42
43
# File 'lib/inspec/resources/zfs_pool.rb', line 34

def gather
  cmd = inspec.command("/sbin/zpool get -Hp all #{@zfs_pool}")
  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

#to_sObject



30
31
32
# File 'lib/inspec/resources/zfs_pool.rb', line 30

def to_s
  "ZFS Pool #{@zfs_pool}"
end