usr/src/lib/install_target/discovery.py
author Drew Fisher <drew.fisher@oracle.com>
Mon, 08 Aug 2011 10:05:19 -0600
changeset 1372 bd82f26440d5
parent 1355 7e6507b2a970
permissions -rw-r--r--
7076301 discovery.py has the wrong path to svcadm
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
#
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    24
# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
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
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    27
""" discovery.py - target discovery checkpoint.  Attempts to find all target
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    28
devices on the given system.  The Data Object Cache is populated with the
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    29
information.
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    30
"""
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    31
1129
e8fa7dfb2df2 7045566 Target Discovery displaying fstyp errors for unknow slices
Drew Fisher <drew.fisher@oracle.com>
parents: 1128
diff changeset
    32
import logging
1355
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
    33
import os
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    34
import platform
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    35
import re
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    36
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    37
import solaris_install.target.vdevs as vdevs
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    38
1218
ead7c7d814c7 7052696 TI install fails with target discovery in snv_167 if there is floppy drive
Drew Fisher <drew.fisher@oracle.com>
parents: 1213
diff changeset
    39
from bootmgmt.pysol import di_find_prop
ead7c7d814c7 7052696 TI install fails with target discovery in snv_167 if there is floppy drive
Drew Fisher <drew.fisher@oracle.com>
parents: 1213
diff changeset
    40
1323
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
    41
from solaris_install import CalledProcessError, Popen, run
1197
41dc6c86a4c3 7020411 support in TD/TI for interfaces that provide CRO information in libdevinfo
Drew Fisher <drew.fisher@oracle.com>
parents: 1151
diff changeset
    42
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
    43
from solaris_install.engine import InstallEngine
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    44
from solaris_install.engine.checkpoint import AbstractCheckpoint as Checkpoint
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    45
from solaris_install.logger import INSTALL_LOGGER_NAME as ILN
1197
41dc6c86a4c3 7020411 support in TD/TI for interfaces that provide CRO information in libdevinfo
Drew Fisher <drew.fisher@oracle.com>
parents: 1151
diff changeset
    46
from solaris_install.target import CRO_LABEL, Target
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    47
from solaris_install.target.libbe import be
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    48
from solaris_install.target.libdevinfo import devinfo
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    49
from solaris_install.target.libdiskmgt import const, diskmgt
1128
a401bf4396fc 7044533 cud_ai: ERROR: an exception occurred : 'naccessible'
Drew Fisher <drew.fisher@oracle.com>
parents: 1122
diff changeset
    50
from solaris_install.target.libdiskmgt.attributes import DMMediaAttr
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    51
from solaris_install.target.logical import BE, Filesystem, Logical, Zpool, Zvol
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    52
from solaris_install.target.physical import Disk, DiskProp, DiskGeometry, \
1323
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
    53
    DiskKeyword, Iscsi, Partition, Slice
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    54
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
    55
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    56
1197
41dc6c86a4c3 7020411 support in TD/TI for interfaces that provide CRO information in libdevinfo
Drew Fisher <drew.fisher@oracle.com>
parents: 1151
diff changeset
    57
CROINFO = "/usr/sbin/croinfo"
1323
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
    58
DEVFSADM = "/usr/sbin/devfsadm"
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
    59
DHCPINFO = "/sbin/dhcpinfo"
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    60
EEPROM = "/usr/sbin/eeprom"
1122
d30415c63b07 7041406 Disk class needs prop_matches() method
Drew Fisher <drew.fisher@oracle.com>
parents: 1118
diff changeset
    61
FSTYP = "/usr/sbin/fstyp"
1323
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
    62
ISCSIADM = "/usr/sbin/iscsiadm"
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    63
PRTVTOC = "/usr/sbin/prtvtoc"
1323
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
    64
SVCS = "/usr/bin/svcs"
1372
bd82f26440d5 7076301 discovery.py has the wrong path to svcadm
Drew Fisher <drew.fisher@oracle.com>
parents: 1355
diff changeset
    65
SVCADM = "/usr/sbin/svcadm"
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    66
ZFS = "/usr/sbin/zfs"
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    67
ZPOOL = "/usr/sbin/zpool"
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    68
ZVOL_PATH = "/dev/zvol/dsk"
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
DISK_SEARCH_NAME = "disk"
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    71
ZPOOL_SEARCH_NAME = "zpool"
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    72
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    73
# regex for matching c#t#d# OR c#d# strings
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    74
DISK_RE = "c\d+(?:t\d+)?d\d+"
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
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    77
class TargetDiscovery(Checkpoint):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    78
    """ Discover all logical and physical devices on the system.
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
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    81
    def __init__(self, name, search_name=None, search_type=None):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    82
        super(TargetDiscovery, self).__init__(name)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    83
1355
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
    84
        self.dry_run = False
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
    85
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    86
        self.eng = InstallEngine.get_instance()
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    87
        self.doc = self.eng.data_object_cache
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
        # create a root node to insert all discovered objects into
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    90
        self.root = Target(Target.DISCOVERED)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    91
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    92
        # user specified search criteria
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    93
        self.search_name = search_name
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    94
        self.search_type = search_type
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    95
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    96
        # list of discovered swap and dump zvols
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    97
        self.swap_list = list()
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    98
        self.dump_list = list()
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    99
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   100
        # eeprom diag mode and bootdisk value
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   101
        self.sparc_diag_mode = False
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   102
        self.bootdisk = None
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
        # kernel architecture
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   105
        self.arch = platform.processor()
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   106
1197
41dc6c86a4c3 7020411 support in TD/TI for interfaces that provide CRO information in libdevinfo
Drew Fisher <drew.fisher@oracle.com>
parents: 1151
diff changeset
   107
        # croinfo dictionary
41dc6c86a4c3 7020411 support in TD/TI for interfaces that provide CRO information in libdevinfo
Drew Fisher <drew.fisher@oracle.com>
parents: 1151
diff changeset
   108
        self.cro_dict = dict()
41dc6c86a4c3 7020411 support in TD/TI for interfaces that provide CRO information in libdevinfo
Drew Fisher <drew.fisher@oracle.com>
parents: 1151
diff changeset
   109
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   110
    def is_bootdisk(self, name):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   111
        """ is_bootdisk() -- simple method to compare the name of the disk in
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   112
        question with what libdevinfo reports as the bootdisk
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   113
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   114
        name - ctd name of the disk to check
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   115
        """
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   116
        # cache the answer so we don't do multiple lookups to libdevinfo
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   117
        if self.bootdisk is None:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   118
            self.bootdisk = devinfo.get_curr_bootdisk()
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   119
        return self.bootdisk == name
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   120
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   121
    def get_progress_estimate(self):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   122
        # XXX
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   123
        return 1
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 discover_disk(self, drive):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   126
        """ discover_disk - method to discover a physical disk's attributes,
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   127
        partitions and slices
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
        drive - which physical drive to parse
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   130
        """
1118
c87a271a3921 7043165 Not possible to tell if a Partition was specified in the XML without a start_sector.
Drew Fisher <drew.fisher@oracle.com>
parents: 1117
diff changeset
   131
        # create a DOC object for this drive.  Set validate_children to False
1117
ae9a188dcfcc 7043629 Target shadow list should not adjust boundaries on discovered partitions
Drew Fisher <drew.fisher@oracle.com>
parents: 1110
diff changeset
   132
        # so the shadow code doesn't adjust the start sector or size for any
ae9a188dcfcc 7043629 Target shadow list should not adjust boundaries on discovered partitions
Drew Fisher <drew.fisher@oracle.com>
parents: 1110
diff changeset
   133
        # children discovered
1118
c87a271a3921 7043165 Not possible to tell if a Partition was specified in the XML without a start_sector.
Drew Fisher <drew.fisher@oracle.com>
parents: 1117
diff changeset
   134
        new_disk = Disk("disk", validate_children=False)
1070
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
        # extract drive attributes and media information
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   137
        drive_attributes = drive.attributes
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   138
        drive_media = drive.media
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   139
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   140
        # set attributes for the disk
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   141
        new_disk.ctd = drive.aliases[0].name
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   142
        new_disk.devid = drive.name
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   143
        new_disk.iscdrom = drive.cdrom
1134
2f672493c0c0 7043048 TD needs to store/compare disk names with the /pci device notation
Drew Fisher <drew.fisher@oracle.com>
parents: 1133
diff changeset
   144
        new_disk.opath = drive_attributes.opath
2f672493c0c0 7043048 TD needs to store/compare disk names with the /pci device notation
Drew Fisher <drew.fisher@oracle.com>
parents: 1133
diff changeset
   145
1236
2f3a9d3aa9cb 7051027 Installer not enabling disk write cache when entire disk selected
Drew Fisher <drew.fisher@oracle.com>
parents: 1218
diff changeset
   146
        # if a drive is offline or down return None
2f3a9d3aa9cb 7051027 Installer not enabling disk write cache when entire disk selected
Drew Fisher <drew.fisher@oracle.com>
parents: 1218
diff changeset
   147
        if drive_attributes.status == "DOWN":
2f3a9d3aa9cb 7051027 Installer not enabling disk write cache when entire disk selected
Drew Fisher <drew.fisher@oracle.com>
parents: 1218
diff changeset
   148
            self.logger.debug("disk '%s' is offline" % new_disk.ctd)
2f3a9d3aa9cb 7051027 Installer not enabling disk write cache when entire disk selected
Drew Fisher <drew.fisher@oracle.com>
parents: 1218
diff changeset
   149
            return None
2f3a9d3aa9cb 7051027 Installer not enabling disk write cache when entire disk selected
Drew Fisher <drew.fisher@oracle.com>
parents: 1218
diff changeset
   150
1134
2f672493c0c0 7043048 TD needs to store/compare disk names with the /pci device notation
Drew Fisher <drew.fisher@oracle.com>
parents: 1133
diff changeset
   151
        # set the devpath
2f672493c0c0 7043048 TD needs to store/compare disk names with the /pci device notation
Drew Fisher <drew.fisher@oracle.com>
parents: 1133
diff changeset
   152
        if os.path.islink(drive_attributes.opath):
2f672493c0c0 7043048 TD needs to store/compare disk names with the /pci device notation
Drew Fisher <drew.fisher@oracle.com>
parents: 1133
diff changeset
   153
            link = os.readlink(drive_attributes.opath)
2f672493c0c0 7043048 TD needs to store/compare disk names with the /pci device notation
Drew Fisher <drew.fisher@oracle.com>
parents: 1133
diff changeset
   154
2f672493c0c0 7043048 TD needs to store/compare disk names with the /pci device notation
Drew Fisher <drew.fisher@oracle.com>
parents: 1133
diff changeset
   155
            # clean up the link to get rid of the leading '../../devices/' and
2f672493c0c0 7043048 TD needs to store/compare disk names with the /pci device notation
Drew Fisher <drew.fisher@oracle.com>
parents: 1133
diff changeset
   156
            # trailing minor name
2f672493c0c0 7043048 TD needs to store/compare disk names with the /pci device notation
Drew Fisher <drew.fisher@oracle.com>
parents: 1133
diff changeset
   157
            if link.startswith("../../devices") and ":" in link:
2f672493c0c0 7043048 TD needs to store/compare disk names with the /pci device notation
Drew Fisher <drew.fisher@oracle.com>
parents: 1133
diff changeset
   158
                link = link.partition("../../devices")[2].rpartition(":")[0]
2f672493c0c0 7043048 TD needs to store/compare disk names with the /pci device notation
Drew Fisher <drew.fisher@oracle.com>
parents: 1133
diff changeset
   159
                new_disk.devpath = link
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   160
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   161
        # check for SPARC eeprom settings which would interfere with finding
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   162
        # the boot disk
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   163
        if self.arch == "sparc":
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   164
            if not self.sparc_diag_mode:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   165
                # check eeprom settings
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   166
                cmd = [EEPROM, "diag-switch?"]
1323
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   167
                p = run(cmd)
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   168
                diag_switch_value = p.stdout.partition("=")[2]
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   169
                if diag_switch_value.strip().lower() == "true":
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   170
                    # set a variable so we don't check every single disk and
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   171
                    # log a message
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   172
                    self.sparc_diag_mode = True
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   173
                    self.logger.info("Unable to determine bootdisk with " + \
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   174
                                     "diag-switch? eeprom setting set to " + \
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   175
                                     "'true'.  Please set diag-switch? " + \
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   176
                                     "to false and reboot the system")
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   177
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   178
        # check for the bootdisk
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   179
        if not self.sparc_diag_mode:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   180
            if self.is_bootdisk(new_disk.ctd):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   181
                new_disk.disk_keyword = DiskKeyword()
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   182
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   183
        # set vendor information for the drive
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   184
        new_disk.disk_prop = DiskProp()
1241
3d4bf09186b2 7060266 snv_167 PV domU install on OVM-222-RC1 fails, "No installation target disks found"
Drew Fisher <drew.fisher@oracle.com>
parents: 1236
diff changeset
   185
        if drive.controllers:
3d4bf09186b2 7060266 snv_167 PV domU install on OVM-222-RC1 fails, "No installation target disks found"
Drew Fisher <drew.fisher@oracle.com>
parents: 1236
diff changeset
   186
            new_disk.disk_prop.dev_type = drive.controllers[0].attributes.type
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   187
        new_disk.disk_prop.dev_vendor = drive_attributes.vendor_id
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   188
1197
41dc6c86a4c3 7020411 support in TD/TI for interfaces that provide CRO information in libdevinfo
Drew Fisher <drew.fisher@oracle.com>
parents: 1151
diff changeset
   189
        # set the alias and receptacle for disks, if possible
41dc6c86a4c3 7020411 support in TD/TI for interfaces that provide CRO information in libdevinfo
Drew Fisher <drew.fisher@oracle.com>
parents: 1151
diff changeset
   190
        if not new_disk.iscdrom and new_disk.ctd in self.cro_dict:
41dc6c86a4c3 7020411 support in TD/TI for interfaces that provide CRO information in libdevinfo
Drew Fisher <drew.fisher@oracle.com>
parents: 1151
diff changeset
   191
            new_disk.disk_prop.dev_chassis = self.cro_dict[new_disk.ctd][1]
41dc6c86a4c3 7020411 support in TD/TI for interfaces that provide CRO information in libdevinfo
Drew Fisher <drew.fisher@oracle.com>
parents: 1151
diff changeset
   192
            new_disk.receptacle = self.cro_dict[new_disk.ctd][2]
41dc6c86a4c3 7020411 support in TD/TI for interfaces that provide CRO information in libdevinfo
Drew Fisher <drew.fisher@oracle.com>
parents: 1151
diff changeset
   193
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   194
        # walk the media node to extract partitions and slices
1218
ead7c7d814c7 7052696 TI install fails with target discovery in snv_167 if there is floppy drive
Drew Fisher <drew.fisher@oracle.com>
parents: 1213
diff changeset
   195
        if drive_media is None:
ead7c7d814c7 7052696 TI install fails with target discovery in snv_167 if there is floppy drive
Drew Fisher <drew.fisher@oracle.com>
parents: 1213
diff changeset
   196
            # since the drive has no media, we can't determine any attributes
ead7c7d814c7 7052696 TI install fails with target discovery in snv_167 if there is floppy drive
Drew Fisher <drew.fisher@oracle.com>
parents: 1213
diff changeset
   197
            # about it (geometry, slices, partitions, etc.) so simply return
ead7c7d814c7 7052696 TI install fails with target discovery in snv_167 if there is floppy drive
Drew Fisher <drew.fisher@oracle.com>
parents: 1213
diff changeset
   198
            # None
ead7c7d814c7 7052696 TI install fails with target discovery in snv_167 if there is floppy drive
Drew Fisher <drew.fisher@oracle.com>
parents: 1213
diff changeset
   199
            return None
ead7c7d814c7 7052696 TI install fails with target discovery in snv_167 if there is floppy drive
Drew Fisher <drew.fisher@oracle.com>
parents: 1213
diff changeset
   200
        else:
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   201
            # store the attributes locally so libdiskmgt doesn't have to keep
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   202
            # looking them up
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   203
            drive_media_attributes = drive_media.attributes
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   204
1355
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   205
            # if a drive comes back without basic information, skip discovery
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   206
            # entirely
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   207
            if not DMMediaAttr.NACCESSIBLE in drive_media_attributes or \
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   208
               not DMMediaAttr.BLOCKSIZE in drive_media_attributes:
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   209
                self.logger.debug("skipping discovery of %s" % new_disk.ctd)
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   210
                return None
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   211
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   212
            # retrieve the drive's geometry
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   213
            new_disk = self.set_geometry(drive_media_attributes, new_disk)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   214
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   215
            # keep a list of slices already visited so they're not discovered
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   216
            # again later
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   217
            visited_slices = []
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   218
1088
d6f83c93a86c 7038486 physical _label_disk() using incorrect logger.
Drew Fisher <drew.fisher@oracle.com>
parents: 1070
diff changeset
   219
            # if this system is x86 and the drive has slices but no fdisk
d6f83c93a86c 7038486 physical _label_disk() using incorrect logger.
Drew Fisher <drew.fisher@oracle.com>
parents: 1070
diff changeset
   220
            # partitions, don't report any of the slices
d6f83c93a86c 7038486 physical _label_disk() using incorrect logger.
Drew Fisher <drew.fisher@oracle.com>
parents: 1070
diff changeset
   221
            if self.arch == "i386" and drive_media.slices and not \
d6f83c93a86c 7038486 physical _label_disk() using incorrect logger.
Drew Fisher <drew.fisher@oracle.com>
parents: 1070
diff changeset
   222
               drive_media.partitions:
d6f83c93a86c 7038486 physical _label_disk() using incorrect logger.
Drew Fisher <drew.fisher@oracle.com>
parents: 1070
diff changeset
   223
                return new_disk
d6f83c93a86c 7038486 physical _label_disk() using incorrect logger.
Drew Fisher <drew.fisher@oracle.com>
parents: 1070
diff changeset
   224
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   225
            for partition in drive_media.partitions:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   226
                new_partition = self.discover_partition(partition,
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   227
                    drive_media_attributes.blocksize)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   228
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   229
                # add the partition to the disk object
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   230
                new_disk.insert_children(new_partition)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   231
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   232
                # check for slices associated with this partition.  If found,
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   233
                # add them as children
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   234
                for slc in partition.media.slices:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   235
                    # discover the slice
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   236
                    new_slice = self.discover_slice(slc,
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   237
                        drive_media_attributes.blocksize)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   238
1122
d30415c63b07 7041406 Disk class needs prop_matches() method
Drew Fisher <drew.fisher@oracle.com>
parents: 1118
diff changeset
   239
                    # constrain when a slice is added to the DOC.  We only want
d30415c63b07 7041406 Disk class needs prop_matches() method
Drew Fisher <drew.fisher@oracle.com>
parents: 1118
diff changeset
   240
                    # to add a slice when:
d30415c63b07 7041406 Disk class needs prop_matches() method
Drew Fisher <drew.fisher@oracle.com>
parents: 1118
diff changeset
   241
                    # - the partition id is a Solaris partition (non EFI)
d30415c63b07 7041406 Disk class needs prop_matches() method
Drew Fisher <drew.fisher@oracle.com>
parents: 1118
diff changeset
   242
                    # - the fstyp is 'zfs' (for EFI labeled disks)
d30415c63b07 7041406 Disk class needs prop_matches() method
Drew Fisher <drew.fisher@oracle.com>
parents: 1118
diff changeset
   243
                    # - the fstyp is 'unknown_fstyp' AND it's slice 8 (for EFI
d30415c63b07 7041406 Disk class needs prop_matches() method
Drew Fisher <drew.fisher@oracle.com>
parents: 1118
diff changeset
   244
                    #   labeled disks)
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   245
                    if new_partition.is_solaris:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   246
                        new_partition.insert_children(new_slice)
1122
d30415c63b07 7041406 Disk class needs prop_matches() method
Drew Fisher <drew.fisher@oracle.com>
parents: 1118
diff changeset
   247
                    elif new_partition.part_type == 238:
d30415c63b07 7041406 Disk class needs prop_matches() method
Drew Fisher <drew.fisher@oracle.com>
parents: 1118
diff changeset
   248
                        # call fstyp to try to figure out the slice type
d30415c63b07 7041406 Disk class needs prop_matches() method
Drew Fisher <drew.fisher@oracle.com>
parents: 1118
diff changeset
   249
                        cmd = [FSTYP, slc.name]
1323
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   250
                        p = run(cmd, check_result=Popen.ANY)
1122
d30415c63b07 7041406 Disk class needs prop_matches() method
Drew Fisher <drew.fisher@oracle.com>
parents: 1118
diff changeset
   251
                        if p.returncode == 0:
d30415c63b07 7041406 Disk class needs prop_matches() method
Drew Fisher <drew.fisher@oracle.com>
parents: 1118
diff changeset
   252
                            if p.stdout.strip() == "zfs":
d30415c63b07 7041406 Disk class needs prop_matches() method
Drew Fisher <drew.fisher@oracle.com>
parents: 1118
diff changeset
   253
                                # add the slice since it's used by zfs
d30415c63b07 7041406 Disk class needs prop_matches() method
Drew Fisher <drew.fisher@oracle.com>
parents: 1118
diff changeset
   254
                                new_partition.insert_children(new_slice)
d30415c63b07 7041406 Disk class needs prop_matches() method
Drew Fisher <drew.fisher@oracle.com>
parents: 1118
diff changeset
   255
                        else:
d30415c63b07 7041406 Disk class needs prop_matches() method
Drew Fisher <drew.fisher@oracle.com>
parents: 1118
diff changeset
   256
                            if p.stderr.startswith("unknown_fstyp") and \
d30415c63b07 7041406 Disk class needs prop_matches() method
Drew Fisher <drew.fisher@oracle.com>
parents: 1118
diff changeset
   257
                                new_slice.name == "8":
d30415c63b07 7041406 Disk class needs prop_matches() method
Drew Fisher <drew.fisher@oracle.com>
parents: 1118
diff changeset
   258
                                # add the slice since it's an EFI boot slice
d30415c63b07 7041406 Disk class needs prop_matches() method
Drew Fisher <drew.fisher@oracle.com>
parents: 1118
diff changeset
   259
                                new_partition.insert_children(new_slice)
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   260
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   261
                    # keep a record this slice so it's not discovered again
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   262
                    visited_slices.append(slc.name)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   263
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   264
            for slc in drive_media.slices:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   265
                # discover the slice if it's not already been found
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   266
                if slc.name not in visited_slices:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   267
                    new_slice = self.discover_slice(slc,
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   268
                        drive_media_attributes.blocksize)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   269
                    new_disk.insert_children(new_slice)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   270
1218
ead7c7d814c7 7052696 TI install fails with target discovery in snv_167 if there is floppy drive
Drew Fisher <drew.fisher@oracle.com>
parents: 1213
diff changeset
   271
            return new_disk
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   272
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   273
    def set_geometry(self, dma, new_disk):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   274
        """ set_geometry() - method to set the geometry of the Disk DOC object
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   275
        from the libdiskmgt drive object.
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   276
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   277
        dma - the drive's media attributes as returned by libdiskmgt
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   278
        new_disk - Disk DOC object
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
        new_geometry = None
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   281
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   282
        # If the disk has a GPT label (or no label), ncylinders will be
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   283
        # None
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   284
        if dma.ncylinders is None:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   285
            new_disk.disk_prop.dev_size = Size(str(dma.naccessible) +
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   286
                                               Size.sector_units)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   287
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   288
            # set only the blocksize (not the cylinder size)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   289
            new_geometry = DiskGeometry(dma.blocksize, None)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   290
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   291
            # set the label of the disk, if possible
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   292
            if dma.efi:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   293
                new_disk.label = "GPT"
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   294
                new_geometry.efi = True
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   295
        else:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   296
            new_disk.label = "VTOC"
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   297
1132
d6766742607d 7043031 TD failing to discover volume name(disk.volid), thus AI cannot match disks on volume name
Drew Fisher <drew.fisher@oracle.com>
parents: 1129
diff changeset
   298
            # set the disk's volid
d6766742607d 7043031 TD failing to discover volume name(disk.volid), thus AI cannot match disks on volume name
Drew Fisher <drew.fisher@oracle.com>
parents: 1129
diff changeset
   299
            new_disk.volid = dma.label
d6766742607d 7043031 TD failing to discover volume name(disk.volid), thus AI cannot match disks on volume name
Drew Fisher <drew.fisher@oracle.com>
parents: 1129
diff changeset
   300
1146
ff4a15105908 7047609 Geometry settings for x86 VTOC disks is wrong
Drew Fisher <drew.fisher@oracle.com>
parents: 1134
diff changeset
   301
            ncyl = dma.ncylinders
ff4a15105908 7047609 Geometry settings for x86 VTOC disks is wrong
Drew Fisher <drew.fisher@oracle.com>
parents: 1134
diff changeset
   302
            nhead = dma.nheads
ff4a15105908 7047609 Geometry settings for x86 VTOC disks is wrong
Drew Fisher <drew.fisher@oracle.com>
parents: 1134
diff changeset
   303
            nsect = dma.nsectors
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   304
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   305
            new_disk.disk_prop.dev_size = Size(str(ncyl * nhead * nsect) +
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   306
                                               Size.sector_units)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   307
            new_geometry = DiskGeometry(dma.blocksize, nhead * nsect)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   308
            new_geometry.ncyl = ncyl
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   309
            new_geometry.nheads = nhead
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   310
            new_geometry.nsectors = nsect
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   311
            new_disk.geometry = new_geometry
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   312
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   313
        return new_disk
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
    def discover_pseudo(self, controller):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   316
        """ discover_psuedo - method to discover pseudo controller information,
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   317
        usually zvol swap and dump
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   318
        """
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   319
        for drive in controller.drives:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   320
            for slc in drive.media.slices:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   321
                stats = slc.use_stats
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   322
                if "used_by" in stats:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   323
                    if stats["used_name"][0] == "dump":
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   324
                        if slc.name.startswith(ZVOL_PATH):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   325
                            # remove the /dev/zvol/dsk from the path
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   326
                            self.dump_list.append(slc.name[14:])
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   327
                    if stats["used_name"][0] == "swap":
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   328
                        if slc.name.startswith(ZVOL_PATH):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   329
                            # remove the /dev/zvol/dsk from the path
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   330
                            self.swap_list.append(slc.name[14:])
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   331
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   332
    def discover_partition(self, partition, blocksize):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   333
        """ discover_partition - method to discover a physical disk's
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   334
        partition layout
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   335
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   336
        partition - partition object as discovered by ldm
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   337
        blocksize - blocksize of the disk
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   338
        """
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   339
        # store the attributes locally so libdiskmgt doesn't have to keep
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   340
        # looking them up
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   341
        partition_attributes = partition.attributes
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
        # partition name is ctdp path.  Split the string on "p"
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   344
        root_path, _none, index = partition.name.partition("p")
1117
ae9a188dcfcc 7043629 Target shadow list should not adjust boundaries on discovered partitions
Drew Fisher <drew.fisher@oracle.com>
parents: 1110
diff changeset
   345
1118
c87a271a3921 7043165 Not possible to tell if a Partition was specified in the XML without a start_sector.
Drew Fisher <drew.fisher@oracle.com>
parents: 1117
diff changeset
   346
        # create a DOC object for this partition.  Set validate_children to
1117
ae9a188dcfcc 7043629 Target shadow list should not adjust boundaries on discovered partitions
Drew Fisher <drew.fisher@oracle.com>
parents: 1110
diff changeset
   347
        # False so the shadow code doesn't adjust the start sector or size for
ae9a188dcfcc 7043629 Target shadow list should not adjust boundaries on discovered partitions
Drew Fisher <drew.fisher@oracle.com>
parents: 1110
diff changeset
   348
        # any children discovered
1118
c87a271a3921 7043165 Not possible to tell if a Partition was specified in the XML without a start_sector.
Drew Fisher <drew.fisher@oracle.com>
parents: 1117
diff changeset
   349
        new_partition = Partition(index, validate_children=False)
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   350
        new_partition.action = "preserve"
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   351
        new_partition.part_type = partition_attributes.id
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   352
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   353
        # check the partition's ID to set the partition type correctly
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   354
        if partition_attributes.id == \
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   355
            Partition.name_to_num("Solaris/Linux swap"):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   356
            try:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   357
                # try to call prtvtoc on slice 2.  If it succeeds, this is a
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   358
                # solaris1 partition.
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   359
                slice2 = root_path + "s2"
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   360
                cmd = [PRTVTOC, slice2]
1323
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   361
                run(cmd, stdout=Popen.DEVNULL)
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   362
            except CalledProcessError:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   363
                # the call to prtvtoc failed which means this partition is
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   364
                # Linux swap. To be sure, prtvtoc failure might also mean an
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   365
                # unlabeled Solaris1 partition but we aren't going to worry
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   366
                # about that for now. Displaying an unlabeled (and therefore
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   367
                # unused) Solaris1 partition should not have any unforeseen
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   368
                # consequences in terms of data loss.
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   369
                new_partition.is_linux_swap = True
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   370
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   371
        new_partition.size = Size(str(partition_attributes.nsectors) + \
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   372
                             Size.sector_units, blocksize=blocksize)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   373
        new_partition.start_sector = long(partition_attributes.relsect)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   374
        new_partition.size_in_sectors = partition_attributes.nsectors
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   375
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   376
        return new_partition
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   377
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   378
    def discover_slice(self, slc, blocksize):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   379
        """ discover_slices - method to discover a physical disk's slice
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   380
        layout.
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   381
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   382
        slc - slice object as discovered by ldm
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   383
        blocksize - blocksize of the disk
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   384
        """
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   385
        # store the attributes locally so libdiskmgt doesn't have to keep
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   386
        # looking them up
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   387
        slc_attributes = slc.attributes
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   388
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   389
        new_slice = Slice(str(slc_attributes.index))
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   390
        new_slice.action = "preserve"
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   391
        new_slice.tag = slc_attributes.tag
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   392
        new_slice.flag = slc_attributes.flag
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   393
        new_slice.size = Size(str(slc_attributes.size) + Size.sector_units,
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   394
                              blocksize=blocksize)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   395
        new_slice.start_sector = long(slc_attributes.start)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   396
        new_slice.size_in_sectors = slc_attributes.size
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
        stats = slc.use_stats
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   399
        if "used_by" in stats:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   400
            new_slice.in_use = stats
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   401
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   402
        return new_slice
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
    def discover_zpools(self, search_name=""):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   405
        """ discover_zpools - method to walk zpool list output to create Zpool
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   406
        objects.  Returns a logical DOC object with all zpools populated.
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   407
        """
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   408
        # create a logical element
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   409
        logical = Logical("logical")
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   410
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   411
        # set noswap and nodump to True until a zvol is found otherwise
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   412
        logical.noswap = True
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   413
        logical.nodump = True
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   414
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   415
        # retreive the list of zpools
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   416
        cmd = [ZPOOL, "list", "-H", "-o", "name"]
1323
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   417
        p = run(cmd)
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   418
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   419
        # Get the list of zpools
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   420
        zpool_list = p.stdout.splitlines()
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   421
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   422
        # walk the list and populate the DOC
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   423
        for zpool_name in zpool_list:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   424
            # if the user has specified a specific search name, only run
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   425
            # discovery on that particular pool name
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   426
            if search_name and zpool_name != search_name:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   427
                continue
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   428
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   429
            self.logger.debug("Populating DOC for zpool:  %s", zpool_name)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   430
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   431
            # create a new Zpool DOC object and insert it
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   432
            zpool = Zpool(zpool_name)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   433
            zpool.action = "preserve"
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   434
            logical.insert_children(zpool)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   435
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   436
            # check to see if the zpool is the boot pool
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   437
            cmd = [ZPOOL, "list", "-H", "-o", "bootfs", zpool_name]
1323
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   438
            p = run(cmd)
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   439
            if p.stdout.rstrip() != "-":
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   440
                zpool.is_root = True
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   441
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   442
            # get the mountpoint of the zpool
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   443
            cmd = [ZFS, "get", "-H", "-o", "value", "mountpoint", zpool_name]
1323
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   444
            p = run(cmd)
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   445
            zpool.mountpoint = p.stdout.strip()
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   446
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   447
            # set the vdev_mapping on each physical object in the DOC tree for
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   448
            # this zpool
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   449
            self.set_vdev_map(zpool)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   450
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   451
            # for each zpool, get all of its datasets
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   452
            cmd = [ZFS, "list", "-r", "-H", "-o",
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   453
                   "name,type,used,mountpoint", zpool_name]
1323
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   454
            p = run(cmd)
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   455
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   456
            # walk each dataset and create the appropriate DOC objects for
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   457
            # each.  Skip the first line of list output, as the top level
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   458
            # dataset (also the dataset with the same name as that of the
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   459
            # zpool) may have a different mountpoint than the zpool.
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   460
            for dataset in p.stdout.rstrip().split("\n")[1:]:
1205
53ccbd18aee3 7049761 cylinder adjustment rounds down and gaps are incorrect
Drew Fisher <drew.fisher@oracle.com>
parents: 1197
diff changeset
   461
                try:
53ccbd18aee3 7049761 cylinder adjustment rounds down and gaps are incorrect
Drew Fisher <drew.fisher@oracle.com>
parents: 1197
diff changeset
   462
                    name, ds_type, ds_size, mountpoint = dataset.split(None, 3)
53ccbd18aee3 7049761 cylinder adjustment rounds down and gaps are incorrect
Drew Fisher <drew.fisher@oracle.com>
parents: 1197
diff changeset
   463
                except ValueError as err:
53ccbd18aee3 7049761 cylinder adjustment rounds down and gaps are incorrect
Drew Fisher <drew.fisher@oracle.com>
parents: 1197
diff changeset
   464
                    # trap on ValueError so any inconsistencies are captured
1218
ead7c7d814c7 7052696 TI install fails with target discovery in snv_167 if there is floppy drive
Drew Fisher <drew.fisher@oracle.com>
parents: 1213
diff changeset
   465
                    self.logger.debug("Unable to process dataset: %r" %
1205
53ccbd18aee3 7049761 cylinder adjustment rounds down and gaps are incorrect
Drew Fisher <drew.fisher@oracle.com>
parents: 1197
diff changeset
   466
                                      dataset)
53ccbd18aee3 7049761 cylinder adjustment rounds down and gaps are incorrect
Drew Fisher <drew.fisher@oracle.com>
parents: 1197
diff changeset
   467
                    self.logger.debug(str(err))
53ccbd18aee3 7049761 cylinder adjustment rounds down and gaps are incorrect
Drew Fisher <drew.fisher@oracle.com>
parents: 1197
diff changeset
   468
                    continue
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   469
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   470
                # fix the name field to remove the name of the pool
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   471
                name = name.partition(zpool_name + "/")[2]
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   472
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   473
                if ds_type == "filesystem":
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   474
                    obj = Filesystem(name)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   475
                    obj.mountpoint = mountpoint
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   476
                elif ds_type == "volume":
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   477
                    obj = Zvol(name)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   478
                    # the output from zfs list returns values like "37G" and
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   479
                    # "3.2M".  The Size() class expects "37GB" and "3.2MB".
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   480
                    obj.size = Size(ds_size + "B")
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   481
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   482
                    # check for swap/dump.  If there's a match, set the zvol
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   483
                    # 'use' attribute and the noswap/nodump attribute of
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   484
                    # logical.  The zpool name needs to be re-attached to the
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   485
                    # zvol name to match what was already parsed
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   486
                    if os.path.join(zpool_name, name) in self.swap_list:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   487
                        obj.use = "swap"
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   488
                        logical.noswap = False
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   489
                    if os.path.join(zpool_name, name) in self.dump_list:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   490
                        obj.use = "dump"
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   491
                        logical.nodump = False
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
                obj.action = "preserve"
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   494
                zpool.insert_children(obj)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   495
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   496
        return logical
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   497
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   498
    def set_vdev_map(self, zpool):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   499
        """ set_vdev_map() - walk the vdev_map to set the zpool's vdev entries
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   500
        and update existing physical DOC entries with the proper in_zpool and
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   501
        in_vdev attributes.
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   502
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   503
        zpool - zpool DOC object
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   504
        """
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   505
        # get the list of Disk DOC objects already inserted
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   506
        disklist = self.root.get_children(class_type=Disk)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   507
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   508
        # get the vdev mappings for this pool
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   509
        vdev_map = vdevs._get_vdev_mapping(zpool.name)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   510
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   511
        for vdev_type, vdev_entries in vdev_map.iteritems():
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   512
            in_vdev_label = "%s-%s" % (zpool.name, vdev_type)
1133
92b5354dba1a 7046012 TD setting redundancy type on discovered Vdev's incorrectly
Drew Fisher <drew.fisher@oracle.com>
parents: 1132
diff changeset
   513
            if vdev_type != "none":
92b5354dba1a 7046012 TD setting redundancy type on discovered Vdev's incorrectly
Drew Fisher <drew.fisher@oracle.com>
parents: 1132
diff changeset
   514
                redundancy = vdev_type.partition("-")[0]
92b5354dba1a 7046012 TD setting redundancy type on discovered Vdev's incorrectly
Drew Fisher <drew.fisher@oracle.com>
parents: 1132
diff changeset
   515
            else:
92b5354dba1a 7046012 TD setting redundancy type on discovered Vdev's incorrectly
Drew Fisher <drew.fisher@oracle.com>
parents: 1132
diff changeset
   516
                redundancy = vdev_type
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   517
1107
859894cb3839 7041859 TD/TI assumes that a disk with just in_zpool, no in_vdev, belongs in an unspecified vdev
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   518
            # create a Vdev DOC entry for the vdev_type
1133
92b5354dba1a 7046012 TD setting redundancy type on discovered Vdev's incorrectly
Drew Fisher <drew.fisher@oracle.com>
parents: 1132
diff changeset
   519
            zpool.add_vdev(in_vdev_label, redundancy)
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   520
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   521
            for full_entry in vdev_entries:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   522
                # remove the device path from the entry
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   523
                entry = full_entry.rpartition("/dev/dsk/")[2]
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   524
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   525
                # try to partition the entry for slices
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   526
                (vdev_ctd, vdev_letter, vdev_index) = entry.rpartition("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
                # if the entry is not a slice, vdev_letter and index will
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   529
                # be empty strings
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   530
                if not vdev_letter:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   531
                    # try to partition the entry for partitions
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   532
                    (vdev_ctd, vdev_letter, vdev_index) = \
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   533
                        entry.rpartition("p")
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   534
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   535
                    # if the entry is also not a partition skip this entry
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   536
                    if not vdev_letter:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   537
                        continue
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   538
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   539
                # walk the disk list looking for a matching ctd
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   540
                for disk in disklist:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   541
                    if hasattr(disk, "ctd"):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   542
                        if disk.ctd == vdev_ctd:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   543
                            # this disk is a match
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   544
                            if vdev_letter == "s":
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   545
                                child_list = disk.get_descendants(
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   546
                                    class_type=Slice)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   547
                            elif vdev_letter == "p":
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   548
                                child_list = disk.get_descendants(
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   549
                                    class_type=Partition)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   550
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   551
                            # walk the child list and look for a matching name
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   552
                            for child in child_list:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   553
                                if child.name == vdev_index:
1107
859894cb3839 7041859 TD/TI assumes that a disk with just in_zpool, no in_vdev, belongs in an unspecified vdev
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   554
                                    # set the in_zpool and in_vdev attributes
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   555
                                    child.in_zpool = zpool.name
1107
859894cb3839 7041859 TD/TI assumes that a disk with just in_zpool, no in_vdev, belongs in an unspecified vdev
Drew Fisher <drew.fisher@oracle.com>
parents: 1088
diff changeset
   556
                                    child.in_vdev = in_vdev_label
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   557
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   558
                            # break out of the disklist walk
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   559
                            break
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   560
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   561
    def discover_BEs(self, zpool_name="", name=None):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   562
        """ discover_BEs - method to discover all Boot Environments (BEs) on
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   563
        the system.
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   564
        """
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   565
        be_list = be.be_list(name)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   566
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   567
        # walk each zpool already discovered and add BEs as necessary
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   568
        for zpool in self.root.get_descendants(class_type=Zpool):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   569
            # check to see if we only want a subset of zpools.
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   570
            if zpool_name and zpool_name != zpool.name:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   571
                continue
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   572
1110
17d2e44bfc3f 7042314 solaris_install.target.be.be_list() should get information about which is the active BE
Drew Fisher <drew.fisher@oracle.com>
parents: 1107
diff changeset
   573
            for be_name, be_pool, root_ds, is_active in be_list:
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   574
                if be_pool == zpool.name:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   575
                    zpool.insert_children(BE(be_name))
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   576
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   577
    def discover_entire_system(self, add_physical=True):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   578
        """ discover_entire_system - populates the root node of the DOC tree
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   579
        with the entire physical layout of the system.
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   580
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   581
        add_physical - boolean value to signal if physical targets should be
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   582
        added to the DOC.
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   583
        """
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   584
        # to find all the drives on the system, first start with the
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   585
        # controllers
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   586
        for controller in diskmgt.descriptors_by_type(const.CONTROLLER):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   587
            # trap on the "/pseudo" controller (zvol swap and dump)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   588
            if controller.name == "/pseudo" and add_physical:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   589
                self.discover_pseudo(controller)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   590
            else:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   591
                # extract every drive on the given controller
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   592
                for drive in controller.drives:
1218
ead7c7d814c7 7052696 TI install fails with target discovery in snv_167 if there is floppy drive
Drew Fisher <drew.fisher@oracle.com>
parents: 1213
diff changeset
   593
                    # skip USB floppy drives
ead7c7d814c7 7052696 TI install fails with target discovery in snv_167 if there is floppy drive
Drew Fisher <drew.fisher@oracle.com>
parents: 1213
diff changeset
   594
                    if controller.attributes is not None and \
ead7c7d814c7 7052696 TI install fails with target discovery in snv_167 if there is floppy drive
Drew Fisher <drew.fisher@oracle.com>
parents: 1213
diff changeset
   595
                       controller.attributes.type == const.CTYPE_USB:
ead7c7d814c7 7052696 TI install fails with target discovery in snv_167 if there is floppy drive
Drew Fisher <drew.fisher@oracle.com>
parents: 1213
diff changeset
   596
                        try:
ead7c7d814c7 7052696 TI install fails with target discovery in snv_167 if there is floppy drive
Drew Fisher <drew.fisher@oracle.com>
parents: 1213
diff changeset
   597
                            di_props = di_find_prop("compatible",
ead7c7d814c7 7052696 TI install fails with target discovery in snv_167 if there is floppy drive
Drew Fisher <drew.fisher@oracle.com>
parents: 1213
diff changeset
   598
                                                    controller.name)
ead7c7d814c7 7052696 TI install fails with target discovery in snv_167 if there is floppy drive
Drew Fisher <drew.fisher@oracle.com>
parents: 1213
diff changeset
   599
                        except Exception:
ead7c7d814c7 7052696 TI install fails with target discovery in snv_167 if there is floppy drive
Drew Fisher <drew.fisher@oracle.com>
parents: 1213
diff changeset
   600
                            di_props = list()
ead7c7d814c7 7052696 TI install fails with target discovery in snv_167 if there is floppy drive
Drew Fisher <drew.fisher@oracle.com>
parents: 1213
diff changeset
   601
ead7c7d814c7 7052696 TI install fails with target discovery in snv_167 if there is floppy drive
Drew Fisher <drew.fisher@oracle.com>
parents: 1213
diff changeset
   602
                        if const.DI_FLOPPY in di_props:
ead7c7d814c7 7052696 TI install fails with target discovery in snv_167 if there is floppy drive
Drew Fisher <drew.fisher@oracle.com>
parents: 1213
diff changeset
   603
                            continue
ead7c7d814c7 7052696 TI install fails with target discovery in snv_167 if there is floppy drive
Drew Fisher <drew.fisher@oracle.com>
parents: 1213
diff changeset
   604
ead7c7d814c7 7052696 TI install fails with target discovery in snv_167 if there is floppy drive
Drew Fisher <drew.fisher@oracle.com>
parents: 1213
diff changeset
   605
                    # query libdiskmgt for the drive's information
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   606
                    new_disk = self.discover_disk(drive)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   607
1241
3d4bf09186b2 7060266 snv_167 PV domU install on OVM-222-RC1 fails, "No installation target disks found"
Drew Fisher <drew.fisher@oracle.com>
parents: 1236
diff changeset
   608
                    # skip invalid drives and CDROM drives
3d4bf09186b2 7060266 snv_167 PV domU install on OVM-222-RC1 fails, "No installation target disks found"
Drew Fisher <drew.fisher@oracle.com>
parents: 1236
diff changeset
   609
                    if new_disk is None or new_disk.iscdrom:
1218
ead7c7d814c7 7052696 TI install fails with target discovery in snv_167 if there is floppy drive
Drew Fisher <drew.fisher@oracle.com>
parents: 1213
diff changeset
   610
                        continue
ead7c7d814c7 7052696 TI install fails with target discovery in snv_167 if there is floppy drive
Drew Fisher <drew.fisher@oracle.com>
parents: 1213
diff changeset
   611
ead7c7d814c7 7052696 TI install fails with target discovery in snv_167 if there is floppy drive
Drew Fisher <drew.fisher@oracle.com>
parents: 1213
diff changeset
   612
                    if add_physical:
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   613
                        self.root.insert_children(new_disk)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   614
1241
3d4bf09186b2 7060266 snv_167 PV domU install on OVM-222-RC1 fails, "No installation target disks found"
Drew Fisher <drew.fisher@oracle.com>
parents: 1236
diff changeset
   615
        # extract all of the devpaths from all of the drives already inserted
1273
c4a56398929a 7052475 need to process dataset options from the AI manifest
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1241
diff changeset
   616
        devpath_list = [disk.devpath for disk in
1241
3d4bf09186b2 7060266 snv_167 PV domU install on OVM-222-RC1 fails, "No installation target disks found"
Drew Fisher <drew.fisher@oracle.com>
parents: 1236
diff changeset
   617
                        self.root.get_descendants(class_type=Disk)]
3d4bf09186b2 7060266 snv_167 PV domU install on OVM-222-RC1 fails, "No installation target disks found"
Drew Fisher <drew.fisher@oracle.com>
parents: 1236
diff changeset
   618
3d4bf09186b2 7060266 snv_167 PV domU install on OVM-222-RC1 fails, "No installation target disks found"
Drew Fisher <drew.fisher@oracle.com>
parents: 1236
diff changeset
   619
        # now walk all the drives in the system to make sure we pick up any
3d4bf09186b2 7060266 snv_167 PV domU install on OVM-222-RC1 fails, "No installation target disks found"
Drew Fisher <drew.fisher@oracle.com>
parents: 1236
diff changeset
   620
        # disks which have no controller (OVM Xen disks)
3d4bf09186b2 7060266 snv_167 PV domU install on OVM-222-RC1 fails, "No installation target disks found"
Drew Fisher <drew.fisher@oracle.com>
parents: 1236
diff changeset
   621
        for drive in diskmgt.descriptors_by_type(const.DRIVE):
3d4bf09186b2 7060266 snv_167 PV domU install on OVM-222-RC1 fails, "No installation target disks found"
Drew Fisher <drew.fisher@oracle.com>
parents: 1236
diff changeset
   622
            new_disk = self.discover_disk(drive)
3d4bf09186b2 7060266 snv_167 PV domU install on OVM-222-RC1 fails, "No installation target disks found"
Drew Fisher <drew.fisher@oracle.com>
parents: 1236
diff changeset
   623
3d4bf09186b2 7060266 snv_167 PV domU install on OVM-222-RC1 fails, "No installation target disks found"
Drew Fisher <drew.fisher@oracle.com>
parents: 1236
diff changeset
   624
            # skip invalid drives and CDROM drives
3d4bf09186b2 7060266 snv_167 PV domU install on OVM-222-RC1 fails, "No installation target disks found"
Drew Fisher <drew.fisher@oracle.com>
parents: 1236
diff changeset
   625
            if new_disk is None or new_disk.iscdrom:
3d4bf09186b2 7060266 snv_167 PV domU install on OVM-222-RC1 fails, "No installation target disks found"
Drew Fisher <drew.fisher@oracle.com>
parents: 1236
diff changeset
   626
                continue
3d4bf09186b2 7060266 snv_167 PV domU install on OVM-222-RC1 fails, "No installation target disks found"
Drew Fisher <drew.fisher@oracle.com>
parents: 1236
diff changeset
   627
3d4bf09186b2 7060266 snv_167 PV domU install on OVM-222-RC1 fails, "No installation target disks found"
Drew Fisher <drew.fisher@oracle.com>
parents: 1236
diff changeset
   628
            # skip any disk we've already discovered
3d4bf09186b2 7060266 snv_167 PV domU install on OVM-222-RC1 fails, "No installation target disks found"
Drew Fisher <drew.fisher@oracle.com>
parents: 1236
diff changeset
   629
            if new_disk.devpath in devpath_list:
3d4bf09186b2 7060266 snv_167 PV domU install on OVM-222-RC1 fails, "No installation target disks found"
Drew Fisher <drew.fisher@oracle.com>
parents: 1236
diff changeset
   630
                continue
3d4bf09186b2 7060266 snv_167 PV domU install on OVM-222-RC1 fails, "No installation target disks found"
Drew Fisher <drew.fisher@oracle.com>
parents: 1236
diff changeset
   631
3d4bf09186b2 7060266 snv_167 PV domU install on OVM-222-RC1 fails, "No installation target disks found"
Drew Fisher <drew.fisher@oracle.com>
parents: 1236
diff changeset
   632
            if add_physical:
3d4bf09186b2 7060266 snv_167 PV domU install on OVM-222-RC1 fails, "No installation target disks found"
Drew Fisher <drew.fisher@oracle.com>
parents: 1236
diff changeset
   633
                self.root.insert_children(new_disk)
3d4bf09186b2 7060266 snv_167 PV domU install on OVM-222-RC1 fails, "No installation target disks found"
Drew Fisher <drew.fisher@oracle.com>
parents: 1236
diff changeset
   634
1355
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   635
    def sparc_label_check(self):
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   636
        """ sparc_label_check - method to check for any unlabeled disks within
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   637
        the system.  The AI manifest is checked to ensure discovery.py does not
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   638
        try to apply a VTOC label to a disk specified with slices marked with
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   639
        the 'preserve' action.
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   640
        """
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   641
        # extract all of the disk objects from the AI manifest
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   642
        ai_disk_list = self.doc.volatile.get_descendants(class_type=Disk)
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   643
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   644
        # create a new list of disk CTD values where the user has specified a
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   645
        # 'preserve' action for a slice.
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   646
        preserve_disks = list()
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   647
        for ai_disk in ai_disk_list:
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   648
            slice_list = ai_disk.get_descendants(class_type=Slice)
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   649
            for slc in slice_list:
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   650
                if slc.action == "preserve":
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   651
                    preserve_disks.append(ai_disk.ctd)
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   652
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   653
        # Since libdiskmgt has no mechanism to update it's internal view of the
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   654
        # disk layout once its scanned /dev,  fork a process and allow
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   655
        # libdiskmgt to instantiate the drives first.  Then in the context of
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   656
        # the main process, when libdiskmgt gathers drive information, the
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   657
        # drive list will be up to date.
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   658
        pid = os.fork()
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   659
        if pid == 0:
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   660
            for drive in diskmgt.descriptors_by_type(const.DRIVE):
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   661
                if drive.media is None:
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   662
                    continue
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   663
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   664
                disk = Disk("disk")
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   665
                disk.ctd = drive.aliases[0].name
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   666
                dma = drive.media.attributes
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   667
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   668
                # If a disk is missing some basic attributes then it most
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   669
                # likely has no disk label.  Force a VTOC label onto the disk
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   670
                # so its geometry can be correctly determined.  This should
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   671
                # only happen for unlabeled SPARC disks, so we're safe to apply
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   672
                # a VTOC label without fear of trashing fdisk partitions
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   673
                # containing other OSes.
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   674
                if (not DMMediaAttr.NACCESSIBLE in dma or \
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   675
                   not DMMediaAttr.BLOCKSIZE in dma) and \
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   676
                   not dma.removable:
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   677
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   678
                    # only label the disk if it does not have any preserved
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   679
                    # slices.
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   680
                    if disk.ctd not in preserve_disks:
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   681
                        if not self.dry_run:
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   682
                            self.logger.info("%s is unlabeled.  Forcing a "
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   683
                                             "VTOC label" % disk.ctd)
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   684
                            disk.force_vtoc()
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   685
                        else:
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   686
                            self.logger.info("%s is unlabeled.  Not forcing "
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   687
                                             "a VTOC label due to dry_run "
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   688
                                             "flag" % disk.ctd)
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   689
                    else:
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   690
                        self.logger.info("%s is unlabeled but manifest "
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   691
                            "specifies 'preserved' slices.  Not forcing a "
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   692
                            "VTOC label onto the disk." % disk.ctd)
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   693
            os._exit(0)
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   694
        else:
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   695
            _none, status = os.wait()
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   696
            if status != 0:
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   697
                raise RuntimeError("Unable to fork a process to reset drive "
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   698
                                   "geometry")
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   699
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   700
    def setup_iscsi(self):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   701
        """ set up the iSCSI initiator appropriately (if specified)
1323
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   702
        such that any physical/logical iSCSI devices can be discovered.
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   703
        """
1323
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   704
        SVC = "svc:/network/iscsi/initiator:default"
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   705
1355
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   706
        # pull out all of the iscsi entries from the DOC
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   707
        iscsi_list = self.doc.get_descendants(class_type=Iscsi)
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   708
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   709
        # if there's nothing to do, simply return
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   710
        if not iscsi_list:
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   711
            return
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   712
1323
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   713
        # verify iscsiadm is available
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   714
        if not os.path.exists(ISCSIADM):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   715
            raise RuntimeError("iSCSI discovery enabled but %s does " \
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   716
                "not exist" % ISCSIADM)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   717
1323
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   718
        # ensure the iscsi/initiator service is online
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   719
        state_cmd = [SVCS, "-H", "-o", "STATE", SVC]
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   720
        p = run(state_cmd, check_result=Popen.ANY)
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   721
        if p.returncode != 0:
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   722
            # iscsi/initiator is not installed
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   723
            raise RuntimeError("%s not found - is it installed?" % SVC)
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   724
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   725
        # if the service is offline, enable it
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   726
        state = p.stdout.strip()
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   727
        if state == "offline":
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   728
            cmd = [SVCADM, "enable", "-s", SVC]
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   729
            run(cmd)
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   730
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   731
            # verify the service is now online
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   732
            p = run(state_cmd, check_result=Popen.ANY)
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   733
            state = p.stdout.strip()
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   734
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   735
            if state != "online":
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   736
                raise RuntimeError("Unable to start %s" % SVC)
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   737
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   738
        elif state != "online":
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   739
            # the service is in some other kind of state, so raise an error
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   740
            raise RuntimeError("%s requires manual servicing" % SVC)
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   741
1355
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   742
        for iscsi in iscsi_list:
1323
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   743
            # check iscsi.source for dhcp.  If set, query dhcpinfo for the
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   744
            # iSCSI boot parameters and set the rest of the Iscsi object
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   745
            # attributes
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   746
            if iscsi.source == "dhcp":
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   747
                p = run([DHCPINFO, "Rootpath"])
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   748
1323
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   749
                # RFC 4173 defines the format of iSCSI boot parameters in DHCP
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   750
                # Rootpath as follows:
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   751
                # Rootpath=iscsi:<IP>:<protocol>:<port>:<LUN>:<target>
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   752
                iscsi_str = p.stdout.partition('=')[2]
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   753
                params = iscsi_str.split(':')
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   754
                iscsi.target_ip = params[1]
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   755
                iscsi.target_port = params[3]
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   756
                iscsi.target_lun = params[4]
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   757
                iscsi.target_name = params[5]
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   758
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   759
            if iscsi.target_name is not None:
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   760
                # set up static discovery of targets
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   761
                discovery_str = iscsi.target_name + "," + iscsi.target_ip
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   762
                if iscsi.target_port is not None:
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   763
                    discovery_str += ":" + iscsi.target_port
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   764
                cmd = [ISCSIADM, "add", "static-config", discovery_str]
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   765
                run(cmd)
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   766
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   767
                cmd = [ISCSIADM, "modify", "discovery", "--static", "enable"]
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   768
                run(cmd)
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   769
1323
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   770
                iscsi_list_cmd = [ISCSIADM, "list", "target", "-S",
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   771
                                  discovery_str]
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   772
            else:
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   773
                # set up discovery of sendtargets targets
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   774
                discovery_str = iscsi.target_ip
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   775
                if iscsi.target_port is not None:
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   776
                    discovery_str += ":" + iscsi.target_port
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   777
                cmd = [ISCSIADM, "add", "discovery-address", discovery_str]
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   778
                run(cmd)
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   779
1323
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   780
                cmd = [ISCSIADM, "modify", "discovery", "--sendtargets",
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   781
                       "enable"]
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   782
                run(cmd)
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   783
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   784
                iscsi_list_cmd = [ISCSIADM, "list", "target", "-S"]
1151
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1146
diff changeset
   785
1323
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   786
            # run devfsadm and wait for the iscsi devices to configure
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   787
            run([DEVFSADM, "-i", "iscsi"])
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   788
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   789
            # list all the targets found
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   790
            iscsi_list = run(iscsi_list_cmd)
1151
95413393ef67 7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1146
diff changeset
   791
1323
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   792
            # the output will look like:
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   793
            #
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   794
            # Target: <iqn string>
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   795
            #        Alias: -
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   796
            #        TPGT: 1
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   797
            #        ISID: 4000002a0000
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   798
            #        Connections: 1
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   799
            #        LUN: 1
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   800
            #             Vendor:  SUN     
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   801
            #             Product: COMSTAR         
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   802
            #             OS Device Name: <ctd>
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   803
            #        LUN: 0
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   804
            #             Vendor:  SUN     
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   805
            #             Product: COMSTAR         
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   806
            #             OS Device Name: <ctd>
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   807
            #
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   808
            # The LUN number and ctd strings are the only values we're
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   809
            # interested in.
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   810
            iscsi_dict = dict()
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   811
1323
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   812
            # walk the output from iscsiadm list target to create a mapping
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   813
            # between ctd and LUN number.
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   814
            for line in iscsi_list.stdout.splitlines():
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   815
                line = line.lstrip()
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   816
                if line.startswith("LUN:"):
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   817
                    lun_num = line.split(": ")[1]
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   818
                if line.startswith("OS Device Name:") and lun_num is not None:
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   819
                    iscsi_ctd = line.rpartition("/")[2]
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   820
                    iscsi_dict[iscsi_ctd] = lun_num
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   821
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   822
                    # reset the lun_num for the next lun
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   823
                    lun_num = None
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   824
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   825
            # try to map iscsi_lun back to iscsi.target_lun
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   826
            for iscsi_ctd, iscsi_lun in iscsi_dict.items():
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   827
                if iscsi.target_lun is not None:
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   828
                    if iscsi.target_lun == iscsi_lun:
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   829
                        iscsi.parent.ctd = iscsi_ctd.partition("s2")[0]
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   830
                        break
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   831
                else:
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   832
                    iscsi.parent.ctd = iscsi_ctd.partition("s2")[0]
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   833
                    break
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   834
            else:
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   835
                raise RuntimeError("target_lun: %s not found on target"
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   836
                                   % iscsi.target_lun)
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   837
1197
41dc6c86a4c3 7020411 support in TD/TI for interfaces that provide CRO information in libdevinfo
Drew Fisher <drew.fisher@oracle.com>
parents: 1151
diff changeset
   838
    def setup_croinfo(self):
41dc6c86a4c3 7020411 support in TD/TI for interfaces that provide CRO information in libdevinfo
Drew Fisher <drew.fisher@oracle.com>
parents: 1151
diff changeset
   839
        """ set up a DataObjectDict representing the output from
41dc6c86a4c3 7020411 support in TD/TI for interfaces that provide CRO information in libdevinfo
Drew Fisher <drew.fisher@oracle.com>
parents: 1151
diff changeset
   840
        /usr/sbin/croinfo
41dc6c86a4c3 7020411 support in TD/TI for interfaces that provide CRO information in libdevinfo
Drew Fisher <drew.fisher@oracle.com>
parents: 1151
diff changeset
   841
        """
41dc6c86a4c3 7020411 support in TD/TI for interfaces that provide CRO information in libdevinfo
Drew Fisher <drew.fisher@oracle.com>
parents: 1151
diff changeset
   842
        cmd = [CROINFO, "-h", "-O", "cAR"]
1323
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   843
        p = run(cmd)
1197
41dc6c86a4c3 7020411 support in TD/TI for interfaces that provide CRO information in libdevinfo
Drew Fisher <drew.fisher@oracle.com>
parents: 1151
diff changeset
   844
1213
db03aed1d691 7057173 target discovery loops in finding disk with CUD_GUI and TI
Drew Fisher <drew.fisher@oracle.com>
parents: 1205
diff changeset
   845
        # for systems that do not support CRO, nothing will be returned in
db03aed1d691 7057173 target discovery loops in finding disk with CUD_GUI and TI
Drew Fisher <drew.fisher@oracle.com>
parents: 1205
diff changeset
   846
        # stdout so simply return.
db03aed1d691 7057173 target discovery loops in finding disk with CUD_GUI and TI
Drew Fisher <drew.fisher@oracle.com>
parents: 1205
diff changeset
   847
        if not p.stdout:
db03aed1d691 7057173 target discovery loops in finding disk with CUD_GUI and TI
Drew Fisher <drew.fisher@oracle.com>
parents: 1205
diff changeset
   848
            return
db03aed1d691 7057173 target discovery loops in finding disk with CUD_GUI and TI
Drew Fisher <drew.fisher@oracle.com>
parents: 1205
diff changeset
   849
1197
41dc6c86a4c3 7020411 support in TD/TI for interfaces that provide CRO information in libdevinfo
Drew Fisher <drew.fisher@oracle.com>
parents: 1151
diff changeset
   850
        # keep a positional counter since we can't use OrderedDicts until 2.7
41dc6c86a4c3 7020411 support in TD/TI for interfaces that provide CRO information in libdevinfo
Drew Fisher <drew.fisher@oracle.com>
parents: 1151
diff changeset
   851
        i = 1
41dc6c86a4c3 7020411 support in TD/TI for interfaces that provide CRO information in libdevinfo
Drew Fisher <drew.fisher@oracle.com>
parents: 1151
diff changeset
   852
        for line in p.stdout.splitlines():
41dc6c86a4c3 7020411 support in TD/TI for interfaces that provide CRO information in libdevinfo
Drew Fisher <drew.fisher@oracle.com>
parents: 1151
diff changeset
   853
            (ctd, alias, receptacle) = line.split(":")
41dc6c86a4c3 7020411 support in TD/TI for interfaces that provide CRO information in libdevinfo
Drew Fisher <drew.fisher@oracle.com>
parents: 1151
diff changeset
   854
            # skip any entries where the ctd is missing.
41dc6c86a4c3 7020411 support in TD/TI for interfaces that provide CRO information in libdevinfo
Drew Fisher <drew.fisher@oracle.com>
parents: 1151
diff changeset
   855
            if not ctd:
41dc6c86a4c3 7020411 support in TD/TI for interfaces that provide CRO information in libdevinfo
Drew Fisher <drew.fisher@oracle.com>
parents: 1151
diff changeset
   856
                continue
41dc6c86a4c3 7020411 support in TD/TI for interfaces that provide CRO information in libdevinfo
Drew Fisher <drew.fisher@oracle.com>
parents: 1151
diff changeset
   857
41dc6c86a4c3 7020411 support in TD/TI for interfaces that provide CRO information in libdevinfo
Drew Fisher <drew.fisher@oracle.com>
parents: 1151
diff changeset
   858
            self.cro_dict[ctd] = (i, alias or None, receptacle)
41dc6c86a4c3 7020411 support in TD/TI for interfaces that provide CRO information in libdevinfo
Drew Fisher <drew.fisher@oracle.com>
parents: 1151
diff changeset
   859
            i += 1
41dc6c86a4c3 7020411 support in TD/TI for interfaces that provide CRO information in libdevinfo
Drew Fisher <drew.fisher@oracle.com>
parents: 1151
diff changeset
   860
1275
a1022e164e5e 7066493 Target Selection failing on system with CRO output, but no CRO disks.
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1273
diff changeset
   861
        if self.cro_dict:
a1022e164e5e 7066493 Target Selection failing on system with CRO output, but no CRO disks.
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1273
diff changeset
   862
            # Only insert if there is something in it
a1022e164e5e 7066493 Target Selection failing on system with CRO output, but no CRO disks.
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1273
diff changeset
   863
            self.doc.persistent.insert_children(
1323
7e185ea5a224 7068381 AI doesn't retry to list the iscsi target if the OS Device Name is not available
Drew Fisher <drew.fisher@oracle.com>
parents: 1275
diff changeset
   864
                DataObjectDict(CRO_LABEL, self.cro_dict,
1275
a1022e164e5e 7066493 Target Selection failing on system with CRO output, but no CRO disks.
Darren Kenny <Darren.Kenny@Oracle.COM>
parents: 1273
diff changeset
   865
                               generate_xml=True))
1197
41dc6c86a4c3 7020411 support in TD/TI for interfaces that provide CRO information in libdevinfo
Drew Fisher <drew.fisher@oracle.com>
parents: 1151
diff changeset
   866
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   867
    def execute(self, dry_run=False):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   868
        """ primary execution checkpoint for Target Discovery
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   869
        """
1355
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   870
        self.dry_run = dry_run
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   871
1197
41dc6c86a4c3 7020411 support in TD/TI for interfaces that provide CRO information in libdevinfo
Drew Fisher <drew.fisher@oracle.com>
parents: 1151
diff changeset
   872
        # setup croinfo mappings
41dc6c86a4c3 7020411 support in TD/TI for interfaces that provide CRO information in libdevinfo
Drew Fisher <drew.fisher@oracle.com>
parents: 1151
diff changeset
   873
        self.setup_croinfo()
41dc6c86a4c3 7020411 support in TD/TI for interfaces that provide CRO information in libdevinfo
Drew Fisher <drew.fisher@oracle.com>
parents: 1151
diff changeset
   874
41dc6c86a4c3 7020411 support in TD/TI for interfaces that provide CRO information in libdevinfo
Drew Fisher <drew.fisher@oracle.com>
parents: 1151
diff changeset
   875
        # setup iSCSI so that all iSCSI physical and logical devices can be
41dc6c86a4c3 7020411 support in TD/TI for interfaces that provide CRO information in libdevinfo
Drew Fisher <drew.fisher@oracle.com>
parents: 1151
diff changeset
   876
        # discovered
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   877
        self.setup_iscsi()
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   878
1355
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   879
        # for sparc, check each disk to make sure there's a label
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   880
        if self.arch == "sparc":
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   881
            self.sparc_label_check()
7e6507b2a970 6260 sparc AI need a way to mechanism to explicitly ask for creating label on Sparc disk
Drew Fisher <drew.fisher@oracle.com>
parents: 1329
diff changeset
   882
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   883
        # check to see if the user specified a search_type
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   884
        if self.search_type == DISK_SEARCH_NAME:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   885
            try:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   886
                # check to see if the search name is either c#t#d# or c#d#
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   887
                if re.match(DISK_RE, self.search_name, re.I):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   888
                    dmd = diskmgt.descriptor_from_key(const.ALIAS,
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   889
                                                      self.search_name)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   890
                    alias = diskmgt.DMAlias(dmd.value)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   891
                    drive = alias.drive
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   892
                else:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   893
                    dmd = diskmgt.descriptor_from_key(const.DRIVE,
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   894
                                                      self.search_name)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   895
                    drive = diskmgt.DMDrive(dmd.value)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   896
            except OSError as err:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   897
                raise RuntimeError("Unable to look up %s - %s" % \
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   898
                    (self.search_name, err))
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   899
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   900
            # insert the drive information into the tree
1218
ead7c7d814c7 7052696 TI install fails with target discovery in snv_167 if there is floppy drive
Drew Fisher <drew.fisher@oracle.com>
parents: 1213
diff changeset
   901
            new_disk = self.discover_disk(drive)
ead7c7d814c7 7052696 TI install fails with target discovery in snv_167 if there is floppy drive
Drew Fisher <drew.fisher@oracle.com>
parents: 1213
diff changeset
   902
            if new_disk is not None:
ead7c7d814c7 7052696 TI install fails with target discovery in snv_167 if there is floppy drive
Drew Fisher <drew.fisher@oracle.com>
parents: 1213
diff changeset
   903
                self.root.insert_children(new_disk)
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   904
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   905
        elif self.search_type == ZPOOL_SEARCH_NAME:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   906
            self.discover_entire_system(add_physical=False)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   907
            self.root.insert_children(self.discover_zpools(
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   908
                self.search_name))
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
            # Add all Boot Environments that are contained in this zpool
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   911
            self.discover_BEs(self.search_name)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   912
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   913
        else:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   914
            self.discover_entire_system()
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   915
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   916
            # Add the discovered zpool objects
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   917
            self.root.insert_children(self.discover_zpools())
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   918
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   919
            # Add all Boot Environments
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   920
            self.discover_BEs()
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   921
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   922
        # Add the root node to the DOC
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   923
        self.doc.persistent.insert_children(self.root)