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