Class: Inspec::Resources::ZfsDataset
- Inherits:
-
Object
- Object
- Inspec::Resources::ZfsDataset
- Defined in:
- lib/resources/zfs_dataset.rb
Instance Method Summary collapse
-
#exec ⇒ Object
override method.
-
#exists? ⇒ Boolean
method called by ‘it { should exist }’.
- #gather ⇒ Object
-
#initialize(zfs_dataset) ⇒ ZfsDataset
constructor
A new instance of ZfsDataset.
-
#method_missing(name) ⇒ Object
expose all parameters.
- #mounted? ⇒ Boolean
- #to_s ⇒ Object
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
#exec ⇒ Object
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 }’
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 |
#gather ⇒ Object
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
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_s ⇒ Object
35 36 37 |
# File 'lib/resources/zfs_dataset.rb', line 35 def to_s "ZFS Dataset #{@zfs_dataset}" end |