Class: Inspec::Resources::ZfsDataset
- Inherits:
-
Object
- Object
- Inspec::Resources::ZfsDataset
- Defined in:
- lib/inspec/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
- #resource_id ⇒ Object
- #to_s ⇒ Object
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
#exec ⇒ Object
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 }’
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 |
#gather ⇒ Object
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
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_id ⇒ Object
41 42 43 |
# File 'lib/inspec/resources/zfs_dataset.rb', line 41 def resource_id @zfs_dataset || "ZFS Dataset" end |
#to_s ⇒ Object
45 46 47 |
# File 'lib/inspec/resources/zfs_dataset.rb', line 45 def to_s "ZFS Dataset #{@zfs_dataset}" end |