Class: ZFS::SnapshotList

Inherits:
Object
  • Object
show all
Defined in:
lib/zfs/snapshot_list.rb

Overview

Represents a list of snapshots like the tool ‘zfs list’ outputs it. This class allows extracting information from that list.

Example:

snl = ZFS::SnapshotList.new(`zfs list -H -o name`)
snl.datasets # => array of dataset names
snl.snapshots('pool1') # => array of snapshots on the pool1

Instance Method Summary collapse

Constructor Details

#initialize(tool_output) ⇒ SnapshotList

Returns a new instance of SnapshotList.



13
14
15
16
17
18
19
20
21
22
# File 'lib/zfs/snapshot_list.rb', line 13

def initialize(tool_output)
  @list = Hash.new { |h,k| h[k] = [] }
  
  tool_output.lines. 
    map { |l| l.chomp.strip.split('@').first(2) }.  # extracts path/snapshot tuples
    each { |path, snapshot|
      snapshots = @list[path]
      snapshots << snapshot if snapshot }
      
end

Instance Method Details

#datasetsObject



23
24
25
# File 'lib/zfs/snapshot_list.rb', line 23

def datasets
  @list.keys
end

#snapshots(dataset_name) ⇒ Object



26
27
28
# File 'lib/zfs/snapshot_list.rb', line 26

def snapshots(dataset_name)
  @list[dataset_name]
end