dataset.py revision 9f9230833b50b8271840dc2c12bd1e94d9df7d12
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore# CDDL HEADER START
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore# The contents of this file are subject to the terms of the
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore# Common Development and Distribution License (the "License").
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore# You may not use this file except in compliance with the License.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore# or http://www.opensolaris.org/os/licensing.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore# See the License for the specific language governing permissions
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore# and limitations under the License.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore# When distributing Covered Code, include this CDDL HEADER in each
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore# If applicable, add the following below this CDDL HEADER, with the
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore# fields enclosed by brackets "[]" replaced with your own identifying
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore# information: Portions Copyright [yyyy] [name of copyright owner]
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore# CDDL HEADER END
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore"""Implements the Dataset class, providing methods for manipulating ZFS
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amoredatasets. Also implements the Property class, which describes ZFS
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amoreproperties."""
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore """This class represents a ZFS property. It contains
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore information about the property -- if it's readonly, a number vs
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore string vs index, etc. Only native properties are represented by
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore this class -- not user properties (eg "user:prop") or userspace
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore properties (eg "userquota@joe")."""
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore __slots__ = "name", "number", "type", "default", "attr", "validtypes", \
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore "values", "colname", "rightalign", "visible", "indextable"
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore """t is the tuple of information about this property
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore from zfs.ioctl.get_proptable, which should match the
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore members of zprop_desc_t (see zfs_prop.h)."""
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore """Return True if this property can be delegated with
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore "zfs allow"."""
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amorefor name, t in zfs.ioctl.get_proptable().iteritems():
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore """Return the Property object that is identified by the given
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore name string. It can be the full name, or the column name."""
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore """Represents a ZFS dataset (filesystem, snapshot, zvol, clone, etc).
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore Generally, this class provides interfaces to the C functions in
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore zfs.ioctl which actually interface with the kernel to manipulate
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore Unless otherwise noted, any method can raise a ZFSError to
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore indicate failure."""
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore types=("filesystem", "volume"), snaps=True):
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore """Open the named dataset, checking that it exists and
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore is of the specified type.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore name is the string name of this dataset.
698f87a48e2e945bfe5493ce168e0d0ae1cedd5cGarrett D'Amore props is the property settings dict from zfs.ioctl.next_dataset.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore types is an iterable of strings specifying which types
698f87a48e2e945bfe5493ce168e0d0ae1cedd5cGarrett D'Amore of datasets are permitted. Accepted strings are
698f87a48e2e945bfe5493ce168e0d0ae1cedd5cGarrett D'Amore "filesystem" and "volume". Defaults to accepting all
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore snaps is a boolean specifying if snapshots are acceptable.
698f87a48e2e945bfe5493ce168e0d0ae1cedd5cGarrett D'Amore Raises a ZFSError if the dataset can't be accessed (eg
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore doesn't exist) or is not of the specified type.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore _("operation not applicable to datasets of this type"))
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if "volume" not in types and self.getprop("type") == 3:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if "filesystem" not in types and self.getprop("type") == 2:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore """Return the value of the given property for this dataset.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore Currently only works for native properties (those with a
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore Property object.)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore Raises KeyError if propname does not specify a native property.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore Does not raise ZFSError.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore """Return a Dataset representing the parent of this one."""
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore return Dataset(self.name[:self.name.rindex("/")])
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore """A generator function which iterates over all
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore descendent Datasets (not including snapshots."""
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore # next_dataset raises StopIteration when done
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore zfs.ioctl.next_dataset(self.name, False, cookie)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore """A generator function which iterates over a
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore userspace-type property.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore prop specifies which property ("userused@",
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore "userquota@", "groupused@", or "groupquota@").
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore returns 3-tuple of domain (string), rid (int), and space (int).
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore d = zfs.ioctl.userspace_many(self.name, prop)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore for ((domain, rid), space) in d.iteritems():
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore """Initialize the accounting information for
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore userused@... and groupused@... properties."""
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore return zfs.ioctl.userspace_upgrade(self.name)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore """Add to the "zfs allow"-ed permissions on this Dataset.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore un is True if the specified permissions should be removed.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore d is a dict specifying which permissions to add/remove:
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore { "whostr" -> None # remove all perms for this entity
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore "whostr" -> { "perm" -> None} # add/remove these perms
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore return zfs.ioctl.set_fsacl(self.name, un, d)
698f87a48e2e945bfe5493ce168e0d0ae1cedd5cGarrett D'Amore """Get the "zfs allow"-ed permissions on the Dataset.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore Return a dict("whostr": { "perm" -> None })."""
698f87a48e2e945bfe5493ce168e0d0ae1cedd5cGarrett D'Amore """Get the user holds on this Dataset.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore Return a dict("tag": timestamp)."""
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amoredef snapshots_fromcmdline(dsnames, recursive):
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore _("operation only applies to snapshots"))
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore if not recursive or e.errno != errno.ENOENT: