usr/src/lib/install_target/logical.py
author Mary Ding <mary.ding@oracle.com>
Wed, 09 May 2012 14:20:58 -0700
changeset 1673 7ad5c8725293
parent 1625 d13be924336e
child 1695 7e11a6b0de11
permissions -rw-r--r--
7161993 pep8 regression in /usr/lib/python2.6/vendor-packages/solaris_install/target/logical.py
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
     1
#!/usr/bin/python
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
     2
#
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
     3
# CDDL HEADER START
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
     4
#
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
     5
# The contents of this file are subject to the terms of the
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
     6
# Common Development and Distribution License (the "License").
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
     7
# You may not use this file except in compliance with the License.
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
     8
#
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
     9
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    10
# or http://www.opensolaris.org/os/licensing.
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    11
# See the License for the specific language governing permissions
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    12
# and limitations under the License.
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    13
#
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    14
# When distributing Covered Code, include this CDDL HEADER in each
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    15
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    16
# If applicable, add the following below this CDDL HEADER, with the
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    17
# fields enclosed by brackets "[]" replaced with your own identifying
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    18
# information: Portions Copyright [yyyy] [name of copyright owner]
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    19
#
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    20
# CDDL HEADER END
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    21
#
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    22
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    23
#
1623
cb56a2fb4925 PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents: 1450
diff changeset
    24
# Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    25
#
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    26
""" logical.py -- library containing class definitions for logical DOC objects,
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    27
including Zpool, Filesystem, and Zvol
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    28
"""
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    29
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    30
import logging
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    31
import os
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    32
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    33
from lxml import etree
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    34
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    35
from solaris_install import CalledProcessError, Popen
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    36
from solaris_install.data_object import DataObject, ParsingError
1273
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
    37
from solaris_install.data_object.data_dict import DataObjectDict
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    38
from solaris_install.logger import INSTALL_LOGGER_NAME as ILN
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    39
from solaris_install.target.size import Size
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    40
from solaris_install.target.shadow.logical import ShadowLogical
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    41
from solaris_install.target.shadow.zpool import ShadowZpool
1151
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1140
diff changeset
    42
from solaris_install.target.libbe.be import be_list, be_init, be_destroy, \
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    43
    be_activate, be_mount, be_unmount
1273
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
    44
from solaris_install.target.libnvpair import nvl
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    45
1083
449ba0d2a6b8 7038169 TI doesn't create swap or dump zvols at all
Drew Fisher <drew.fisher@oracle.com>
parents: 1080
diff changeset
    46
DUMPADM = "/usr/sbin/dumpadm"
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    47
LOFIADM = "/usr/sbin/lofiadm"
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    48
MKFILE = "/usr/sbin/mkfile"
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    49
MOUNT = "/usr/sbin/mount"
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    50
NEWFS = "/usr/sbin/newfs"
1083
449ba0d2a6b8 7038169 TI doesn't create swap or dump zvols at all
Drew Fisher <drew.fisher@oracle.com>
parents: 1080
diff changeset
    51
SWAP = "/usr/sbin/swap"
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    52
UMOUNT = "/usr/sbin/umount"
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    53
ZFS = "/usr/sbin/zfs"
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    54
ZPOOL = "/usr/sbin/zpool"
1237
1422ef107116 7059003 test_target_selection_* tests failing if BE "solaris" exists
Matt Keenan <matt.keenan@oracle.com>
parents: 1236
diff changeset
    55
DEFAULT_BE_NAME = "solaris"
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    56
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    57
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    58
class Logical(DataObject):
1094
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
    59
    """ logical DOC node definition
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
    60
    """
1088
d6f83c93a86c 7038486 physical _label_disk() using incorrect logger.
Drew Fisher <drew.fisher@oracle.com>
parents: 1083
diff changeset
    61
    def __init__(self, name):
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    62
        super(Logical, self).__init__(name)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    63
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    64
        self.noswap = False
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    65
        self.nodump = False
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    66
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    67
        # shadow lists
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    68
        self._children = ShadowZpool(self)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    69
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    70
    def to_xml(self):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    71
        element = etree.Element("logical")
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    72
        element.set("noswap", str(self.noswap).lower())
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    73
        element.set("nodump", str(self.nodump).lower())
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    74
        return element
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    75
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    76
    @classmethod
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    77
    def can_handle(cls, element):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    78
        """ Returns True if the element has the tag 'logical'
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    79
        """
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    80
        if element.tag == "logical":
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    81
            return True
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    82
        return False
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    83
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    84
    @classmethod
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    85
    def from_xml(cls, element):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    86
        noswap = element.get("noswap")
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    87
        nodump = element.get("nodump")
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    88
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    89
        logical = Logical("logical")
1623
cb56a2fb4925 PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents: 1450
diff changeset
    90
        if noswap is not None:
cb56a2fb4925 PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents: 1450
diff changeset
    91
            try:
cb56a2fb4925 PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents: 1450
diff changeset
    92
                logical.noswap = {"true": True, "false": False}[noswap.lower()]
cb56a2fb4925 PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents: 1450
diff changeset
    93
            except KeyError:
cb56a2fb4925 PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents: 1450
diff changeset
    94
                raise ParsingError("Logical  element's noswap attribute " +
cb56a2fb4925 PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents: 1450
diff changeset
    95
                                   "must be either 'true' or 'false'")
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    96
1623
cb56a2fb4925 PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents: 1450
diff changeset
    97
        if nodump is not None:
cb56a2fb4925 PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents: 1450
diff changeset
    98
            try:
cb56a2fb4925 PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents: 1450
diff changeset
    99
                logical.nodump = {"true": True, "false": False}[nodump.lower()]
cb56a2fb4925 PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents: 1450
diff changeset
   100
            except KeyError:
cb56a2fb4925 PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents: 1450
diff changeset
   101
                raise ParsingError("Logical  element's nodump attribute " +
cb56a2fb4925 PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents: 1450
diff changeset
   102
                                   "must be either 'true' or 'false'")
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   103
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   104
        return logical
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   105
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   106
    def add_zpool(self, zpool_name, is_root=False, mountpoint=None):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   107
        """ add_zpool() - method to create a Zpool object and add it as a child
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   108
        of the Logical object
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   109
        """
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   110
        # create a new Zpool object
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   111
        new_zpool = Zpool(zpool_name)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   112
        new_zpool.is_root = is_root
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   113
        new_zpool.mountpoint = mountpoint
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   114
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   115
        # add the new Zpool object as a child
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   116
        self.insert_children(new_zpool)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   117
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   118
        return new_zpool
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   119
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   120
    def delete_zpool(self, zpool):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   121
        """ delete_zpool() - method to delete a specific Zpool object
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   122
        """
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   123
        self.delete_children(name=zpool.name, class_type=Zpool)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   124
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   125
    def __copy__(self):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   126
        """ method to override the parent's version of __copy__.
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   127
        We want the _children list to be a shadow list instead of a flat list
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   128
        """
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   129
        new_copy = super(Logical, self).__copy__()
1128
a401bf4396fc 7044533 cud_ai: ERROR: an exception occurred : 'naccessible'
Drew Fisher <drew.fisher@oracle.com>
parents: 1094
diff changeset
   130
        new_copy._children = ShadowZpool(new_copy)
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   131
        return new_copy
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   132
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   133
    def __repr__(self):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   134
        return "Logical: noswap=%s; nodump=%s" % (self.noswap, self.nodump)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   135
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   136
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   137
class Zpool(DataObject):
1094
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   138
    """ zpool DOC node definition
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   139
    """
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   140
    def __init__(self, name, vdev_list=None, mountpoint=None):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   141
        super(Zpool, self).__init__(name)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   142
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   143
        self.action = "create"
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   144
        self.is_root = False
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   145
        self.mountpoint = mountpoint
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   146
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   147
        if not isinstance(vdev_list, list):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   148
            # convert a string of vdev(s) into a list with one element
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   149
            self.vdev_list = [vdev_list]
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   150
        else:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   151
            self.vdev_list = vdev_list
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   152
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   153
        # shadow lists
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   154
        self._children = ShadowLogical(self)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   155
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   156
    def to_xml(self):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   157
        element = etree.Element("zpool")
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   158
        element.set("name", self.name)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   159
        element.set("action", self.action)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   160
        element.set("is_root", str(self.is_root).lower())
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   161
        if self.mountpoint is not None:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   162
            element.set("mountpoint", self.mountpoint)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   163
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   164
        return element
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   165
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   166
    @classmethod
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   167
    def can_handle(cls, element):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   168
        """ Returns True if element has:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   169
        - the tag 'zpool'
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   170
        - a name attribute
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   171
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   172
        otherwise return False
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   173
        """
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   174
        if element.tag != "zpool":
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   175
            return False
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   176
        if element.get("name") is None:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   177
            return False
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   178
        return True
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   179
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   180
    @classmethod
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   181
    def from_xml(cls, element):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   182
        name = element.get("name")
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   183
        action = element.get("action")
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   184
        is_root = element.get("is_root")
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   185
        mountpoint = element.get("mountpoint")
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   186
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   187
        zpool = Zpool(name)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   188
        if action is not None:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   189
            zpool.action = action
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   190
        if is_root is not None:
1623
cb56a2fb4925 PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents: 1450
diff changeset
   191
            try:
cb56a2fb4925 PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents: 1450
diff changeset
   192
                zpool.is_root = {"true": True, "false": False}[is_root.lower()]
cb56a2fb4925 PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents: 1450
diff changeset
   193
            except KeyError:
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   194
                raise ParsingError("Zpool element's is_root attribute must " +
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   195
                                   "be either 'true' or 'false'")
1623
cb56a2fb4925 PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents: 1450
diff changeset
   196
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   197
        if mountpoint is not None:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   198
            zpool.mountpoint = mountpoint
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   199
        return zpool
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   200
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   201
    @property
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   202
    def exists(self):
1094
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   203
        """ property to check for the existance of the zpool
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   204
        """
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   205
        cmd = [ZPOOL, "list", self.name]
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   206
        p = Popen.check_call(cmd, stdout=Popen.STORE, stderr=Popen.STORE,
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   207
                             check_result=Popen.ANY)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   208
        return p.returncode == 0
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   209
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   210
    @property
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   211
    def filesystems(self):
1094
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   212
        """ method to return all filesystems which belong to the pool
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   213
        """
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   214
        filesystem_list = []
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   215
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   216
        # if the zpool doesn't yet exist, return an empty list
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   217
        if not self.exists:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   218
            return filesystem_list
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   219
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   220
        cmd = [ZFS, "list", "-H", "-t", "filesystem", "-o", "name", "-r",
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   221
               self.name]
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   222
        p = Popen.check_call(cmd, stdout=Popen.STORE, stderr=Popen.STORE,
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   223
                             logger=ILN)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   224
        for fs in p.stdout.splitlines():
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   225
            filesystem_list.append(Filesystem(fs))
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   226
        return filesystem_list
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   227
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   228
    def set(self, propname, propvalue, dry_run):
1094
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   229
        """ method to set a property for the pool
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   230
        """
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   231
        cmd = [ZPOOL, "set", "%s=%s" % (propname, propvalue), self.name]
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   232
        if not dry_run:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   233
            Popen.check_call(cmd, stdout=Popen.STORE, stderr=Popen.STORE,
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   234
                             logger=ILN)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   235
1094
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   236
    def get(self, propname="all"):
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   237
        """ get() - method to return a specific zpool property.
1151
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1140
diff changeset
   238
1094
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   239
        propname - name of the property to return.  If the user does not
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   240
        specify a propname, return all pool properties
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   241
        """
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   242
        cmd = [ZPOOL, "get", propname, self.name]
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   243
        p = Popen.check_call(cmd, stdout=Popen.STORE, stderr=Popen.STORE,
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   244
                             logger=ILN)
1094
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   245
        # construct a dictionary of properties
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   246
        prop_dict = dict()
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   247
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   248
        # skip the header line
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   249
        for line in p.stdout.splitlines()[1:]:
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   250
            # The output from zpool get is in four columns:
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   251
            # NAME PROPERTY VALUE SOURCE
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   252
            # We're only interested in the PROPERTY and VALUE columns
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   253
            _none, prop, value, _none = line.strip().split()
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   254
            prop_dict[prop] = value
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   255
        return prop_dict
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   256
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   257
    def create(self, dry_run, options=[]):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   258
        """ method to create the zpool from the vdevs
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   259
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   260
        options - optional list of pool and/or dataset options to pass to the
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   261
        create flag
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   262
        """
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   263
        cmd = [ZPOOL, "create", "-f"]
1623
cb56a2fb4925 PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents: 1450
diff changeset
   264
        if self.is_root:
cb56a2fb4925 PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents: 1450
diff changeset
   265
            cmd.append("-B")
cb56a2fb4925 PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents: 1450
diff changeset
   266
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   267
        if options:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   268
            cmd.extend(options)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   269
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   270
        # add the mountpoint if specified
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   271
        if self.mountpoint is not None:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   272
            cmd.append("-m")
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   273
            cmd.append(self.mountpoint)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   274
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   275
        cmd.append(self.name)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   276
        if None in self.vdev_list:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   277
            raise RuntimeError("Invalid entry in vdev_list:  " + \
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   278
                               str(self.vdev_list))
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   279
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   280
        # add the vdev_list to the cmd to preserve the format Popen needs
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   281
        cmd += self.vdev_list
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   282
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   283
        if not dry_run:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   284
            Popen.check_call(cmd, stdout=Popen.STORE, stderr=Popen.STORE,
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   285
                             logger=ILN)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   286
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   287
    def destroy(self, dry_run, force=False):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   288
        """ method to destroy the zpool
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   289
        """
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   290
        if self.exists:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   291
            cmd = [ZPOOL, "destroy"]
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   292
            if force:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   293
                cmd.append("-f")
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   294
            cmd.append(self.name)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   295
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   296
            if not dry_run:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   297
                Popen.check_call(cmd, stdout=Popen.STORE, stderr=Popen.STORE,
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   298
                                 logger=ILN)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   299
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   300
    def add_vdev(self, label, redundancy):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   301
        """ add_vdev() - method to create a Vdev object and add it as a child
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   302
        of the Zpool object
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   303
        """
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   304
        # No need to validate here because the schema has a list of valid
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   305
        # redundancy values already
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   306
        new_vdev = Vdev(label)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   307
        new_vdev.redundancy = redundancy
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   308
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   309
        self.insert_children(new_vdev)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   310
        return new_vdev
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   311
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   312
    def delete_vdev(self, vdev):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   313
        """ delete_vdev() - method to delete a specific Vdev object
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   314
        """
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   315
        self.delete_children(name=vdev.name, class_type=Vdev)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   316
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   317
    def add_filesystem(self, fs_name, mountpoint=None):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   318
        """ add_filesystem - method to create a Filesystem object and add it as
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   319
        a child of the Zpool object
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   320
        """
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   321
        # create a new Filesystem object
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   322
        new_filesystem = Filesystem(fs_name)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   323
        new_filesystem.mountpoint = mountpoint
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   324
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   325
        # add the new Filesystem object as a child
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   326
        self.insert_children(new_filesystem)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   327
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   328
        return new_filesystem
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   329
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   330
    def delete_filesystem(self, filesystem):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   331
        """ delete_filesystem() - method to delete a specific Filesystem object
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   332
        """
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   333
        self.delete_children(name=filesystem.name, class_type=Filesystem)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   334
1625
d13be924336e 7070697 size element for zvols should be optional
nirmal27<Nirmal.Agarwal@oracle.com>
parents: 1623
diff changeset
   335
    def add_zvol(self, zvol_name, size="", size_units=Size.gb_units, use=None,
1370
0e49021cc774 6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents: 1326
diff changeset
   336
                 create_failure_ok=False):
1094
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   337
        """ add_zvol - method to create a Zvol object and add it as a child of
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   338
        the Zpool object
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   339
        """
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   340
        # create a new Zvol object
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   341
        new_zvol = Zvol(zvol_name)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   342
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   343
        # fix the size units to conform to ZFS syntax by removing the "b"
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   344
        # character from the units
1625
d13be924336e 7070697 size element for zvols should be optional
nirmal27<Nirmal.Agarwal@oracle.com>
parents: 1623
diff changeset
   345
        if size:
d13be924336e 7070697 size element for zvols should be optional
nirmal27<Nirmal.Agarwal@oracle.com>
parents: 1623
diff changeset
   346
            if size == "max":
d13be924336e 7070697 size element for zvols should be optional
nirmal27<Nirmal.Agarwal@oracle.com>
parents: 1623
diff changeset
   347
                new_zvol.size = size
d13be924336e 7070697 size element for zvols should be optional
nirmal27<Nirmal.Agarwal@oracle.com>
parents: 1623
diff changeset
   348
            else:
d13be924336e 7070697 size element for zvols should be optional
nirmal27<Nirmal.Agarwal@oracle.com>
parents: 1623
diff changeset
   349
                size_units = str(size_units).rstrip("bB")
d13be924336e 7070697 size element for zvols should be optional
nirmal27<Nirmal.Agarwal@oracle.com>
parents: 1623
diff changeset
   350
                new_zvol.size = str(size) + size_units
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   351
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   352
        if use is not None:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   353
            new_zvol.use = use
1370
0e49021cc774 6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents: 1326
diff changeset
   354
        new_zvol.create_failure_ok = create_failure_ok
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   355
1083
449ba0d2a6b8 7038169 TI doesn't create swap or dump zvols at all
Drew Fisher <drew.fisher@oracle.com>
parents: 1080
diff changeset
   356
        # add the new Zvol object as a child
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   357
        self.insert_children(new_zvol)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   358
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   359
        return new_zvol
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   360
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   361
    def delete_zvol(self, zvol):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   362
        """ delete_zvol() - method to delete a specific Zvol object
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   363
        """
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   364
        self.delete_children(name=zvol.name, class_type=Zvol)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   365
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   366
    def __copy__(self):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   367
        """ method to override the parent's version of __copy__.
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   368
        We want the _children list to be a shadow list instead of a flat list
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   369
        """
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   370
        new_copy = super(Zpool, self).__copy__()
1128
a401bf4396fc 7044533 cud_ai: ERROR: an exception occurred : 'naccessible'
Drew Fisher <drew.fisher@oracle.com>
parents: 1094
diff changeset
   371
        new_copy._children = ShadowLogical(new_copy)
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   372
        return new_copy
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   373
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   374
    def __repr__(self):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   375
        s = "Zpool: name=%s; action=%s" % (self.name, self.action)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   376
        s += "; is_root=%s" % self.is_root
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   377
        if self.mountpoint is not None:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   378
            s += "; mountpoint=%s" % self.mountpoint
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   379
        if self.vdev_list is not None:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   380
            s += "; vdev_list=" + str(self.vdev_list)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   381
        return s
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   382
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   383
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   384
class Vdev(DataObject):
1094
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   385
    """ vdev DOC node definition
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   386
    """
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   387
    def __init__(self, name):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   388
        super(Vdev, self).__init__(name)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   389
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   390
        self.redundancy = "mirror"
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   391
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   392
    def to_xml(self):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   393
        element = etree.Element("vdev")
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   394
        element.set("name", self.name)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   395
        element.set("redundancy", self.redundancy)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   396
        return element
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   397
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   398
    @classmethod
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   399
    def can_handle(cls, element):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   400
        if element.tag == "vdev":
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   401
            return True
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   402
        return False
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   403
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   404
    @classmethod
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   405
    def from_xml(cls, element):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   406
        name = element.get("name")
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   407
        redundancy = element.get("redundancy")
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   408
        vdev = Vdev(name)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   409
        if redundancy is not None:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   410
            vdev.redundancy = redundancy
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   411
        return vdev
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   412
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   413
    def __repr__(self):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   414
        return "Vdev: name=%s; redundancy=%s" % (self.name, self.redundancy)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   415
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   416
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   417
class Filesystem(DataObject):
1094
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   418
    """ Filesystem DOC node definition
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   419
    """
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   420
    def __init__(self, name):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   421
        super(Filesystem, self).__init__(name)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   422
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   423
        self.action = "create"
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   424
        self.mountpoint = None
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   425
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   426
        self.in_be = False
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   427
1083
449ba0d2a6b8 7038169 TI doesn't create swap or dump zvols at all
Drew Fisher <drew.fisher@oracle.com>
parents: 1080
diff changeset
   428
    @property
449ba0d2a6b8 7038169 TI doesn't create swap or dump zvols at all
Drew Fisher <drew.fisher@oracle.com>
parents: 1080
diff changeset
   429
    def full_name(self):
1140
a3271aa615b8 7046207 TI throwing exception when deleting non-existant Filesystem
Drew Fisher <drew.fisher@oracle.com>
parents: 1131
diff changeset
   430
        """ Keep a full_name attribute with the entire ZFS path for the
a3271aa615b8 7046207 TI throwing exception when deleting non-existant Filesystem
Drew Fisher <drew.fisher@oracle.com>
parents: 1131
diff changeset
   431
        filesystem.  This is done because Filesystem objects can be created via
a3271aa615b8 7046207 TI throwing exception when deleting non-existant Filesystem
Drew Fisher <drew.fisher@oracle.com>
parents: 1131
diff changeset
   432
        Zpool.add_filesystem, simple instantiation, or with the in_be attribute
a3271aa615b8 7046207 TI throwing exception when deleting non-existant Filesystem
Drew Fisher <drew.fisher@oracle.com>
parents: 1131
diff changeset
   433
        set.
1083
449ba0d2a6b8 7038169 TI doesn't create swap or dump zvols at all
Drew Fisher <drew.fisher@oracle.com>
parents: 1080
diff changeset
   434
        """
449ba0d2a6b8 7038169 TI doesn't create swap or dump zvols at all
Drew Fisher <drew.fisher@oracle.com>
parents: 1080
diff changeset
   435
        if self.parent is not None:
1140
a3271aa615b8 7046207 TI throwing exception when deleting non-existant Filesystem
Drew Fisher <drew.fisher@oracle.com>
parents: 1131
diff changeset
   436
            if self.in_be:
a3271aa615b8 7046207 TI throwing exception when deleting non-existant Filesystem
Drew Fisher <drew.fisher@oracle.com>
parents: 1131
diff changeset
   437
                # for in_be Filesystem objects, we need to get the BE and add
a3271aa615b8 7046207 TI throwing exception when deleting non-existant Filesystem
Drew Fisher <drew.fisher@oracle.com>
parents: 1131
diff changeset
   438
                # it instead of the parent
a3271aa615b8 7046207 TI throwing exception when deleting non-existant Filesystem
Drew Fisher <drew.fisher@oracle.com>
parents: 1131
diff changeset
   439
                be = self.parent.get_first_child(class_type=BE)
a3271aa615b8 7046207 TI throwing exception when deleting non-existant Filesystem
Drew Fisher <drew.fisher@oracle.com>
parents: 1131
diff changeset
   440
                return os.path.join(self.parent.name, "ROOT", be.name,
a3271aa615b8 7046207 TI throwing exception when deleting non-existant Filesystem
Drew Fisher <drew.fisher@oracle.com>
parents: 1131
diff changeset
   441
                                    self.name.lstrip("/"))
a3271aa615b8 7046207 TI throwing exception when deleting non-existant Filesystem
Drew Fisher <drew.fisher@oracle.com>
parents: 1131
diff changeset
   442
            else:
a3271aa615b8 7046207 TI throwing exception when deleting non-existant Filesystem
Drew Fisher <drew.fisher@oracle.com>
parents: 1131
diff changeset
   443
                return os.path.join(self.parent.name, self.name.lstrip("/"))
1083
449ba0d2a6b8 7038169 TI doesn't create swap or dump zvols at all
Drew Fisher <drew.fisher@oracle.com>
parents: 1080
diff changeset
   444
        else:
449ba0d2a6b8 7038169 TI doesn't create swap or dump zvols at all
Drew Fisher <drew.fisher@oracle.com>
parents: 1080
diff changeset
   445
            return self.name
449ba0d2a6b8 7038169 TI doesn't create swap or dump zvols at all
Drew Fisher <drew.fisher@oracle.com>
parents: 1080
diff changeset
   446
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   447
    def to_xml(self):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   448
        element = etree.Element("filesystem")
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   449
        element.set("name", self.name)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   450
        element.set("action", self.action)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   451
        if self.mountpoint is not None:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   452
            element.set("mountpoint", self.mountpoint)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   453
        element.set("in_be", str(self.in_be).lower())
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   454
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   455
        return element
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   456
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   457
    @classmethod
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   458
    def can_handle(cls, element):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   459
        """ Returns True if element has:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   460
        - the tag 'filesystem'
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   461
        - a name attribute
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   462
        - an action attribute
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   463
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   464
        otherwise return False
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   465
        """
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   466
        if element.tag != "filesystem":
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   467
            return False
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   468
        if element.get("name") is None:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   469
            return False
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   470
        return True
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   471
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   472
    @classmethod
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   473
    def from_xml(cls, element):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   474
        name = element.get("name")
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   475
        action = element.get("action")
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   476
        mountpoint = element.get("mountpoint")
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   477
        in_be = element.get("in_be")
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   478
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   479
        filesystem = Filesystem(name)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   480
        if action is not None:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   481
            filesystem.action = action
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   482
        if mountpoint is not None:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   483
            filesystem.mountpoint = mountpoint
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   484
        else:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   485
            # Recursively strip the dataset_path until the mountpoint is
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   486
            # found.
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   487
            stripped_entries = []
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   488
            dataset_list = name.split("/")
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   489
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   490
            # add the parent's name (the zpool name) to the list
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   491
            dataset_list.insert(0, element.getparent().get("name"))
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   492
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   493
            while dataset_list:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   494
                try:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   495
                    test_dataset = Filesystem("/".join(dataset_list))
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   496
                    test_dataset_mp = test_dataset.get("mountpoint")
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   497
                except CalledProcessError:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   498
                    # strip off the last element and save it for later
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   499
                    stripped_entries.append(dataset_list[-1])
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   500
                    dataset_list = dataset_list[:-1]
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   501
                    continue
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   502
                else:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   503
                    # the mountpoint was found so add the stripped entries
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   504
                    # (in reverse) to generate the proper path.
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   505
                    filesystem.mountpoint = os.path.join(test_dataset_mp,
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   506
                        "/".join(reversed(stripped_entries)))
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   507
                    break
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   508
            else:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   509
                # set the mountpoint to None
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   510
                filesystem.mountpoint = None
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   511
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   512
        if in_be is not None:
1623
cb56a2fb4925 PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents: 1450
diff changeset
   513
            try:
1673
7ad5c8725293 7161993 pep8 regression in /usr/lib/python2.6/vendor-packages/solaris_install/target/logical.py
Mary Ding <mary.ding@oracle.com>
parents: 1625
diff changeset
   514
                filesystem.in_be = {"true": True,
7ad5c8725293 7161993 pep8 regression in /usr/lib/python2.6/vendor-packages/solaris_install/target/logical.py
Mary Ding <mary.ding@oracle.com>
parents: 1625
diff changeset
   515
                                    "false": False}[in_be.lower()]
1623
cb56a2fb4925 PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents: 1450
diff changeset
   516
            except KeyError:
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   517
                raise ParsingError("Filesystem element's in_be attribute " +
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   518
                                   "must be either 'true' or 'false'")
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   519
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   520
        return filesystem
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   521
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   522
    def __repr__(self):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   523
        s = "Filesystem: name=%s; action=%s" % (self.name, self.action)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   524
        if self.mountpoint is not None:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   525
            s += "; mountpoint=%s" % self.mountpoint
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   526
        return s
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   527
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   528
    def snapshot(self, snapshot_name, overwrite=False):
1094
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   529
        """ snapshot - method to create a ZFS shapshot of the filesystem
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   530
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   531
        snapshot_name - name of the snapshot to create
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   532
        overwrite - boolean argument to determine if ZFS should delete an
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   533
        existing snapshot with the same name (if it exists)
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   534
        """
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   535
        snap = self.snapname(snapshot_name)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   536
        if overwrite and snap in self.snapshot_list:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   537
            self.destroy(dry_run=False, snapshot=snapshot_name)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   538
        cmd = [ZFS, "snapshot", snap]
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   539
        Popen.check_call(cmd, stdout=Popen.STORE, stderr=Popen.STORE,
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   540
                         logger=ILN)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   541
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   542
    def snapname(self, short_name):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   543
        '''Returns the full (dataset@snapshot) name based on the given
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   544
        short name'''
1083
449ba0d2a6b8 7038169 TI doesn't create swap or dump zvols at all
Drew Fisher <drew.fisher@oracle.com>
parents: 1080
diff changeset
   545
        return self.full_name + "@" + short_name
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   546
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   547
    def _snapshots(self):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   548
        ''' Get list of snapshots.  Snapshots returned will be in creation
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   549
            time order with the earliest first '''
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   550
        cmd = [ZFS, "list", "-H", "-o", "name", "-t", "snapshot",
1083
449ba0d2a6b8 7038169 TI doesn't create swap or dump zvols at all
Drew Fisher <drew.fisher@oracle.com>
parents: 1080
diff changeset
   551
               "-s", "creation", "-r", self.full_name]
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   552
        p = Popen.check_call(cmd, stdout=Popen.STORE, stderr=Popen.STORE,
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   553
                             logger=ILN)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   554
        return p.stdout.splitlines()
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   555
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   556
    # Probably a bit heavyweight for a property
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   557
    snapshot_list = property(_snapshots)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   558
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   559
    def rollback(self, to_snapshot, recursive=False):
1094
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   560
        """ rollback - method to rollback a ZFS filesystem to a given
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   561
        checkpoint
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   562
        """
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   563
        cmd = [ZFS, "rollback"]
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   564
        if recursive:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   565
            cmd.append("-r")
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   566
        cmd.append(self.snapname(to_snapshot))
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   567
        Popen.check_call(cmd, stdout=Popen.STORE, stderr=Popen.STORE,
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   568
                         logger=ILN)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   569
1094
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   570
    def set(self, prop, value, dry_run):
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   571
        """ method to set a property on the ZFS filesystem
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   572
        """
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   573
        cmd = [ZFS, "set", "%s=%s" % (prop, value), self.full_name]
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   574
        if not dry_run:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   575
            Popen.check_call(cmd, stdout=Popen.STORE, stderr=Popen.STORE,
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   576
                             logger=ILN)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   577
1094
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   578
    def get(self, prop):
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   579
        """ method to return the value for a ZFS property of the filesystem
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   580
        """
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   581
        cmd = [ZFS, "get", "-H", "-o", "value", prop, self.full_name]
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   582
        p = Popen.check_call(cmd, stdout=Popen.STORE, stderr=Popen.STORE,
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   583
                             stderr_loglevel=logging.DEBUG, logger=ILN)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   584
        return p.stdout.strip()
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   585
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   586
    def create(self, dry_run):
1094
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   587
        """ create the filesystem
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   588
        """
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   589
        if not self.exists:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   590
            cmd = [ZFS, "create", "-p"]
1273
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   591
            zfs_options = self.get_first_child(class_type=Options)
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   592
            if zfs_options is not None:
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   593
                cmd.extend(zfs_options.get_arg_list())
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   594
            if self.mountpoint is not None:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   595
                cmd.extend(["-o", "mountpoint=%s" % self.mountpoint])
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   596
1083
449ba0d2a6b8 7038169 TI doesn't create swap or dump zvols at all
Drew Fisher <drew.fisher@oracle.com>
parents: 1080
diff changeset
   597
            cmd.append(self.full_name)
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   598
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   599
            if not dry_run:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   600
                Popen.check_call(cmd, stdout=Popen.STORE, stderr=Popen.STORE,
1394
7f92dd7e7416 7077329 Problem with install/textui
Karen Tung <Karen.Tung@oracle.com>
parents: 1370
diff changeset
   601
                                 logger=ILN, env={"LC_ALL": "C"})
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   602
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   603
    def destroy(self, dry_run, snapshot=None, recursive=False):
1094
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   604
        """ destroy the filesystem
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   605
        """
1140
a3271aa615b8 7046207 TI throwing exception when deleting non-existant Filesystem
Drew Fisher <drew.fisher@oracle.com>
parents: 1131
diff changeset
   606
        if self.exists:
a3271aa615b8 7046207 TI throwing exception when deleting non-existant Filesystem
Drew Fisher <drew.fisher@oracle.com>
parents: 1131
diff changeset
   607
            if not dry_run:
a3271aa615b8 7046207 TI throwing exception when deleting non-existant Filesystem
Drew Fisher <drew.fisher@oracle.com>
parents: 1131
diff changeset
   608
                cmd = [ZFS, "destroy"]
a3271aa615b8 7046207 TI throwing exception when deleting non-existant Filesystem
Drew Fisher <drew.fisher@oracle.com>
parents: 1131
diff changeset
   609
                if recursive:
a3271aa615b8 7046207 TI throwing exception when deleting non-existant Filesystem
Drew Fisher <drew.fisher@oracle.com>
parents: 1131
diff changeset
   610
                    cmd.append("-r")
a3271aa615b8 7046207 TI throwing exception when deleting non-existant Filesystem
Drew Fisher <drew.fisher@oracle.com>
parents: 1131
diff changeset
   611
                if snapshot is not None:
a3271aa615b8 7046207 TI throwing exception when deleting non-existant Filesystem
Drew Fisher <drew.fisher@oracle.com>
parents: 1131
diff changeset
   612
                    cmd.append(self.snapname(snapshot))
a3271aa615b8 7046207 TI throwing exception when deleting non-existant Filesystem
Drew Fisher <drew.fisher@oracle.com>
parents: 1131
diff changeset
   613
                else:
a3271aa615b8 7046207 TI throwing exception when deleting non-existant Filesystem
Drew Fisher <drew.fisher@oracle.com>
parents: 1131
diff changeset
   614
                    cmd.append(self.full_name)
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   615
1140
a3271aa615b8 7046207 TI throwing exception when deleting non-existant Filesystem
Drew Fisher <drew.fisher@oracle.com>
parents: 1131
diff changeset
   616
                Popen.check_call(cmd, stdout=Popen.STORE, stderr=Popen.STORE,
a3271aa615b8 7046207 TI throwing exception when deleting non-existant Filesystem
Drew Fisher <drew.fisher@oracle.com>
parents: 1131
diff changeset
   617
                                 logger=ILN)
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   618
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   619
    @property
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   620
    def exists(self):
1094
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   621
        """ property to check for the existance of the filesystem
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   622
        """
1083
449ba0d2a6b8 7038169 TI doesn't create swap or dump zvols at all
Drew Fisher <drew.fisher@oracle.com>
parents: 1080
diff changeset
   623
        cmd = [ZFS, "list", self.full_name]
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   624
        p = Popen.check_call(cmd, stdout=Popen.STORE, stderr=Popen.STORE,
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   625
                             check_result=Popen.ANY)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   626
        return p.returncode == 0
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   627
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   628
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   629
class Zvol(DataObject):
1094
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   630
    """ Zvol DOC node definition
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   631
    """
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   632
    def __init__(self, name):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   633
        super(Zvol, self).__init__(name)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   634
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   635
        self.action = "create"
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   636
        self.use = "none"
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   637
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   638
        self.size = ""
1450
60f63c2d05d7 7083584 snv 172 text installer does not initially present SAS drive aliases/receptacles
Karen Tung <Karen.Tung@oracle.com>
parents: 1394
diff changeset
   639
        self.create_failure_ok = False
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   640
1083
449ba0d2a6b8 7038169 TI doesn't create swap or dump zvols at all
Drew Fisher <drew.fisher@oracle.com>
parents: 1080
diff changeset
   641
    @property
449ba0d2a6b8 7038169 TI doesn't create swap or dump zvols at all
Drew Fisher <drew.fisher@oracle.com>
parents: 1080
diff changeset
   642
    def full_name(self):
449ba0d2a6b8 7038169 TI doesn't create swap or dump zvols at all
Drew Fisher <drew.fisher@oracle.com>
parents: 1080
diff changeset
   643
        """ keep a full_name attribute with the entire ZFS path for the
449ba0d2a6b8 7038169 TI doesn't create swap or dump zvols at all
Drew Fisher <drew.fisher@oracle.com>
parents: 1080
diff changeset
   644
        zvol.  This is done because Zvol objects can either be
449ba0d2a6b8 7038169 TI doesn't create swap or dump zvols at all
Drew Fisher <drew.fisher@oracle.com>
parents: 1080
diff changeset
   645
        created via Zpool.add_zvol or by simple instantiation
449ba0d2a6b8 7038169 TI doesn't create swap or dump zvols at all
Drew Fisher <drew.fisher@oracle.com>
parents: 1080
diff changeset
   646
        (Zvol("tank/zv"))
449ba0d2a6b8 7038169 TI doesn't create swap or dump zvols at all
Drew Fisher <drew.fisher@oracle.com>
parents: 1080
diff changeset
   647
        """
449ba0d2a6b8 7038169 TI doesn't create swap or dump zvols at all
Drew Fisher <drew.fisher@oracle.com>
parents: 1080
diff changeset
   648
        if self.parent is not None:
449ba0d2a6b8 7038169 TI doesn't create swap or dump zvols at all
Drew Fisher <drew.fisher@oracle.com>
parents: 1080
diff changeset
   649
            return os.path.join(self.parent.name, self.name)
449ba0d2a6b8 7038169 TI doesn't create swap or dump zvols at all
Drew Fisher <drew.fisher@oracle.com>
parents: 1080
diff changeset
   650
        else:
449ba0d2a6b8 7038169 TI doesn't create swap or dump zvols at all
Drew Fisher <drew.fisher@oracle.com>
parents: 1080
diff changeset
   651
            return self.name
449ba0d2a6b8 7038169 TI doesn't create swap or dump zvols at all
Drew Fisher <drew.fisher@oracle.com>
parents: 1080
diff changeset
   652
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   653
    def to_xml(self):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   654
        element = etree.Element("zvol")
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   655
        element.set("name", self.name)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   656
        element.set("action", self.action)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   657
        element.set("use", self.use)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   658
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   659
        size = etree.SubElement(element, "size")
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   660
        size.set("val", str(self.size))
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   661
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   662
        return element
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   663
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   664
    @classmethod
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   665
    def can_handle(cls, element):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   666
        """ Returns True if element has:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   667
        - the tag 'zvol'
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   668
        - a name attribute
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   669
        - an action attribute
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   670
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   671
        otherwise return False
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   672
        """
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   673
        if element.tag != "zvol":
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   674
            return False
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   675
        if element.get("name") is None:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   676
            return False
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   677
        return True
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   678
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   679
    @classmethod
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   680
    def from_xml(cls, element):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   681
        name = element.get("name")
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   682
        action = element.get("action")
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   683
        use = element.get("use")
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   684
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   685
        zvol = Zvol(name)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   686
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   687
        size = element.find("size")
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   688
        if size is not None:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   689
            if size.get("val") is None:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   690
                raise ParsingError("Size element must contain a 'val' " + \
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   691
                                   "attribute")
1625
d13be924336e 7070697 size element for zvols should be optional
nirmal27<Nirmal.Agarwal@oracle.com>
parents: 1623
diff changeset
   692
d13be924336e 7070697 size element for zvols should be optional
nirmal27<Nirmal.Agarwal@oracle.com>
parents: 1623
diff changeset
   693
            # 'max' is allowed only for swap zvol
d13be924336e 7070697 size element for zvols should be optional
nirmal27<Nirmal.Agarwal@oracle.com>
parents: 1623
diff changeset
   694
            if size.get("val") == "max":
d13be924336e 7070697 size element for zvols should be optional
nirmal27<Nirmal.Agarwal@oracle.com>
parents: 1623
diff changeset
   695
                if use is None or use != "swap":
d13be924336e 7070697 size element for zvols should be optional
nirmal27<Nirmal.Agarwal@oracle.com>
parents: 1623
diff changeset
   696
                    raise ParsingError("'max' value for 'val' attribute is "
d13be924336e 7070697 size element for zvols should be optional
nirmal27<Nirmal.Agarwal@oracle.com>
parents: 1623
diff changeset
   697
                                       "applicable only for swap zvol.")
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   698
            zvol.size = size.get("val")
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   699
        else:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   700
            raise ParsingError("Zvol element must contain a size subelement")
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   701
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   702
        zvol.action = action
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   703
        if use is not None:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   704
            zvol.use = use
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   705
        return zvol
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   706
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   707
    @property
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   708
    def exists(self):
1094
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   709
        """ property to check for the existance of the zvol
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   710
        """
1083
449ba0d2a6b8 7038169 TI doesn't create swap or dump zvols at all
Drew Fisher <drew.fisher@oracle.com>
parents: 1080
diff changeset
   711
        cmd = [ZFS, "list", self.full_name]
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   712
        p = Popen.check_call(cmd, stdout=Popen.STORE, stderr=Popen.STORE,
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   713
                             check_result=Popen.ANY)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   714
        return p.returncode == 0
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   715
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   716
    def create(self, dry_run):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   717
        """ method to create a zvol.
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   718
        """
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   719
        if not self.exists:
1080
23095028f96a 7037795 TI Fails to create Zvols if Zvol.size is a Size object
Drew Fisher <drew.fisher@oracle.com>
parents: 1070
diff changeset
   720
            # check self.size.  If it's a Size() object, convert it to a string
23095028f96a 7037795 TI Fails to create Zvols if Zvol.size is a Size object
Drew Fisher <drew.fisher@oracle.com>
parents: 1070
diff changeset
   721
            # ZFS expects
23095028f96a 7037795 TI Fails to create Zvols if Zvol.size is a Size object
Drew Fisher <drew.fisher@oracle.com>
parents: 1070
diff changeset
   722
            if isinstance(self.size, Size):
23095028f96a 7037795 TI Fails to create Zvols if Zvol.size is a Size object
Drew Fisher <drew.fisher@oracle.com>
parents: 1070
diff changeset
   723
                zvol_size = str(int(self.size.get(Size.mb_units))) + "M"
1625
d13be924336e 7070697 size element for zvols should be optional
nirmal27<Nirmal.Agarwal@oracle.com>
parents: 1623
diff changeset
   724
            elif self.size == "max":
d13be924336e 7070697 size element for zvols should be optional
nirmal27<Nirmal.Agarwal@oracle.com>
parents: 1623
diff changeset
   725
                # Allocate 90 % of available space on pool to zvol.
d13be924336e 7070697 size element for zvols should be optional
nirmal27<Nirmal.Agarwal@oracle.com>
parents: 1623
diff changeset
   726
                # Size of zvol is capped to 90 % to avoid full zpool
d13be924336e 7070697 size element for zvols should be optional
nirmal27<Nirmal.Agarwal@oracle.com>
parents: 1623
diff changeset
   727
                # issues.
d13be924336e 7070697 size element for zvols should be optional
nirmal27<Nirmal.Agarwal@oracle.com>
parents: 1623
diff changeset
   728
                if self.parent is not None:
d13be924336e 7070697 size element for zvols should be optional
nirmal27<Nirmal.Agarwal@oracle.com>
parents: 1623
diff changeset
   729
                    fs = Filesystem(self.parent.name)
d13be924336e 7070697 size element for zvols should be optional
nirmal27<Nirmal.Agarwal@oracle.com>
parents: 1623
diff changeset
   730
                    fs_size = Size(fs.get("available"))
d13be924336e 7070697 size element for zvols should be optional
nirmal27<Nirmal.Agarwal@oracle.com>
parents: 1623
diff changeset
   731
                    zvol_size = str(int(fs_size.get(Size.mb_units) * 0.9)) + \
d13be924336e 7070697 size element for zvols should be optional
nirmal27<Nirmal.Agarwal@oracle.com>
parents: 1623
diff changeset
   732
                                    "M"
d13be924336e 7070697 size element for zvols should be optional
nirmal27<Nirmal.Agarwal@oracle.com>
parents: 1623
diff changeset
   733
                    self.size = Size(zvol_size)
1080
23095028f96a 7037795 TI Fails to create Zvols if Zvol.size is a Size object
Drew Fisher <drew.fisher@oracle.com>
parents: 1070
diff changeset
   734
            else:
23095028f96a 7037795 TI Fails to create Zvols if Zvol.size is a Size object
Drew Fisher <drew.fisher@oracle.com>
parents: 1070
diff changeset
   735
                zvol_size = self.size
23095028f96a 7037795 TI Fails to create Zvols if Zvol.size is a Size object
Drew Fisher <drew.fisher@oracle.com>
parents: 1070
diff changeset
   736
23095028f96a 7037795 TI Fails to create Zvols if Zvol.size is a Size object
Drew Fisher <drew.fisher@oracle.com>
parents: 1070
diff changeset
   737
            cmd = [ZFS, "create", "-p", "-V", zvol_size]
1083
449ba0d2a6b8 7038169 TI doesn't create swap or dump zvols at all
Drew Fisher <drew.fisher@oracle.com>
parents: 1080
diff changeset
   738
1273
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   739
            zfs_options = self.get_first_child(class_type=Options)
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   740
            if zfs_options is not None:
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   741
                cmd.extend(zfs_options.get_arg_list())
1083
449ba0d2a6b8 7038169 TI doesn't create swap or dump zvols at all
Drew Fisher <drew.fisher@oracle.com>
parents: 1080
diff changeset
   742
449ba0d2a6b8 7038169 TI doesn't create swap or dump zvols at all
Drew Fisher <drew.fisher@oracle.com>
parents: 1080
diff changeset
   743
            cmd.append(self.full_name)
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   744
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   745
            if not dry_run:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   746
                Popen.check_call(cmd, stdout=Popen.STORE, stderr=Popen.STORE,
1394
7f92dd7e7416 7077329 Problem with install/textui
Karen Tung <Karen.Tung@oracle.com>
parents: 1370
diff changeset
   747
                                 logger=ILN, env={"LC_ALL": "C"})
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   748
1083
449ba0d2a6b8 7038169 TI doesn't create swap or dump zvols at all
Drew Fisher <drew.fisher@oracle.com>
parents: 1080
diff changeset
   749
                # check the "use" attribute
449ba0d2a6b8 7038169 TI doesn't create swap or dump zvols at all
Drew Fisher <drew.fisher@oracle.com>
parents: 1080
diff changeset
   750
                if self.use == "swap":
449ba0d2a6b8 7038169 TI doesn't create swap or dump zvols at all
Drew Fisher <drew.fisher@oracle.com>
parents: 1080
diff changeset
   751
                    cmd = [SWAP, "-a",
449ba0d2a6b8 7038169 TI doesn't create swap or dump zvols at all
Drew Fisher <drew.fisher@oracle.com>
parents: 1080
diff changeset
   752
                           os.path.join("/dev/zvol/dsk", self.full_name)]
449ba0d2a6b8 7038169 TI doesn't create swap or dump zvols at all
Drew Fisher <drew.fisher@oracle.com>
parents: 1080
diff changeset
   753
                    Popen.check_call(cmd, stdout=Popen.STORE,
1088
d6f83c93a86c 7038486 physical _label_disk() using incorrect logger.
Drew Fisher <drew.fisher@oracle.com>
parents: 1083
diff changeset
   754
                                     stderr=Popen.STORE, logger=ILN,
d6f83c93a86c 7038486 physical _label_disk() using incorrect logger.
Drew Fisher <drew.fisher@oracle.com>
parents: 1083
diff changeset
   755
                                     stderr_loglevel=logging.DEBUG)
1083
449ba0d2a6b8 7038169 TI doesn't create swap or dump zvols at all
Drew Fisher <drew.fisher@oracle.com>
parents: 1080
diff changeset
   756
                elif self.use == "dump":
1326
c919d80b4704 6994666 savecore should be enabled by default
Dave Miner <dave.miner@oracle.com>
parents: 1319
diff changeset
   757
                    cmd = [DUMPADM, "-d",
1083
449ba0d2a6b8 7038169 TI doesn't create swap or dump zvols at all
Drew Fisher <drew.fisher@oracle.com>
parents: 1080
diff changeset
   758
                           os.path.join("/dev/zvol/dsk", self.full_name)]
1370
0e49021cc774 6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents: 1326
diff changeset
   759
                    if self.create_failure_ok:
0e49021cc774 6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents: 1326
diff changeset
   760
                        results = (0, 1)
0e49021cc774 6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents: 1326
diff changeset
   761
                    else:
0e49021cc774 6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents: 1326
diff changeset
   762
                        results = (0,)
0e49021cc774 6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents: 1326
diff changeset
   763
                    p = Popen.check_call(cmd, stdout=Popen.STORE,
0e49021cc774 6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents: 1326
diff changeset
   764
                                         stderr=Popen.STORE, logger=ILN,
0e49021cc774 6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents: 1326
diff changeset
   765
                                         stderr_loglevel=logging.DEBUG,
0e49021cc774 6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents: 1326
diff changeset
   766
                                         check_result=results)
0e49021cc774 6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents: 1326
diff changeset
   767
                    if p.returncode == 1:
0e49021cc774 6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents: 1326
diff changeset
   768
                        logger = logging.getLogger(ILN)
0e49021cc774 6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents: 1326
diff changeset
   769
                        logger.warning("Unable to create dump Zvol "
0e49021cc774 6987821 text installer fails on systems with large memory
Karen Tung <Karen.Tung@oracle.com>
parents: 1326
diff changeset
   770
                                       "with size %s." % zvol_size)
1083
449ba0d2a6b8 7038169 TI doesn't create swap or dump zvols at all
Drew Fisher <drew.fisher@oracle.com>
parents: 1080
diff changeset
   771
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   772
    def destroy(self, dry_run):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   773
        """ method to destroy a zvol.
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   774
        """
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   775
        if self.exists:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   776
            if not dry_run:
1131
321737de165e 7044170 AI should support "s" for sector units
Drew Fisher <drew.fisher@oracle.com>
parents: 1128
diff changeset
   777
                full_path = os.path.join("/dev/zvol/dsk", self.full_name)
321737de165e 7044170 AI should support "s" for sector units
Drew Fisher <drew.fisher@oracle.com>
parents: 1128
diff changeset
   778
321737de165e 7044170 AI should support "s" for sector units
Drew Fisher <drew.fisher@oracle.com>
parents: 1128
diff changeset
   779
                # look to see if this zvol is in use by swap.  If so, remove it
321737de165e 7044170 AI should support "s" for sector units
Drew Fisher <drew.fisher@oracle.com>
parents: 1128
diff changeset
   780
                # from swap control
321737de165e 7044170 AI should support "s" for sector units
Drew Fisher <drew.fisher@oracle.com>
parents: 1128
diff changeset
   781
                cmd = [SWAP, "-l"]
321737de165e 7044170 AI should support "s" for sector units
Drew Fisher <drew.fisher@oracle.com>
parents: 1128
diff changeset
   782
                p = Popen.check_call(cmd, stdout=Popen.STORE,
321737de165e 7044170 AI should support "s" for sector units
Drew Fisher <drew.fisher@oracle.com>
parents: 1128
diff changeset
   783
                    stderr=Popen.STORE, logger=ILN, check_result=Popen.ANY,
321737de165e 7044170 AI should support "s" for sector units
Drew Fisher <drew.fisher@oracle.com>
parents: 1128
diff changeset
   784
                    stderr_loglevel=logging.DEBUG)
321737de165e 7044170 AI should support "s" for sector units
Drew Fisher <drew.fisher@oracle.com>
parents: 1128
diff changeset
   785
321737de165e 7044170 AI should support "s" for sector units
Drew Fisher <drew.fisher@oracle.com>
parents: 1128
diff changeset
   786
                # remove the header and look for the zvol
321737de165e 7044170 AI should support "s" for sector units
Drew Fisher <drew.fisher@oracle.com>
parents: 1128
diff changeset
   787
                swap_list = p.stdout.splitlines()[1:]
321737de165e 7044170 AI should support "s" for sector units
Drew Fisher <drew.fisher@oracle.com>
parents: 1128
diff changeset
   788
                for entry in swap_list:
321737de165e 7044170 AI should support "s" for sector units
Drew Fisher <drew.fisher@oracle.com>
parents: 1128
diff changeset
   789
                    if entry.startswith(full_path):
321737de165e 7044170 AI should support "s" for sector units
Drew Fisher <drew.fisher@oracle.com>
parents: 1128
diff changeset
   790
                        cmd = [SWAP, "-d", full_path]
321737de165e 7044170 AI should support "s" for sector units
Drew Fisher <drew.fisher@oracle.com>
parents: 1128
diff changeset
   791
                        Popen.check_call(cmd, stdout=Popen.STORE,
321737de165e 7044170 AI should support "s" for sector units
Drew Fisher <drew.fisher@oracle.com>
parents: 1128
diff changeset
   792
                            stderr=Popen.STORE, logger=ILN,
321737de165e 7044170 AI should support "s" for sector units
Drew Fisher <drew.fisher@oracle.com>
parents: 1128
diff changeset
   793
                            stderr_loglevel=logging.DEBUG)
321737de165e 7044170 AI should support "s" for sector units
Drew Fisher <drew.fisher@oracle.com>
parents: 1128
diff changeset
   794
321737de165e 7044170 AI should support "s" for sector units
Drew Fisher <drew.fisher@oracle.com>
parents: 1128
diff changeset
   795
                # TODO:  CR 6910925 prevents the removal of zvols marked for
321737de165e 7044170 AI should support "s" for sector units
Drew Fisher <drew.fisher@oracle.com>
parents: 1128
diff changeset
   796
                # use by dumpadm.  Until that bug is fixed, we can not remove
321737de165e 7044170 AI should support "s" for sector units
Drew Fisher <drew.fisher@oracle.com>
parents: 1128
diff changeset
   797
                # the zvol from dumpadm control or destroy the zvol.
321737de165e 7044170 AI should support "s" for sector units
Drew Fisher <drew.fisher@oracle.com>
parents: 1128
diff changeset
   798
321737de165e 7044170 AI should support "s" for sector units
Drew Fisher <drew.fisher@oracle.com>
parents: 1128
diff changeset
   799
                # look to see if this zvol is under dumpadm control.  If it is,
321737de165e 7044170 AI should support "s" for sector units
Drew Fisher <drew.fisher@oracle.com>
parents: 1128
diff changeset
   800
                # we can't remove it.
321737de165e 7044170 AI should support "s" for sector units
Drew Fisher <drew.fisher@oracle.com>
parents: 1128
diff changeset
   801
                p = Popen.check_call([DUMPADM], stdout=Popen.STORE,
321737de165e 7044170 AI should support "s" for sector units
Drew Fisher <drew.fisher@oracle.com>
parents: 1128
diff changeset
   802
                    stderr=Popen.STORE, logger=ILN)
321737de165e 7044170 AI should support "s" for sector units
Drew Fisher <drew.fisher@oracle.com>
parents: 1128
diff changeset
   803
321737de165e 7044170 AI should support "s" for sector units
Drew Fisher <drew.fisher@oracle.com>
parents: 1128
diff changeset
   804
                for line in p.stdout.splitlines():
321737de165e 7044170 AI should support "s" for sector units
Drew Fisher <drew.fisher@oracle.com>
parents: 1128
diff changeset
   805
                    if line.lstrip().startswith("Dump device:"):
321737de165e 7044170 AI should support "s" for sector units
Drew Fisher <drew.fisher@oracle.com>
parents: 1128
diff changeset
   806
                        if full_path in line:
321737de165e 7044170 AI should support "s" for sector units
Drew Fisher <drew.fisher@oracle.com>
parents: 1128
diff changeset
   807
                            logger = logging.getLogger(ILN)
321737de165e 7044170 AI should support "s" for sector units
Drew Fisher <drew.fisher@oracle.com>
parents: 1128
diff changeset
   808
                            logger.warning("Unable to destroy Zvol '%s' as it "
321737de165e 7044170 AI should support "s" for sector units
Drew Fisher <drew.fisher@oracle.com>
parents: 1128
diff changeset
   809
                                "is under dumpadm control" % self.full_name)
321737de165e 7044170 AI should support "s" for sector units
Drew Fisher <drew.fisher@oracle.com>
parents: 1128
diff changeset
   810
                            break
321737de165e 7044170 AI should support "s" for sector units
Drew Fisher <drew.fisher@oracle.com>
parents: 1128
diff changeset
   811
                else:
321737de165e 7044170 AI should support "s" for sector units
Drew Fisher <drew.fisher@oracle.com>
parents: 1128
diff changeset
   812
                    cmd = [ZFS, "destroy", self.full_name]
321737de165e 7044170 AI should support "s" for sector units
Drew Fisher <drew.fisher@oracle.com>
parents: 1128
diff changeset
   813
                    Popen.check_call(cmd, stdout=Popen.STORE,
321737de165e 7044170 AI should support "s" for sector units
Drew Fisher <drew.fisher@oracle.com>
parents: 1128
diff changeset
   814
                                     stderr=Popen.STORE, logger=ILN)
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   815
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   816
    def __repr__(self):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   817
        return "Zvol: name=%s; action=%s; use=%s; size=%s" % \
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   818
            (self.name, self.action, self.use, self.size)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   819
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   820
    def resize(self, new_size, size_units=Size.gb_units):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   821
        """ resize() - method to resize a Zvol object.
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   822
        """
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   823
        # delete the existing Zvol from the parent's shadow list
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   824
        self.delete()
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   825
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   826
        # re-insert it with the new size
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   827
        self.parent.add_zvol(self.name, new_size, size_units)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   828
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   829
        # reset the attributes with the proper values
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   830
        self.size = str(new_size) + str(size_units)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   831
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   832
1273
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   833
class Options(DataObjectDict):
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   834
    """Base class for all ZFS options variations"""
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   835
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   836
    TAG_NAME = "options"
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   837
    SUB_TAG_NAME = "option"
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   838
    OPTIONS_PARAM_STR = "-o"
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   839
1273
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   840
    def __init__(self, name, data_dict, generate_xml=False):
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   841
        """Initialize ZfsOptionsDict.  """
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   842
1273
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   843
        # Ignoring some passed arguments:
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   844
        # - Name is None since there is no name attribute allowed in its XML.
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   845
        # - Set generate_xml to True always to ensure it reads/writes XML
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   846
        super(Options, self).__init__(None, data_dict,
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   847
                                             generate_xml=True)
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   848
1273
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   849
    def get_arg_list(self, quote=False):
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   850
        """Returns a list of arguments suitable for passing to Popen"""
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   851
        arg_list = list()
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   852
        for key in self.data_dict:
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   853
            arg_list.append(self.OPTIONS_PARAM_STR)
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   854
            # Dont quote value in default case since Popen will pass it
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   855
            # directly causing zpool/zfs command to fail.
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   856
            if quote:
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   857
                arg_list.append('%s="%s"' % (key, self.data_dict[key]))
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   858
            else:
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   859
                arg_list.append('%s=%s' % (key, self.data_dict[key]))
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   860
        return arg_list
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   861
1273
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   862
    def get_nvlist(self):
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   863
        """Returns options as an NVList"""
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   864
        nv_list = nvl.NVList()
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   865
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   866
        if self.data_dict is None or len(self.data_dict) == 0:
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   867
            return nv_list
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   868
1273
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   869
        for key in self.data_dict:
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   870
            nv_list.add_string(key, self.data_dict[key])
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   871
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   872
        return nv_list
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   873
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   874
    def __str__(self):
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   875
        return "%s: %s" % (self.__class__.__name__,
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   876
                          " ".join(self.get_arg_list(quote=True)))
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   877
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   878
1273
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   879
class PoolOptions(Options):
1094
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   880
    """ pool_options DOC node definition
1273
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   881
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   882
        Its a DataObjectDict using the tags like:
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   883
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   884
        <pool_options>
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   885
          <option name="opt1" value="val1"/>
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   886
          <option name="opt2" value="val2"/>
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   887
          ...
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   888
          <option name="optN" value="valN"/>
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   889
        </pool_options>
1094
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   890
    """
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   891
    TAG_NAME = "pool_options"
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   892
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   893
1273
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   894
class DatasetOptions(Options):
1094
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   895
    """ dataset_options DOC node definition
1273
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   896
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   897
        Its a DataObjectDict using the tags like:
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   898
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   899
        <dataset_options>
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   900
          <option name="opt1" value="val1"/>
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   901
          <option name="opt2" value="val2"/>
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   902
          ...
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   903
          <option name="optN" value="valN"/>
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   904
        </dataset_options>
1094
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   905
    """
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   906
    TAG_NAME = "dataset_options"
1273
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   907
    OPTIONS_PARAM_STR = "-O"  # -O used to pass ZFS options to a pool
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   908
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   909
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   910
class BE(DataObject):
1094
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   911
    """ be DOC node definition
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   912
    """
1237
1422ef107116 7059003 test_target_selection_* tests failing if BE "solaris" exists
Matt Keenan <matt.keenan@oracle.com>
parents: 1236
diff changeset
   913
    def __init__(self, initial_name=None):
1422ef107116 7059003 test_target_selection_* tests failing if BE "solaris" exists
Matt Keenan <matt.keenan@oracle.com>
parents: 1236
diff changeset
   914
        if initial_name is None:
1422ef107116 7059003 test_target_selection_* tests failing if BE "solaris" exists
Matt Keenan <matt.keenan@oracle.com>
parents: 1236
diff changeset
   915
            initial_name = DEFAULT_BE_NAME
1151
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1140
diff changeset
   916
        super(BE, self).__init__(initial_name)
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   917
1151
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1140
diff changeset
   918
        self.created_name = None
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1140
diff changeset
   919
        self.initial_name = initial_name
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   920
        self.mountpoint = None
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   921
1151
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1140
diff changeset
   922
    @property
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1140
diff changeset
   923
    def name(self):
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1140
diff changeset
   924
        return self.created_name or self.initial_name
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1140
diff changeset
   925
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   926
    def to_xml(self):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   927
        element = etree.Element("be")
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   928
        element.set("name", self.name)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   929
        return element
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   930
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   931
    @classmethod
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   932
    def can_handle(cls, element):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   933
        """ Returns True if element has:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   934
        - the tag 'BE'
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   935
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   936
        otherwise return False
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   937
        """
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   938
        if element.tag != "be":
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   939
            return False
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   940
        return True
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   941
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   942
    @classmethod
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   943
    def from_xml(cls, element):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   944
        name = element.get("name")
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   945
        if name:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   946
            be = BE(name)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   947
        else:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   948
            be = BE()
1273
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   949
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   950
        return be
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   951
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   952
    @property
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   953
    def exists(self):
1094
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   954
        """ property to check for the existance of the BE
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   955
        """
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   956
        exists = be_list(self.name)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   957
        return exists
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   958
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   959
    def __repr__(self):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   960
        s = "BE: name=%s" % self.name
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   961
        if self.mountpoint is not None:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   962
            s += "; mountpoint=%s" % self.mountpoint
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   963
        return s
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   964
1151
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1140
diff changeset
   965
    def init(self, dry_run, pool_name="rpool", nested_be=False,
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1140
diff changeset
   966
            fs_list=None, fs_zfs_properties=None,
1319
4de70a67fb1e 7061417 Ensure BE name is unique in AI
Matt Keenan <matt.keenan@oracle.com>
parents: 1273
diff changeset
   967
            shared_fs_list=None, shared_fs_zfs_properties=None,
4de70a67fb1e 7061417 Ensure BE name is unique in AI
Matt Keenan <matt.keenan@oracle.com>
parents: 1273
diff changeset
   968
            allow_auto_naming=True):
1273
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   969
        """ method to initialize a BE by creating the empty datasets for
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   970
            the BE.
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   971
        """
1151
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1140
diff changeset
   972
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1140
diff changeset
   973
        if not dry_run:
1273
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   974
            be_options = self.get_first_child(class_type=Options)
1151
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1140
diff changeset
   975
            new_name = be_init(self.name, pool_name, nested_be=nested_be,
1273
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1237
diff changeset
   976
                zfs_properties=be_options,
1151
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1140
diff changeset
   977
                fs_list=fs_list, fs_zfs_properties=fs_zfs_properties,
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1140
diff changeset
   978
                shared_fs_list=shared_fs_list,
1319
4de70a67fb1e 7061417 Ensure BE name is unique in AI
Matt Keenan <matt.keenan@oracle.com>
parents: 1273
diff changeset
   979
                shared_fs_zfs_properties=shared_fs_zfs_properties,
4de70a67fb1e 7061417 Ensure BE name is unique in AI
Matt Keenan <matt.keenan@oracle.com>
parents: 1273
diff changeset
   980
                allow_auto_naming=allow_auto_naming)
1151
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1140
diff changeset
   981
1319
4de70a67fb1e 7061417 Ensure BE name is unique in AI
Matt Keenan <matt.keenan@oracle.com>
parents: 1273
diff changeset
   982
            # If auto-naming is allowed, the processes of initialize a new BE
1151
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1140
diff changeset
   983
            # may have ended up creating a different name.  We reap that
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1140
diff changeset
   984
            # here and update the stored name in this BE object accordingly.
1319
4de70a67fb1e 7061417 Ensure BE name is unique in AI
Matt Keenan <matt.keenan@oracle.com>
parents: 1273
diff changeset
   985
            if allow_auto_naming and new_name is not None:
1151
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1140
diff changeset
   986
                logger = logging.getLogger(ILN)
1319
4de70a67fb1e 7061417 Ensure BE name is unique in AI
Matt Keenan <matt.keenan@oracle.com>
parents: 1273
diff changeset
   987
                logger.debug("Initialized BE with auto name: %s" % new_name)
1151
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1140
diff changeset
   988
                self.created_name = new_name
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1140
diff changeset
   989
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1140
diff changeset
   990
            # if a mountpoint was specified, mount the freshly
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1140
diff changeset
   991
            # created BE and create the mountpoint in the process
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1140
diff changeset
   992
            # if it does not exist
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1140
diff changeset
   993
            if self.mountpoint is not None:
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1140
diff changeset
   994
                if nested_be:
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1140
diff changeset
   995
                    self.mount(self.mountpoint, dry_run, pool_name)
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1140
diff changeset
   996
                else:
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   997
                    self.mount(self.mountpoint, dry_run)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   998
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   999
    def destroy(self, dry_run):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1000
        """ method to destroy a BE.
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1001
        """
1151
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1140
diff changeset
  1002
        if not dry_run:
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1140
diff changeset
  1003
            be_destroy(self.name)
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1004
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1005
    def activate(self, dry_run):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1006
        """ method to activate a BE.
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1007
        """
1151
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1140
diff changeset
  1008
        if not dry_run:
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1140
diff changeset
  1009
            be_activate(self.name)
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1010
1151
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1140
diff changeset
  1011
    def mount(self, mountpoint, dry_run, altpool=None):
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1012
        """ method to mount a BE.
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1013
        """
1151
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1140
diff changeset
  1014
        if not dry_run:
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1140
diff changeset
  1015
            if not os.path.exists(mountpoint):
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1140
diff changeset
  1016
                os.makedirs(mountpoint)
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1140
diff changeset
  1017
            be_mount(self.name, mountpoint, altpool)
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1140
diff changeset
  1018
            self.mountpoint = mountpoint
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1019
1151
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1140
diff changeset
  1020
    def unmount(self, dry_run, altpool=None):
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1021
        """ method to unmount a BE.
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1022
        """
1151
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1140
diff changeset
  1023
        if not dry_run:
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1140
diff changeset
  1024
            be_unmount(self.name, altpool)
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1140
diff changeset
  1025
            self.mountpoint = None
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1026
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1027
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1028
class Lofi(object):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1029
    """ class representing a loopback file interface. The backing-store does
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1030
    not have to exist; it can be created
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1031
    """
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1032
    def __init__(self, ramdisk, mountpoint, size=0):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1033
        """ constructor for the class
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1034
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1035
        ramdisk - path to the file to use as a backing store
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1036
        mountpoint - path to mount the file as a loopback device
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1037
        size - size of the file to create
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1038
        """
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1039
        self.ramdisk = ramdisk
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1040
        self.mountpoint = mountpoint
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1041
        self.size = size
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1042
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1043
        self.lofi_device = None
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1044
        self._mounted = False
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1045
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1046
        self.nbpi = None
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1047
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1048
    @property
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1049
    def exists(self):
1094
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
  1050
        """ property to check for the existance of the ramdisk
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
  1051
        """
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1052
        return os.path.exists(self.ramdisk)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1053
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1054
    @property
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1055
    def mounted(self):
1094
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
  1056
        """ property to return a boolean value representing if the lofi device
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
  1057
        is currently mounted.
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
  1058
        """
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1059
        return self._mounted
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1060
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1061
    @mounted.setter
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1062
    def mounted(self, val):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1063
        self._mounted = val
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1064
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1065
    def create_ramdisk(self, dry_run):
1094
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
  1066
        """ create_ramdisk - method to create the ramdisk, if needed
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
  1067
        """
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1068
        if not self.exists:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1069
            # create the file first
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1070
            cmd = [MKFILE, "%dk" % self.size, self.ramdisk]
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1071
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1072
            if not dry_run:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1073
                Popen.check_call(cmd, stdout=Popen.STORE, stderr=Popen.STORE,
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1074
                                 logger=ILN)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1075
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1076
    def create(self, dry_run):
1094
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
  1077
        """ create - method to create, newfs and mount a lofi device
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
  1078
        """
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1079
        # create the ramdisk (if needed)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1080
        self.create_ramdisk(dry_run)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1081
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1082
        # create the lofi device
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1083
        cmd = [LOFIADM, "-a", self.ramdisk]
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1084
        if not dry_run:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1085
            p = Popen.check_call(cmd, stdout=Popen.STORE, stderr=Popen.STORE,
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1086
                                 logger=ILN)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1087
            self.lofi_device = p.stdout.strip()
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1088
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1089
        # newfs it
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1090
        cmd = [NEWFS, "-m", "0", "-o", "space"]
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1091
        if self.nbpi is not None:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1092
            cmd.append("-i")
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1093
            cmd.append(str(self.nbpi))
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1094
        cmd.append(self.lofi_device.replace("lofi", "rlofi"))
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1095
        if not dry_run:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1096
            # due to the way Popen works, we can not assign a logger to the
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1097
            # call, otherwise the process will complete before we can pass the
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1098
            # "y" to newfs
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1099
            logger = logging.getLogger(ILN)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1100
            logger.debug("Executing: %s" % " ".join(cmd))
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1101
            p = Popen(cmd, stdin=Popen.PIPE, stdout=Popen.DEVNULL,
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1102
                      stderr=Popen.DEVNULL)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1103
            p.communicate("y\n")
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1104
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1105
        # ensure a directory exists to mount the lofi device to
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1106
        if not os.path.exists(self.mountpoint) and not dry_run:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1107
            os.makedirs(self.mountpoint)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1108
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1109
        cmd = [MOUNT, "-F", "ufs", "-o", "rw", self.lofi_device,
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1110
               self.mountpoint]
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1111
        if not dry_run:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1112
            Popen.check_call(cmd, stdout=Popen.STORE, stderr=Popen.STORE,
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1113
                             logger=ILN)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1114
        self.mounted = True
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1115
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1116
    def unmount(self, dry_run):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1117
        """ method to unmount the ramdisk
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1118
        """
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1119
        if self.mounted:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1120
            cmd = [UMOUNT, "-f", self.mountpoint]
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1121
            if not dry_run:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1122
                Popen.check_call(cmd, stdout=Popen.STORE, stderr=Popen.STORE,
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1123
                                 logger=ILN)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1124
            self.mounted = False
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1125
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1126
    def destroy(self, dry_run):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1127
        """ method to unmount and destroy the lofi device
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1128
        """
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1129
        if not self.exists:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1130
            return
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1131
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1132
        self.unmount(dry_run)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1133
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1134
        # there is an undocumented -f flag to lofiadm to 'force' the destroy
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1135
        cmd = [LOFIADM, "-f", "-d", self.lofi_device]
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1136
        if not dry_run:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1137
            Popen.check_call(cmd, stdout=Popen.STORE, stderr=Popen.STORE,
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1138
                             logger=ILN)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1139
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1140
    def __repr__(self):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1141
        return "Lofi: ramdisk=%s; mountpoint=%s; size=%s; lofi_device=%s; " \
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1142
               "mounted=%s; nbpi=%s" % \
1094
75cedb5286c2 7039887 Size class needs to support up zetabyte
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
  1143
               (self.ramdisk, self.mountpoint, self.size, self.lofi_device,
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1144
               self._mounted, self.nbpi)