class ZfsMgmt::ZfsMgr::List

class list

Public Instance Methods

holds() click to toggle source
# 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
stale() click to toggle source
# 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