Class: ZfsMgmt::ZfsMgr::List
- Inherits:
-
Thor
- Object
- Thor
- ZfsMgmt::ZfsMgr::List
- Defined in:
- lib/zfs_mgmt/zfs_mgr/list.rb
Overview
class list
Instance Method Summary collapse
Instance Method Details
#holds ⇒ Object
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([:loglevel]) ZfsMgmt. = table = Text::Table.new table.head = ['snapshot','userrefs','holds'] table.rows = [] ZfsMgmt.zfs_managed_list(filter: [: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 [:format] == 'tab' print line.join("\t"),"\n" elsif [:format] == 'release' ZfsMgmt.zfs_holds(snap).each do |hold| print "zfs release #{hold} #{snap}\n" end end end end end if [:format] == 'table' and table.rows.count > 0 print table.to_s end end |
#stale ⇒ Object
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([:loglevel]) ZfsMgmt. = cutoff = Time.at(Time.now.to_i - ZfsMgmt.timespec_to_seconds([:age])) table = Text::Table.new table.head = ['zfs','snapshot','age'] table.rows = [] ZfsMgmt.zfs_managed_list(filter: [: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 [:format] == 'tab' print line.join("\t"),"\n" end end end if [:format] == 'table' and table.rows.count > 0 print table.to_s end end |