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