Class: Inspec::Resources::ZfsPool
- Inherits:
-
Object
- Object
- Inspec::Resources::ZfsPool
- Defined in:
- lib/inspec/resources/zfs_pool.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#exists? ⇒ Boolean
method called by ‘it { should exist }’.
- #gather ⇒ Object
-
#initialize(zfs_pool) ⇒ ZfsPool
constructor
A new instance of ZfsPool.
-
#method_missing(name) ⇒ Object
expose all parameters.
- #resource_id ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(zfs_pool) ⇒ ZfsPool
Returns a new instance of ZfsPool.
17 18 19 20 21 22 23 24 25 26 27 |
# 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? || inspec.os.linux? @zfs_pool = zfs_pool find_zpool = inspec.command("which zpool") @zpool_cmd = find_zpool.stdout.strip return skip_resource "zfs is not installed" if find_zpool.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
54 55 56 |
# File 'lib/inspec/resources/zfs_pool.rb', line 54 def method_missing(name) @params[name.to_s] end |
Instance Method Details
#exists? ⇒ Boolean
method called by ‘it { should exist }’
30 31 32 |
# File 'lib/inspec/resources/zfs_pool.rb', line 30 def exists? inspec.command("#{@zpool_cmd} get -Hp all #{@zfs_pool}").exit_status == 0 end |
#gather ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/inspec/resources/zfs_pool.rb', line 42 def gather cmd = inspec.command("#{@zpool_cmd} 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 |
#resource_id ⇒ Object
34 35 36 |
# File 'lib/inspec/resources/zfs_pool.rb', line 34 def resource_id @zfs_pool || "ZFS Pool" end |
#to_s ⇒ Object
38 39 40 |
# File 'lib/inspec/resources/zfs_pool.rb', line 38 def to_s "ZFS Pool #{@zfs_pool}" end |