Class: ZfsMgmt::ZfsMgr::List

Inherits:
Thor
  • Object
show all
Defined in:
lib/zfs_mgmt/zfs_mgr/list.rb

Overview

class list

Instance Method Summary collapse

Instance Method Details

#holdsObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/zfs_mgmt/zfs_mgr/list.rb', line 33

def holds()
  ZfsMgmt.set_log_level(options[:loglevel])
  ZfsMgmt.global_options = options
  table = Text::Table.new
  table.head = ['snapshot','userrefs','holds']
  table.rows = []
  ZfsMgmt.zfs_managed_list(filter: options[:filter], property_match: {} ).each do |zfs,props,snaps|
    snaps.sort_by { |x,y| y['creation'] }.each do |snap,d|
      if d['userrefs'] > 0
        line = [snap,d['userrefs'].to_s,ZfsMgmt.zfs_holds(snap).join(',')]
        table.rows << line
        if options[:format] == 'tab'
          print line.join("\t"),"\n"
        elsif options[:format] == 'release'
          ZfsMgmt.zfs_holds(snap).each do |hold|
            print "zfs release #{hold} #{snap}\n"
          end
        end
      end
    end
  end
  if options[:format] == 'table' and table.rows.count > 0
    print table.to_s
  end
end

#staleObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/zfs_mgmt/zfs_mgr/list.rb', line 9

def stale()
  ZfsMgmt.set_log_level(options[:loglevel])
  ZfsMgmt.global_options = options
  cutoff = Time.at(Time.now.to_i -  ZfsMgmt.timespec_to_seconds(options[:age]))
  table = Text::Table.new
  table.head = ['zfs','snapshot','age']
  table.rows = []
  ZfsMgmt.zfs_managed_list(filter: options[:filter]).each do |zfs,props,snaps|
    last = snaps.keys.sort { |a,b| snaps[a]['creation'] <=> snaps[b]['creation'] }.last
    snap_time = Time.at(snaps[last]['creation'])
    if snap_time < cutoff
      line = [zfs,last.split('@')[1],snap_time]
      table.rows << line
      if options[:format] == 'tab'
        print line.join("\t"),"\n"
      end
    end
  end
  if options[:format] == 'table' and table.rows.count > 0
    print table.to_s
  end
end