Path: blob/main/cddl/contrib/opensolaris/lib/pyzfs/common/holds.py
39563 views
#! /usr/bin/python2.61#2# CDDL HEADER START3#4# The contents of this file are subject to the terms of the5# Common Development and Distribution License (the "License").6# You may not use this file except in compliance with the License.7#8# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE9# or http://www.opensolaris.org/os/licensing.10# See the License for the specific language governing permissions11# and limitations under the License.12#13# When distributing Covered Code, include this CDDL HEADER in each14# file and include the License file at usr/src/OPENSOLARIS.LICENSE.15# If applicable, add the following below this CDDL HEADER, with the16# fields enclosed by brackets "[]" replaced with your own identifying17# information: Portions Copyright [yyyy] [name of copyright owner]18#19# CDDL HEADER END20#21# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.22#2324"""This module implements the "zfs holds" subcommand.25The only public interface is the zfs.holds.do_holds() function."""2627import optparse28import sys29import errno30import time31import zfs.util32import zfs.dataset33import zfs.table3435_ = zfs.util._3637def do_holds():38"""Implements the "zfs holds" subcommand."""39def usage(msg=None):40parser.print_help()41if msg:4243parser.exit("zfs: error: " + msg)44else:45parser.exit()4647u = _("""holds [-r] <snapshot> ...""")4849parser = optparse.OptionParser(usage=u, prog="zfs")5051parser.add_option("-r", action="store_true", dest="recursive",52help=_("list holds recursively"))5354(options, args) = parser.parse_args(sys.argv[2:])5556if len(args) < 1:57usage(_("missing snapshot argument"))5859fields = ("name", "tag", "timestamp")60rjustfields = ()61printing = False62gotone = False63t = zfs.table.Table(fields, rjustfields)64for ds in zfs.dataset.snapshots_fromcmdline(args, options.recursive):65gotone = True66for tag, tm in ds.get_holds().iteritems():67val = {"name": ds.name, "tag": tag,68"timestamp": time.ctime(tm)}69t.addline(ds.name, val)70printing = True71if printing:72t.printme()73elif not gotone:74raise zfs.util.ZFSError(errno.ENOENT, _("no matching datasets"))757677