components/openstack/cinder/files/solaris/solarisfc.py
author Devjani Ray <devjani.ray@oracle.com>
Fri, 05 Feb 2016 17:54:17 -0500
changeset 5405 66fd59fecd68
parent 4793 24053a14d972
child 6070 87daa7413b2d
child 7787 26bcbec7afce
permissions -rw-r--r--
PSARC 2015/535 OpenStack service updates for Kilo PSARC 2015/458 aioeventlet - asyncio event loop scheduling callbacks in eventlet PSARC 2015/460 msgpack - C/Python bindings for MessagePack (de)serializer data PSARC 2015/466 openstackclient - OpenStack Command-line Client PSARC 2015/467 oslo.versionedobjects - Oslo Versioned Objects library PSARC 2015/468 pint - A physical quantities module PSARC 2015/469 pysaml2 - A pure Python implementation of SAML2 PSARC 2015/471 semantic_version - A library implementing the 'SemVer' scheme PSARC 2015/472 testresources - PyUnit extension for managing expensive test resources PSARC 2015/473 testscenarios - Extensions to Python unittest to support scenarios PSARC 2015/474 trollius - Port of the Tulip project (asyncio module, PEP 3156) on Python 2 PSARC 2015/475 urllib3 - HTTP library with thread-safe connection pooling, file post, and more PSARC 2015/520 oslo.concurrency - Oslo Concurrency library PSARC 2015/521 oslo.log - Oslo Logging Configuration library PSARC 2015/529 oslo.policy - Oslo Policy library PSARC 2015/530 psutil - Python system and process utilities PSARC 2015/538 fixtures - Python module to support reusable state for writing clean tests PSARC 2015/539 sqlparse - An SQL parser module for Python PSARC 2016/017 extras - Useful extra utilities for Python PSARC 2016/018 linecache2 - Port of the standard linecache module PSARC 2016/019 python-mimeparse - Basic functions for parsing mime-types PSARC 2016/020 testtools - Extensions to the Python unit testing framework PSARC 2016/021 traceback2 - Port of the standard traceback module PSARC 2016/014 OpenStack Cinder NFS driver for Solaris 22384068 OpenStack service updates for Kilo (Umbrella) 21974208 The Python module msgpack should be added to Userland 22010630 The Python trollius module should be added to Userland 22011755 The Python module pint should be added to Userland 22012256 The Python aioeventlet module should be added to Userland 22012282 The Python oslo.versionedobjects module should be added to Userland 22012317 The Python semantic_version module should be added to Userland 22012321 The Python testresources module should be added to Userland 22012329 The Python testscenarios module should be added to Userland 22012336 The Python urllib3 module should be added to Userland 22012343 The Python openstackclient module should be added to Userland 22299389 The Python oslo.concurrency module should be added to Userland 22299409 The Python oslo.log module should be added to Userland 22299418 The Python oslo.policy module should be added to Userland 22299469 The Python psutil module should be added to Userland 22337793 The Python sqlparse module should be added to Userland 22338325 The Python fixtures module should be added to Userland 22535728 The Python testtools module should be added to Userland 22535739 The Python extras module should be added to Userland 22535748 The Python linecache2 module should be added to Userland 22535753 The Python traceback2 module should be added to Userland 22535760 The Python python-mimeparse module should be added to Userland 18961001 Image filtering does not function as expected 21678935 NFS for Cinder in Solaris OpenStack 22548630 derived manifest should not enforce presence of global when installing from UAR 22629795 problem in SERVICE/KEYSTONE
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3998
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
     1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
     2
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
     3
# Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
     4
#
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
     5
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
     6
#    not use this file except in compliance with the License. You may obtain
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
     7
#    a copy of the License at
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
     8
#
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
     9
#         http://www.apache.org/licenses/LICENSE-2.0
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    10
#
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    11
#    Unless required by applicable law or agreed to in writing, software
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    12
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    13
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    14
#    License for the specific language governing permissions and limitations
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    15
#    under the License.
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    16
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    17
"""Generic Solaris Fibre Channel utilities."""
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    18
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    19
import os
4793
24053a14d972 21365620 cinder volume backups sometimes fail on SPARC
Strony <strony.zhang@oracle.com>
parents: 3998
diff changeset
    20
import platform
3998
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    21
import time
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    22
5405
66fd59fecd68 PSARC 2015/535 OpenStack service updates for Kilo
Devjani Ray <devjani.ray@oracle.com>
parents: 4793
diff changeset
    23
from oslo_concurrency import processutils as putils
66fd59fecd68 PSARC 2015/535 OpenStack service updates for Kilo
Devjani Ray <devjani.ray@oracle.com>
parents: 4793
diff changeset
    24
from oslo_log import log as logging
66fd59fecd68 PSARC 2015/535 OpenStack service updates for Kilo
Devjani Ray <devjani.ray@oracle.com>
parents: 4793
diff changeset
    25
3998
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    26
from cinder.brick import exception
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    27
from cinder.openstack.common.gettextutils import _
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    28
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    29
LOG = logging.getLogger(__name__)
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    30
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    31
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    32
class SolarisFibreChannel(object):
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    33
    def __init__(self, *args, **kwargs):
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    34
        self.execute = putils.execute
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    35
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    36
    def _get_fc_hbas(self):
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    37
        """Get Fibre Channel HBA information."""
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    38
        out = None
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    39
        try:
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    40
            out, err = self.execute('/usr/sbin/fcinfo', 'hba-port')
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    41
        except putils.ProcessExecutionError as err:
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    42
            return None
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    43
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    44
        if out is None:
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    45
            LOG.info(_("Cannot find any Fibre Channel HBAs"))
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    46
            return None
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    47
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    48
        hbas = []
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    49
        hba = {}
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    50
        for line in out.splitlines():
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    51
            line = line.strip()
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    52
            # Collect the following hba-port data:
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    53
            # 1: Port WWN
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    54
            # 2: State (online|offline)
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    55
            # 3: Node WWN
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    56
            if line.startswith("HBA Port WWN:"):
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    57
                # New HBA port entry
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    58
                hba = {}
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    59
                wwpn = line.split()[-1]
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    60
                hba['port_name'] = wwpn
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    61
                continue
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    62
            elif line.startswith("Port Mode:"):
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    63
                mode = line.split()[-1]
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    64
                # Skip Target mode ports
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    65
                if mode != 'Initiator':
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    66
                    break
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    67
            elif line.startswith("State:"):
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    68
                state = line.split()[-1]
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    69
                hba['port_state'] = state
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    70
                continue
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    71
            elif line.startswith("Node WWN:"):
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    72
                wwnn = line.split()[-1]
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    73
                hba['node_name'] = wwnn
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    74
                continue
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    75
            if len(hba) == 3:
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    76
                hbas.append(hba)
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    77
                hba = {}
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    78
        return hbas
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    79
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    80
    def get_fc_wwnns(self):
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    81
        """Get Fibre Channel WWNNs from the system, if any."""
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    82
        hbas = self._get_fc_hbas()
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    83
        if hbas is None:
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    84
            return None
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    85
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    86
        wwnns = []
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    87
        for hba in hbas:
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    88
            if hba['port_state'] == 'online':
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    89
                wwnn = hba['node_name']
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    90
                wwnns.append(wwnn)
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    91
        return wwnns
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    92
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    93
    def get_fc_wwpns(self):
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    94
        """Get Fibre Channel WWPNs from the system, if any."""
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    95
        hbas = self._get_fc_hbas()
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    96
        if hbas is None:
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    97
            return None
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    98
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
    99
        wwpns = []
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   100
        for hba in hbas:
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   101
            if hba['port_state'] == 'online':
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   102
                wwpn = hba['port_name']
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   103
                wwpns.append(wwpn)
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   104
        return wwpns
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   105
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   106
    def _refresh_connection(self):
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   107
        """Force the link reinitialization to make the LUN present."""
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   108
        wwpns = self.get_fc_wwpns()
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   109
        for wwpn in wwpns:
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   110
            self.execute('/usr/sbin/fcadm', 'force-lip', wwpn)
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   111
4793
24053a14d972 21365620 cinder volume backups sometimes fail on SPARC
Strony <strony.zhang@oracle.com>
parents: 3998
diff changeset
   112
    def _get_device_path(self, wwn):
3998
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   113
        """Get the Device Name of the WWN"""
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   114
        try:
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   115
            out, err = self.execute('/usr/sbin/fcinfo', 'logical-unit', '-v')
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   116
        except putils.ProcessExecutionError as err:
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   117
            return None
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   118
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   119
        host_dev = None
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   120
        remote_port = None
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   121
        if out is not None:
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   122
            for line in [l.strip() for l in out.splitlines()]:
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   123
                if line.startswith("OS Device Name:"):
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   124
                    host_dev = line.split()[-1]
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   125
                if line.startswith("Remote Port WWN:"):
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   126
                    remote_port = line.split()[-1]
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   127
                if remote_port == wwn:
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   128
                    return host_dev
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   129
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   130
        return None
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   131
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   132
    def connect_volume(self, connection_properties, scan_tries):
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   133
        """Attach the volume to instance_name.
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   134
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   135
        connection_properties for Fibre Channel must include:
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   136
        target_portal - ip and optional port
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   137
        target_iqn - iSCSI Qualified Name
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   138
        target_lun - LUN id of the volume
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   139
        """
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   140
        device_info = {'type': 'block'}
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   141
        target_wwn = connection_properties['target_wwn']
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   142
        # Check for multiple target_wwn values in a list
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   143
        if isinstance(target_wwn, list):
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   144
            wwn = target_wwn[0]
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   145
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   146
        # The scsi_vhci disk node is not always present immediately.
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   147
        # Sometimes we need to reinitialize the connection to trigger
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   148
        # a refresh.
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   149
        for i in range(1, scan_tries):
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   150
            LOG.debug("Looking for Fibre Channel device")
4793
24053a14d972 21365620 cinder volume backups sometimes fail on SPARC
Strony <strony.zhang@oracle.com>
parents: 3998
diff changeset
   151
            host_dev = self._get_device_path(wwn)
3998
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   152
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   153
            if host_dev is not None and os.path.exists(host_dev):
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   154
                break
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   155
            else:
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   156
                self._refresh_connection()
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   157
                time.sleep(i ** 2)
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   158
        else:
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   159
            msg = _("Fibre Channel volume device not found.")
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   160
            LOG.error(msg)
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   161
            raise exception.NoFibreChannelVolumeDeviceFound()
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   162
4793
24053a14d972 21365620 cinder volume backups sometimes fail on SPARC
Strony <strony.zhang@oracle.com>
parents: 3998
diff changeset
   163
        # Set the label EFI to the disk on SPARC before it is accessed and
24053a14d972 21365620 cinder volume backups sometimes fail on SPARC
Strony <strony.zhang@oracle.com>
parents: 3998
diff changeset
   164
        # make sure the correct device path with slice 0
24053a14d972 21365620 cinder volume backups sometimes fail on SPARC
Strony <strony.zhang@oracle.com>
parents: 3998
diff changeset
   165
        # (like '/dev/rdsk/c0t600xxxd0s0').
24053a14d972 21365620 cinder volume backups sometimes fail on SPARC
Strony <strony.zhang@oracle.com>
parents: 3998
diff changeset
   166
        if platform.processor() == 'sparc':
24053a14d972 21365620 cinder volume backups sometimes fail on SPARC
Strony <strony.zhang@oracle.com>
parents: 3998
diff changeset
   167
            tmp_dev_name = host_device.rsplit('s', 1)
24053a14d972 21365620 cinder volume backups sometimes fail on SPARC
Strony <strony.zhang@oracle.com>
parents: 3998
diff changeset
   168
            disk_name = tmp_dev_name[0].split('/')[-1]
24053a14d972 21365620 cinder volume backups sometimes fail on SPARC
Strony <strony.zhang@oracle.com>
parents: 3998
diff changeset
   169
            (out, _err) = self.execute('/usr/sbin/format', '-L', 'efi', '-d',
24053a14d972 21365620 cinder volume backups sometimes fail on SPARC
Strony <strony.zhang@oracle.com>
parents: 3998
diff changeset
   170
                                       disk_name)
24053a14d972 21365620 cinder volume backups sometimes fail on SPARC
Strony <strony.zhang@oracle.com>
parents: 3998
diff changeset
   171
            host_device = '%ss0' % tmp_dev_name[0]
24053a14d972 21365620 cinder volume backups sometimes fail on SPARC
Strony <strony.zhang@oracle.com>
parents: 3998
diff changeset
   172
3998
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   173
        device_info['path'] = host_dev
5bd484384122 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents:
diff changeset
   174
        return device_info