Class: OsCtl::Lib::Zfs::PropertyReader

Inherits:
Object
  • Object
show all
Includes:
Utils::Log, Utils::System
Defined in:
lib/libosctl/zfs/property_reader.rb

Overview

Read selected dataset properties into DatasetTree

Instance Method Summary collapse

Methods included from Utils::System

#repeat_on_failure, #syscmd, #zfs

Methods included from Utils::Log

included

Instance Method Details

#read(dataset_names, properties, type: 'filesystem', recursive: false, ignore_error: false) ⇒ Zfs::DatasetTree

Parameters:

  • dataset_names (Array<String>)
  • properties (Array<String>)
  • type (String) (defaults to: 'filesystem')
  • recursive (Boolean) (defaults to: false)
  • ignore_error (Boolean) (defaults to: false)

Returns:



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/libosctl/zfs/property_reader.rb', line 13

def read(dataset_names, properties, type: 'filesystem', recursive: false, ignore_error: false)
  tree = Zfs::DatasetTree.new
  return tree if dataset_names.empty?

  zfs_opts = [
    '-Hp',
    '-o', 'name,property,value',
    '-t', type
  ]

  zfs_opts << '-r' if recursive
  zfs_opts << properties.join(',')

  zfs(
    :get,
    zfs_opts.join(' '),
    dataset_names.join(' '),
    { stderr: false, valid_rcs: ignore_error ? :all : [0] }
  ).output.strip.split("\n").each do |line|
    dataset, prop, val = line.split("\t")

    tree.add_property(dataset, prop, val)
  end

  tree
end