Class: OsCtl::Lib::Zfs::PropertyState
Overview
Store a set of configured ZFS properties, then apply it to another dataset
Instance Attribute Summary collapse
Instance Method Summary
collapse
#repeat_on_failure, #syscmd, #zfs
Methods included from Utils::Log
included
Constructor Details
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
#options ⇒ Hash
11
12
13
|
# File 'lib/libosctl/zfs/property_state.rb', line 11
def options
@options
end
|
#properties ⇒ Hash
8
9
10
|
# File 'lib/libosctl/zfs/property_state.rb', line 8
def properties
@properties
end
|
Instance Method Details
#apply_to(dataset) ⇒ Object
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
|
#clean ⇒ Object
18
19
20
21
|
# File 'lib/libosctl/zfs/property_state.rb', line 18
def clean
@properties.clear
@options.clear
end
|
#option_strings ⇒ 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
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
54
55
56
57
58
|
# File 'lib/libosctl/zfs/property_state.rb', line 54
def to_option(property, value)
return 'none' if %w[quota refquota].include?(property) && value.to_i == 0
value
end
|