Class: OsCtl::Lib::Zfs::PropertyState

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

Overview

Store a set of configured ZFS properties, then apply it to another dataset

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::System

#repeat_on_failure, #syscmd, #zfs

Methods included from Utils::Log

included

Constructor Details

#initializePropertyState

Returns a new instance of PropertyState.



13
14
15
16
# File 'lib/libosctl/zfs/property_state.rb', line 13

def initialize
  @properties = {}
  @options = {}
end

Instance Attribute Details

#optionsHash (readonly)

Returns:

  • (Hash)


11
12
13
# File 'lib/libosctl/zfs/property_state.rb', line 11

def options
  @options
end

#propertiesHash (readonly)

Returns:

  • (Hash)


8
9
10
# File 'lib/libosctl/zfs/property_state.rb', line 8

def properties
  @properties
end

Instance Method Details

#apply_to(dataset) ⇒ Object

Parameters:



37
38
39
40
41
42
43
# File 'lib/libosctl/zfs/property_state.rb', line 37

def apply_to(dataset)
  zfs(
    :set,
    option_strings.map { |opt| "-o #{opt}" }.join(" "),
    dataset,
  )
end

#cleanObject



18
19
20
21
# File 'lib/libosctl/zfs/property_state.rb', line 18

def clean
  @properties.clear
  @options.clear
end

#option_stringsArray<String>

Returns:

  • (Array<String>)


46
47
48
# File 'lib/libosctl/zfs/property_state.rb', line 46

def option_strings
  options.map { |k, v| "\"#{k}=#{v}\"" }
end

#read_from(dataset) ⇒ Object

Parameters:



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/libosctl/zfs/property_state.rb', line 24

def read_from(dataset)
  zfs(
    :get,
    '-Hp -o property,value -s local,received all',
    dataset
  ).output.strip.split("\n").each do |line|
    prop, value = line.split
    properties[prop] = value
    options[prop] = to_option(prop, value)
  end
end

#to_option(property, value) ⇒ Object (protected)

Parameters:

  • property (String)
  • value (String)


53
54
55
56
# File 'lib/libosctl/zfs/property_state.rb', line 53

def to_option(property, value)
  return 'none' if %w(quota refquota).include?(property) && value.to_i == 0
  value
end