components/openstack/nova/files/solariszones/driver.py
author saurabh.vyas@oracle.com
Tue, 15 Dec 2015 00:08:40 -0800
branchs11u3-sru
changeset 5409 2c588e2f06d9
parent 4679 a5bb9ac1f999
child 5410 2fe121cb8570
permissions -rw-r--r--
20410887 Solaris Nova driver should be resilient when network info is None
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
     1
# Copyright 2011 Justin Santa Barbara
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
     2
# All Rights Reserved.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
     3
#
4072
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
     4
# Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
     5
#
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
     6
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
     7
#    not use this file except in compliance with the License. You may obtain
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
     8
#    a copy of the License at
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
     9
#
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    10
#         http://www.apache.org/licenses/LICENSE-2.0
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    11
#
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    12
#    Unless required by applicable law or agreed to in writing, software
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    13
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    14
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    15
#    License for the specific language governing permissions and limitations
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    16
#    under the License.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    17
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    18
"""
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    19
Driver for Solaris Zones (nee Containers):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    20
"""
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    21
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    22
import glob
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    23
import os
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    24
import platform
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    25
import shutil
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    26
import tempfile
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    27
import uuid
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    28
4679
a5bb9ac1f999 21434410 Nova zones driver should use specific version of kstat RAD module
david.comay@oracle.com
parents: 4645
diff changeset
    29
import rad.bindings.com.oracle.solaris.rad.kstat_1 as kstat
a5bb9ac1f999 21434410 Nova zones driver should use specific version of kstat RAD module
david.comay@oracle.com
parents: 4645
diff changeset
    30
import rad.bindings.com.oracle.solaris.rad.zonemgr_1 as zonemgr
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    31
import rad.client
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    32
import rad.connect
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    33
from solaris_install.archive.checkpoints import InstantiateUnifiedArchive
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    34
from solaris_install.archive import LOGFILE as ARCHIVE_LOGFILE
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    35
from solaris_install.archive import UnifiedArchive
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    36
from solaris_install.engine import InstallEngine
3178
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
    37
from solaris_install.target.size import Size
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    38
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    39
from eventlet import greenthread
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    40
from lxml import etree
4628
21e8147a2b1e 21038378 Nova VNC console not accessible in multi-node and multi-network configuration
Niall Power <niall.power@oracle.com>
parents: 4569
diff changeset
    41
from oslo_config import cfg
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    42
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    43
from nova.compute import power_state
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    44
from nova.compute import task_states
3178
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
    45
from nova.compute import vm_states
4072
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
    46
from nova.console import type as ctype
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    47
from nova import conductor
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    48
from nova import context as nova_context
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    49
from nova import exception
4072
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
    50
from nova.i18n import _
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    51
from nova.image import glance
3178
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
    52
from nova.network import neutronv2
4629
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
    53
from nova import objects
4072
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
    54
from nova.objects import flavor as flavor_obj
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    55
from nova.openstack.common import fileutils
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    56
from nova.openstack.common import jsonutils
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    57
from nova.openstack.common import log as logging
3178
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
    58
from nova.openstack.common import loopingcall
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
    59
from nova.openstack.common import processutils
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
    60
from nova.openstack.common import strutils
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    61
from nova import utils
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    62
from nova.virt import driver
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    63
from nova.virt import event as virtevent
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    64
from nova.virt import images
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    65
from nova.virt.solariszones import sysconfig
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    66
from nova import volume
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    67
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    68
solariszones_opts = [
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    69
    cfg.StrOpt('glancecache_dirname',
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    70
               default='$state_path/images',
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    71
               help='Default path to Glance cache for Solaris Zones.'),
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    72
    cfg.StrOpt('solariszones_snapshots_directory',
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    73
               default='$instances_path/snapshots',
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    74
               help='Location where solariszones driver will store snapshots '
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    75
                    'before uploading them to the Glance image service'),
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    76
]
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    77
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    78
CONF = cfg.CONF
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    79
CONF.register_opts(solariszones_opts)
4628
21e8147a2b1e 21038378 Nova VNC console not accessible in multi-node and multi-network configuration
Niall Power <niall.power@oracle.com>
parents: 4569
diff changeset
    80
CONF.import_opt('vncserver_proxyclient_address', 'nova.vnc')
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    81
LOG = logging.getLogger(__name__)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    82
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    83
# These should match the strings returned by the zone_state_str()
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    84
# function in the (private) libzonecfg library. These values are in turn
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    85
# returned in the 'state' string of the Solaris Zones' RAD interface by
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    86
# the zonemgr(3RAD) provider.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    87
ZONE_STATE_CONFIGURED = 'configured'
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    88
ZONE_STATE_INCOMPLETE = 'incomplete'
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    89
ZONE_STATE_UNAVAILABLE = 'unavailable'
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    90
ZONE_STATE_INSTALLED = 'installed'
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    91
ZONE_STATE_READY = 'ready'
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    92
ZONE_STATE_RUNNING = 'running'
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    93
ZONE_STATE_SHUTTING_DOWN = 'shutting_down'
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    94
ZONE_STATE_DOWN = 'down'
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    95
ZONE_STATE_MOUNTED = 'mounted'
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    96
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    97
# Mapping between zone state and Nova power_state.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    98
SOLARISZONES_POWER_STATE = {
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    99
    ZONE_STATE_CONFIGURED:      power_state.NOSTATE,
3200
16d08ab96b7f 18686478 kstat warning every minute in nova-compute log on SPARC
david.comay@oracle.com
parents: 3178
diff changeset
   100
    ZONE_STATE_INCOMPLETE:      power_state.NOSTATE,
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   101
    ZONE_STATE_UNAVAILABLE:     power_state.NOSTATE,
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   102
    ZONE_STATE_INSTALLED:       power_state.SHUTDOWN,
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   103
    ZONE_STATE_READY:           power_state.RUNNING,
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   104
    ZONE_STATE_RUNNING:         power_state.RUNNING,
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   105
    ZONE_STATE_SHUTTING_DOWN:   power_state.RUNNING,
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   106
    ZONE_STATE_DOWN:            power_state.RUNNING,
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   107
    ZONE_STATE_MOUNTED:         power_state.NOSTATE
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   108
}
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   109
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   110
# Solaris Zones brands as defined in brands(5).
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   111
ZONE_BRAND_LABELED = 'labeled'
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   112
ZONE_BRAND_SOLARIS = 'solaris'
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   113
ZONE_BRAND_SOLARIS_KZ = 'solaris-kz'
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   114
ZONE_BRAND_SOLARIS10 = 'solaris10'
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   115
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   116
# Mapping between supported zone brands and the name of the corresponding
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   117
# brand template.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   118
ZONE_BRAND_TEMPLATE = {
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   119
    ZONE_BRAND_SOLARIS:         'SYSdefault',
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   120
    ZONE_BRAND_SOLARIS_KZ:      'SYSsolaris-kz',
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   121
}
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   122
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   123
MAX_CONSOLE_BYTES = 102400
3809
eb8d6ce0657e PSARC/2014/377 noVNC - A browser based VNC client
Niall Power <niall.power@oracle.com>
parents: 3200
diff changeset
   124
VNC_CONSOLE_BASE_FMRI = 'svc:/application/openstack/nova/zone-vnc-console'
eb8d6ce0657e PSARC/2014/377 noVNC - A browser based VNC client
Niall Power <niall.power@oracle.com>
parents: 3200
diff changeset
   125
# Required in order to create a zone VNC console SMF service instance
eb8d6ce0657e PSARC/2014/377 noVNC - A browser based VNC client
Niall Power <niall.power@oracle.com>
parents: 3200
diff changeset
   126
VNC_SERVER_PATH = '/usr/bin/vncserver'
eb8d6ce0657e PSARC/2014/377 noVNC - A browser based VNC client
Niall Power <niall.power@oracle.com>
parents: 3200
diff changeset
   127
XTERM_PATH = '/usr/bin/xterm'
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   128
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   129
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   130
def lookup_resource_property(zone, resource, prop, filter=None):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   131
    """Lookup specified property from specified Solaris Zone resource."""
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   132
    try:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   133
        val = zone.getResourceProperties(zonemgr.Resource(resource, filter),
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   134
                                         [prop])
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   135
    except rad.client.ObjectError:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   136
        return None
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   137
    except Exception:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   138
        raise
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   139
    return val[0].value if val else None
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   140
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   141
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   142
def lookup_resource_property_value(zone, resource, prop, value):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   143
    """Lookup specified property with value from specified Solaris Zone
3178
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   144
    resource. Returns property if matching value is found, else None
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   145
    """
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   146
    try:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   147
        resources = zone.getResources(zonemgr.Resource(resource))
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   148
        for resource in resources:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   149
            for propertee in resource.properties:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   150
                if propertee.name == prop and propertee.value == value:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   151
                    return propertee
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   152
        else:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   153
            return None
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   154
    except rad.client.ObjectError:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   155
        return None
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   156
    except Exception:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   157
        raise
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   158
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   159
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   160
class ZoneConfig(object):
3178
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   161
    """ZoneConfig - context manager for access zone configurations.
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   162
    Automatically opens the configuration for a zone and commits any changes
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   163
    before exiting
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   164
    """
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   165
    def __init__(self, zone):
3178
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   166
        """zone is a zonemgr object representing either a kernel zone or
5409
2c588e2f06d9 20410887 Solaris Nova driver should be resilient when network info is None
saurabh.vyas@oracle.com
parents: 4679
diff changeset
   167
        non-global zone.
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   168
        """
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   169
        self.zone = zone
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   170
        self.editing = False
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   171
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   172
    def __enter__(self):
3178
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   173
        """enables the editing of the zone."""
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   174
        try:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   175
            self.zone.editConfig()
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   176
            self.editing = True
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   177
            return self
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   178
        except rad.client.ObjectError as err:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   179
            LOG.error(_("Unable to initialize editing of instance '%s' via "
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   180
                        "zonemgr(3RAD): %s") % (self.zone.name, err))
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   181
            raise
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   182
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   183
    def __exit__(self, exc_type, exc_val, exc_tb):
3178
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   184
        """looks for any kind of exception before exiting.  If one is found,
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   185
        cancel any configuration changes and reraise the exception.  If not,
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   186
        commit the new configuration.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   187
        """
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   188
        if exc_type is not None and self.editing:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   189
            # We received some kind of exception.  Cancel the config and raise.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   190
            self.zone.cancelConfig()
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   191
            raise
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   192
        else:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   193
            # commit the config
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   194
            try:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   195
                self.zone.commitConfig()
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   196
            except rad.client.ObjectError as err:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   197
                LOG.error(_("Unable to commit the new configuration for "
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   198
                            "instance '%s' via zonemgr(3RAD): %s")
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   199
                          % (self.zone.name, err))
4645
7e2c683157d6 21307395 nova ZoneConfig class should call cancelConfig when editConfig fails in __exit__
Brian Reitz <Brian.Reitz@Oracle.COM>
parents: 4629
diff changeset
   200
7e2c683157d6 21307395 nova ZoneConfig class should call cancelConfig when editConfig fails in __exit__
Brian Reitz <Brian.Reitz@Oracle.COM>
parents: 4629
diff changeset
   201
                # Last ditch effort to cleanup.
7e2c683157d6 21307395 nova ZoneConfig class should call cancelConfig when editConfig fails in __exit__
Brian Reitz <Brian.Reitz@Oracle.COM>
parents: 4629
diff changeset
   202
                self.zone.cancelConfig()
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   203
                raise
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   204
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   205
    def setprop(self, resource, prop, value):
3178
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   206
        """sets a property for an existing resource OR creates a new resource
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   207
        with the given property(s).
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   208
        """
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   209
        current = lookup_resource_property(self.zone, resource, prop)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   210
        if current is not None and current == value:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   211
            # the value is already set
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   212
            return
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   213
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   214
        try:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   215
            if current is None:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   216
                self.zone.addResource(zonemgr.Resource(
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   217
                    resource, [zonemgr.Property(prop, value)]))
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   218
            else:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   219
                self.zone.setResourceProperties(
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   220
                    zonemgr.Resource(resource),
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   221
                    [zonemgr.Property(prop, value)])
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   222
        except rad.client.ObjectError as err:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   223
            LOG.error(_("Unable to set '%s' property on '%s' resource for "
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   224
                        "instance '%s' via zonemgr(3RAD): %s")
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   225
                      % (prop, resource, self.zone.name, err))
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   226
            raise
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   227
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   228
    def addresource(self, resource, props=None):
3178
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   229
        """creates a new resource with an optional property list."""
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   230
        if props is None:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   231
            props = []
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   232
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   233
        try:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   234
            self.zone.addResource(zonemgr.Resource(resource, props))
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   235
        except rad.client.ObjectError as err:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   236
            LOG.error(_("Unable to create new resource '%s' for instance '%s'"
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   237
                        "via zonemgr(3RAD): %s")
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   238
                      % (resource, self.zone.name, err))
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   239
            raise
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   240
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   241
    def removeresources(self, resource, props=None):
3178
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   242
        """removes resources whose properties include the optional property
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   243
        list specified in props.
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   244
        """
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   245
        if props is None:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   246
            props = []
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   247
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   248
        try:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   249
            self.zone.removeResources(zonemgr.Resource(resource, props))
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   250
        except rad.client.ObjectError as err:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   251
            LOG.error(_("Unable to remove resource '%s' for instance '%s' via "
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   252
                        "zonemgr(3RAD): %s") % (resource, self.zone.name, err))
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   253
            raise
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   254
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   255
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   256
class SolarisZonesDriver(driver.ComputeDriver):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   257
    """Solaris Zones Driver using the zonemgr(3RAD) and kstat(3RAD) providers.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   258
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   259
    The interface to this class talks in terms of 'instances' (Amazon EC2 and
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   260
    internal Nova terminology), by which we mean 'running virtual machine'
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   261
    (XenAPI terminology) or domain (Xen or libvirt terminology).
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   262
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   263
    An instance has an ID, which is the identifier chosen by Nova to represent
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   264
    the instance further up the stack.  This is unfortunately also called a
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   265
    'name' elsewhere.  As far as this layer is concerned, 'instance ID' and
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   266
    'instance name' are synonyms.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   267
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   268
    Note that the instance ID or name is not human-readable or
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   269
    customer-controlled -- it's an internal ID chosen by Nova.  At the
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   270
    nova.virt layer, instances do not have human-readable names at all -- such
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   271
    things are only known higher up the stack.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   272
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   273
    Most virtualization platforms will also have their own identity schemes,
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   274
    to uniquely identify a VM or domain.  These IDs must stay internal to the
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   275
    platform-specific layer, and never escape the connection interface.  The
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   276
    platform-specific layer is responsible for keeping track of which instance
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   277
    ID maps to which platform-specific ID, and vice versa.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   278
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   279
    Some methods here take an instance of nova.compute.service.Instance.  This
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   280
    is the data structure used by nova.compute to store details regarding an
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   281
    instance, and pass them into this layer.  This layer is responsible for
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   282
    translating that generic data structure into terms that are specific to the
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   283
    virtualization platform.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   284
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   285
    """
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   286
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   287
    capabilities = {
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   288
        "has_imagecache": False,
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   289
        "supports_recreate": False,
4072
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   290
        }
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   291
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   292
    def __init__(self, virtapi):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   293
        self.virtapi = virtapi
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   294
        self._compute_event_callback = None
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   295
        self._conductor_api = conductor.API()
3178
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   296
        self._fc_hbas = None
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   297
        self._fc_wwnns = None
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   298
        self._fc_wwpns = None
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   299
        self._host_stats = {}
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   300
        self._initiator = None
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   301
        self._install_engine = None
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   302
        self._pagesize = os.sysconf('SC_PAGESIZE')
4072
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   303
        self._rad_connection = None
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   304
        self._uname = os.uname()
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   305
        self._validated_archives = list()
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   306
        self._volume_api = volume.API()
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   307
4072
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   308
    @property
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   309
    def rad_connection(self):
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   310
        if self._rad_connection is None:
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   311
            self._rad_connection = rad.connect.connect_unix()
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   312
        else:
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   313
            # taken from rad.connect.RadConnection.__repr__ to look for a
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   314
            # closed connection
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   315
            if self._rad_connection._closed is not None:
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   316
                # the RAD connection has been lost.  Reconnect to RAD
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   317
                self._rad_connection = rad.connect.connect_unix()
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   318
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   319
        return self._rad_connection
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   320
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   321
    def _init_rad(self):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   322
        """Connect to RAD providers for kernel statistics and Solaris
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   323
        Zones. By connecting to the local rad(1M) service through a
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   324
        UNIX domain socket, kernel statistics can be read via
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   325
        kstat(3RAD) and Solaris Zones can be configured and controlled
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   326
        via zonemgr(3RAD).
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   327
        """
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   328
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   329
        try:
4072
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   330
            self._kstat_control = self.rad_connection.get_object(
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   331
                kstat.Control())
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   332
        except Exception as reason:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   333
            msg = (_('Unable to connect to svc:/system/rad:local: %s')
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   334
                   % reason)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   335
            raise exception.NovaException(msg)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   336
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   337
    def init_host(self, host):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   338
        """Initialize anything that is necessary for the driver to function,
3178
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   339
        including catching up with currently running VM's on the given host.
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   340
        """
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   341
        # TODO(Vek): Need to pass context in for access to auth_token
3178
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   342
        self._init_rad()
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   343
4072
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   344
    def cleanup_host(self, host):
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   345
        """Clean up anything that is necessary for the driver gracefully stop,
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   346
        including ending remote sessions. This is optional.
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   347
        """
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   348
        pass
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   349
3178
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   350
    def _get_fc_hbas(self):
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   351
        """Get Fibre Channel HBA information."""
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   352
        if self._fc_hbas:
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   353
            return self._fc_hbas
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   354
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   355
        out = None
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   356
        try:
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   357
            out, err = utils.execute('/usr/sbin/fcinfo', 'hba-port')
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   358
        except processutils.ProcessExecutionError as err:
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   359
            return []
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   360
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   361
        if out is None:
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   362
            raise RuntimeError(_("Cannot find any Fibre Channel HBAs"))
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   363
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   364
        hbas = []
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   365
        hba = {}
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   366
        for line in out.splitlines():
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   367
            line = line.strip()
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   368
            # Collect the following hba-port data:
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   369
            # 1: Port WWN
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   370
            # 2: State (online|offline)
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   371
            # 3: Node WWN
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   372
            if line.startswith("HBA Port WWN:"):
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   373
                # New HBA port entry
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   374
                hba = {}
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   375
                wwpn = line.split()[-1]
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   376
                hba['port_name'] = wwpn
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   377
                continue
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   378
            elif line.startswith("Port Mode:"):
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   379
                mode = line.split()[-1]
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   380
                # Skip Target mode ports
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   381
                if mode != 'Initiator':
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   382
                    break
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   383
            elif line.startswith("State:"):
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   384
                state = line.split()[-1]
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   385
                hba['port_state'] = state
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   386
                continue
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   387
            elif line.startswith("Node WWN:"):
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   388
                wwnn = line.split()[-1]
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   389
                hba['node_name'] = wwnn
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   390
                continue
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   391
            if len(hba) == 3:
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   392
                hbas.append(hba)
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   393
                hba = {}
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   394
        self._fc_hbas = hbas
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   395
        return self._fc_hbas
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   396
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   397
    def _get_fc_wwnns(self):
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   398
        """Get Fibre Channel WWNNs from the system, if any."""
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   399
        hbas = self._get_fc_hbas()
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   400
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   401
        wwnns = []
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   402
        for hba in hbas:
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   403
            if hba['port_state'] == 'online':
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   404
                wwnn = hba['node_name']
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   405
                wwnns.append(wwnn)
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   406
        return wwnns
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   407
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   408
    def _get_fc_wwpns(self):
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   409
        """Get Fibre Channel WWPNs from the system, if any."""
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   410
        hbas = self._get_fc_hbas()
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   411
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   412
        wwpns = []
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   413
        for hba in hbas:
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   414
            if hba['port_state'] == 'online':
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   415
                wwpn = hba['port_name']
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   416
                wwpns.append(wwpn)
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   417
        return wwpns
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   418
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   419
    def _get_iscsi_initiator(self):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   420
        """ Return the iSCSI initiator node name IQN for this host """
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   421
        out, err = utils.execute('/usr/sbin/iscsiadm', 'list',
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   422
                                 'initiator-node')
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   423
        # Sample first line of command output:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   424
        # Initiator node name: iqn.1986-03.com.sun:01:e00000000000.4f757217
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   425
        initiator_name_line = out.splitlines()[0]
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   426
        initiator_iqn = initiator_name_line.rsplit(' ', 1)[1]
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   427
        return initiator_iqn
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   428
3178
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   429
    def _get_zone_auto_install_state(self, zone_name):
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   430
        """Returns the SMF state of the auto-installer service,
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   431
           or None if auto-installer service is non-existent
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   432
        """
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   433
        try:
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   434
            out, err = utils.execute('/usr/sbin/zlogin', '-S', zone_name,
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   435
                                     '/usr/bin/svcs', '-H', '-o', 'state',
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   436
                                     'auto-installer:default')
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   437
            return out.strip()
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   438
        except processutils.ProcessExecutionError as err:
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   439
            # No auto-installer instance most likely.
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   440
            return None
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   441
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   442
    def _get_zone_by_name(self, name):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   443
        """Return a Solaris Zones object via RAD by name."""
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   444
        try:
4072
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   445
            zone = self.rad_connection.get_object(
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   446
                zonemgr.Zone(), rad.client.ADRGlobPattern({'name': name}))
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   447
        except rad.client.NotFoundError:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   448
            return None
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   449
        except Exception:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   450
            raise
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   451
        return zone
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   452
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   453
    def _get_state(self, zone):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   454
        """Return the running state, one of the power_state codes."""
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   455
        return SOLARISZONES_POWER_STATE[zone.state]
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   456
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   457
    def _pages_to_kb(self, pages):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   458
        """Convert a number of pages of memory into a total size in KBytes."""
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   459
        return (pages * self._pagesize) / 1024
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   460
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   461
    def _get_max_mem(self, zone):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   462
        """Return the maximum memory in KBytes allowed."""
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   463
        max_mem = lookup_resource_property(zone, 'capped-memory', 'physical')
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   464
        if max_mem is not None:
4072
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   465
            return strutils.string_to_bytes("%sB" % max_mem) / 1024
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   466
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   467
        # If physical property in capped-memory doesn't exist, this may
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   468
        # represent a non-global zone so just return the system's total
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   469
        # memory.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   470
        return self._pages_to_kb(os.sysconf('SC_PHYS_PAGES'))
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   471
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   472
    def _get_mem(self, zone):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   473
        """Return the memory in KBytes used by the domain."""
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   474
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   475
        # There isn't any way of determining this from the hypervisor
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   476
        # perspective in Solaris, so just return the _get_max_mem() value
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   477
        # for now.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   478
        return self._get_max_mem(zone)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   479
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   480
    def _get_num_cpu(self, zone):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   481
        """Return the number of virtual CPUs for the domain.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   482
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   483
        In the case of kernel zones, the number of virtual CPUs a zone
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   484
        ends up with depends on whether or not there were 'virtual-cpu'
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   485
        or 'dedicated-cpu' resources in the configuration or whether
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   486
        there was an assigned pool in the configuration. This algorithm
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   487
        attempts to emulate what the virtual platform code does to
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   488
        determine a number of virtual CPUs to use.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   489
        """
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   490
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   491
        # If a 'virtual-cpu' resource exists, use the minimum number of
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   492
        # CPUs defined there.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   493
        ncpus = lookup_resource_property(zone, 'virtual-cpu', 'ncpus')
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   494
        if ncpus is not None:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   495
            min = ncpus.split('-', 1)[0]
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   496
            if min.isdigit():
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   497
                return int(min)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   498
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   499
        # Otherwise if a 'dedicated-cpu' resource exists, use the maximum
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   500
        # number of CPUs defined there.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   501
        ncpus = lookup_resource_property(zone, 'dedicated-cpu', 'ncpus')
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   502
        if ncpus is not None:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   503
            max = ncpus.split('-', 1)[-1]
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   504
            if max.isdigit():
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   505
                return int(max)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   506
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   507
        # Finally if neither resource exists but the zone was assigned a
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   508
        # pool in the configuration, the number of CPUs would be the size
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   509
        # of the processor set. Currently there's no way of easily
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   510
        # determining this so use the system's notion of the total number
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   511
        # of online CPUs.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   512
        return os.sysconf('SC_NPROCESSORS_ONLN')
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   513
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   514
    def _get_kstat_by_name(self, kstat_class, module, instance, name):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   515
        """Return Kstat snapshot data via RAD as a dictionary."""
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   516
        pattern = {
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   517
            'class':    kstat_class,
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   518
            'module':   module,
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   519
            'instance': instance,
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   520
            'name':     name
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   521
        }
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   522
        try:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   523
            self._kstat_control.update()
4072
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   524
            kstat_object = self.rad_connection.get_object(
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   525
                kstat.Kstat(), rad.client.ADRGlobPattern(pattern))
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   526
        except Exception as reason:
3200
16d08ab96b7f 18686478 kstat warning every minute in nova-compute log on SPARC
david.comay@oracle.com
parents: 3178
diff changeset
   527
            LOG.info(_("Unable to retrieve kstat object '%s:%s:%s' of class "
16d08ab96b7f 18686478 kstat warning every minute in nova-compute log on SPARC
david.comay@oracle.com
parents: 3178
diff changeset
   528
                       "'%s' via kstat(3RAD): %s")
16d08ab96b7f 18686478 kstat warning every minute in nova-compute log on SPARC
david.comay@oracle.com
parents: 3178
diff changeset
   529
                     % (module, instance, name, kstat_class, reason))
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   530
            return None
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   531
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   532
        kstat_data = {}
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   533
        for named in kstat_object.fresh_snapshot().data.NAMED:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   534
            kstat_data[named.name] = getattr(named.value,
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   535
                                             str(named.value.discriminant))
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   536
        return kstat_data
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   537
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   538
    def _get_cpu_time(self, zone):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   539
        """Return the CPU time used in nanoseconds."""
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   540
        if zone.id == -1:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   541
            return 0
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   542
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   543
        kstat_data = self._get_kstat_by_name('zones', 'cpu', str(zone.id),
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   544
                                             'sys_zone_aggr')
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   545
        if kstat_data is None:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   546
            return 0
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   547
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   548
        return kstat_data['cpu_nsec_kernel'] + kstat_data['cpu_nsec_user']
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   549
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   550
    def get_info(self, instance):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   551
        """Get the current status of an instance, by name (not ID!)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   552
4072
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   553
        :param instance: nova.objects.instance.Instance object
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   554
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   555
        Returns a dict containing:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   556
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   557
        :state:           the running state, one of the power_state codes
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   558
        :max_mem:         (int) the maximum memory in KBytes allowed
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   559
        :mem:             (int) the memory in KBytes used by the domain
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   560
        :num_cpu:         (int) the number of virtual CPUs for the domain
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   561
        :cpu_time:        (int) the CPU time used in nanoseconds
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   562
        """
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   563
        # TODO(Vek): Need to pass context in for access to auth_token
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   564
        name = instance['name']
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   565
        zone = self._get_zone_by_name(name)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   566
        if zone is None:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   567
            LOG.error(_("Unable to find instance '%s' via zonemgr(3RAD)")
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   568
                      % name)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   569
            raise exception.InstanceNotFound(instance_id=name)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   570
        return {
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   571
            'state':    self._get_state(zone),
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   572
            'max_mem':  self._get_max_mem(zone),
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   573
            'mem':      self._get_mem(zone),
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   574
            'num_cpu':  self._get_num_cpu(zone),
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   575
            'cpu_time': self._get_cpu_time(zone)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   576
        }
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   577
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   578
    def get_num_instances(self):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   579
        """Return the total number of virtual machines.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   580
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   581
        Return the number of virtual machines that the hypervisor knows
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   582
        about.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   583
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   584
        .. note::
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   585
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   586
            This implementation works for all drivers, but it is
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   587
            not particularly efficient. Maintainers of the virt drivers are
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   588
            encouraged to override this method with something more
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   589
            efficient.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   590
        """
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   591
        return len(self.list_instances())
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   592
4072
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   593
    def instance_exists(self, instance):
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   594
        """Checks existence of an instance on the host.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   595
4072
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   596
        :param instance: The instance to lookup
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   597
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   598
        Returns True if an instance with the supplied ID exists on
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   599
        the host, False otherwise.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   600
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   601
        .. note::
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   602
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   603
            This implementation works for all drivers, but it is
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   604
            not particularly efficient. Maintainers of the virt drivers are
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   605
            encouraged to override this method with something more
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   606
            efficient.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   607
        """
4072
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   608
        try:
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   609
            return instance.uuid in self.list_instance_uuids()
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   610
        except NotImplementedError:
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   611
            return instance.name in self.list_instances()
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   612
3178
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   613
    def estimate_instance_overhead(self, instance_info):
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   614
        """Estimate the virtualization overhead required to build an instance
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   615
        of the given flavor.
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   616
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   617
        Defaults to zero, drivers should override if per-instance overhead
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   618
        calculations are desired.
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   619
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   620
        :param instance_info: Instance/flavor to calculate overhead for.
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   621
        :returns: Dict of estimated overhead values.
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   622
        """
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   623
        return {'memory_mb': 0}
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   624
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   625
    def _get_list_zone_object(self):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   626
        """Return a list of all Solaris Zones objects via RAD."""
4072
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   627
        return self.rad_connection.list_objects(zonemgr.Zone())
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   628
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   629
    def list_instances(self):
4072
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   630
        """Return the names of all the instances known to the virtualization
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   631
        layer, as a list.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   632
        """
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   633
        # TODO(Vek): Need to pass context in for access to auth_token
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   634
        instances_list = []
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   635
        for zone in self._get_list_zone_object():
4072
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   636
            instances_list.append(self.rad_connection.get_object(zone).name)
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   637
        return instances_list
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   638
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   639
    def list_instance_uuids(self):
4072
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   640
        """Return the UUIDS of all the instances known to the virtualization
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   641
        layer, as a list.
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   642
        """
4072
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   643
        raise NotImplementedError()
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   644
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   645
    def rebuild(self, context, instance, image_meta, injected_files,
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   646
                admin_password, bdms, detach_block_devices,
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   647
                attach_block_devices, network_info=None,
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   648
                recreate=False, block_device_info=None,
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   649
                preserve_ephemeral=False):
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   650
        """Destroy and re-make this instance.
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   651
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   652
        A 'rebuild' effectively purges all existing data from the system and
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   653
        remakes the VM with given 'metadata' and 'personalities'.
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   654
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   655
        This base class method shuts down the VM, detaches all block devices,
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   656
        then spins up the new VM afterwards. It may be overridden by
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   657
        hypervisors that need to - e.g. for optimisations, or when the 'VM'
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   658
        is actually proxied and needs to be held across the shutdown + spin
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   659
        up steps.
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   660
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   661
        :param context: security context
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   662
        :param instance: nova.objects.instance.Instance
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   663
                         This function should use the data there to guide
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   664
                         the creation of the new instance.
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   665
        :param image_meta: image object returned by nova.image.glance that
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   666
                           defines the image from which to boot this instance
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   667
        :param injected_files: User files to inject into instance.
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   668
        :param admin_password: Administrator password to set in instance.
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   669
        :param bdms: block-device-mappings to use for rebuild
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   670
        :param detach_block_devices: function to detach block devices. See
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   671
            nova.compute.manager.ComputeManager:_rebuild_default_impl for
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   672
            usage.
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   673
        :param attach_block_devices: function to attach block devices. See
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   674
            nova.compute.manager.ComputeManager:_rebuild_default_impl for
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   675
            usage.
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   676
        :param network_info:
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   677
           :py:meth:`~nova.network.manager.NetworkManager.get_instance_nw_info`
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   678
        :param recreate: True if the instance is being recreated on a new
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   679
            hypervisor - all the cleanup of old state is skipped.
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   680
        :param block_device_info: Information about block devices to be
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   681
                                  attached to the instance.
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   682
        :param preserve_ephemeral: True if the default ephemeral storage
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   683
                                   partition must be preserved on rebuild
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   684
        """
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   685
        raise NotImplementedError()
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   686
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   687
    def _fetch_image(self, context, instance):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   688
        """Fetch an image using Glance given the instance's image_ref."""
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   689
        glancecache_dirname = CONF.glancecache_dirname
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   690
        fileutils.ensure_tree(glancecache_dirname)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   691
        image = ''.join([glancecache_dirname, '/', instance['image_ref']])
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   692
        if os.path.exists(image):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   693
            LOG.debug(_("Using existing, cached Glance image: id %s")
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   694
                      % instance['image_ref'])
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   695
            return image
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   696
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   697
        LOG.debug(_("Fetching new Glance image: id %s")
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   698
                  % instance['image_ref'])
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   699
        try:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   700
            images.fetch(context, instance['image_ref'], image,
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   701
                         instance['user_id'], instance['project_id'])
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   702
        except Exception as reason:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   703
            LOG.error(_("Unable to fetch Glance image: id %s: %s")
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   704
                      % (instance['image_ref'], reason))
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   705
            raise
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   706
        return image
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   707
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   708
    def _validate_image(self, image, instance):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   709
        """Validate a glance image for compatibility with the instance"""
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   710
        # Skip if the image was already checked and confirmed as valid
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   711
        if instance['image_ref'] in self._validated_archives:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   712
            return
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   713
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   714
        if self._install_engine is None:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   715
            self._install_engine = InstallEngine(ARCHIVE_LOGFILE)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   716
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   717
        try:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   718
            init_ua_cp = InstantiateUnifiedArchive(instance['image_ref'],
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   719
                                                   image)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   720
            init_ua_cp.execute()
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   721
        except Exception:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   722
            reason = (_("Image query failed. Possibly invalid or corrupt. "
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   723
                        "Log file location: %s:%s")
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   724
                      % (self._uname[1], ARCHIVE_LOGFILE))
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   725
            LOG.error(reason)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   726
            raise exception.ImageUnacceptable(image_id=instance['image_ref'],
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   727
                                              reason=reason)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   728
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   729
        try:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   730
            ua = self._install_engine.doc.volatile.get_first_child(
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   731
                class_type=UnifiedArchive)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   732
            # Validate the image at this point to ensure:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   733
            # - contains one deployable system
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   734
            deployables = ua.archive_objects
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   735
            if len(deployables) != 1:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   736
                reason = (_('Image must contain only 1 deployable system'))
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   737
                raise exception.ImageUnacceptable(
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   738
                    image_id=instance['image_ref'],
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   739
                    reason=reason)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   740
            # - matching architecture
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   741
            deployable_arch = deployables[0].system.arch
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   742
            compute_arch = platform.processor()
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   743
            if deployable_arch != compute_arch:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   744
                reason = (_('Image architecture "%s" is incompatible with this'
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   745
                          'compute host architecture: "%s"')
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   746
                          % (deployable_arch, compute_arch))
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   747
                raise exception.ImageUnacceptable(
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   748
                    image_id=instance['image_ref'],
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   749
                    reason=reason)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   750
            # - single root pool only
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   751
            streams = deployables[0].zfs_streams
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   752
            stream_pools = set(stream.zpool for stream in streams)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   753
            if len(stream_pools) > 1:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   754
                reason = (_('Image contains more than one zpool: "%s"')
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   755
                          % (stream_pools))
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   756
                raise exception.ImageUnacceptable(
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   757
                    image_id=instance['image_ref'],
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   758
                    reason=reason)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   759
            # - looks like it's OK
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   760
            self._validated_archives.append(instance['image_ref'])
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   761
        finally:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   762
            # Clear the reference to the UnifiedArchive object in the engine
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   763
            # data cache to avoid collision with the next checkpoint execution.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   764
            self._install_engine.doc.volatile.delete_children(
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   765
                class_type=UnifiedArchive)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   766
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   767
    def _suri_from_volume_info(self, connection_info):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   768
        """Returns a suri(5) formatted string based on connection_info
3178
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   769
        Currently supports local ZFS volume and iSCSI driver types.
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   770
        """
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   771
        driver_type = connection_info['driver_volume_type']
3178
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   772
        if driver_type not in ['iscsi', 'fibre_channel', 'local']:
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   773
            raise exception.VolumeDriverNotFound(driver_type=driver_type)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   774
        if driver_type == 'local':
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   775
            suri = 'dev:/dev/zvol/dsk/%s' % connection_info['volume_path']
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   776
        elif driver_type == 'iscsi':
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   777
            data = connection_info['data']
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   778
            # suri(5) format:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   779
            #       iscsi://<host>[:<port>]/target.<IQN>,lun.<LUN>
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   780
            # Sample iSCSI connection data values:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   781
            # target_portal: 192.168.1.244:3260
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   782
            # target_iqn: iqn.2010-10.org.openstack:volume-a89c.....
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   783
            # target_lun: 1
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   784
            suri = 'iscsi://%s/target.%s,lun.%d' % (data['target_portal'],
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   785
                                                    data['target_iqn'],
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   786
                                                    data['target_lun'])
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   787
            # TODO(npower): need to handle CHAP authentication also
3178
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   788
        elif driver_type == 'fibre_channel':
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   789
            data = connection_info['data']
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   790
            target_wwn = data['target_wwn']
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   791
            # Check for multiple target_wwn values in a list
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   792
            if isinstance(target_wwn, list):
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   793
                target_wwn = target_wwn[0]
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   794
            # Ensure there's a fibre channel HBA.
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   795
            hbas = self._get_fc_hbas()
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   796
            if not hbas:
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   797
                LOG.error(_("Cannot attach Fibre Channel volume '%s' because "
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   798
                          "no Fibre Channel HBA initiators were found")
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   799
                          % (target_wwn))
3200
16d08ab96b7f 18686478 kstat warning every minute in nova-compute log on SPARC
david.comay@oracle.com
parents: 3178
diff changeset
   800
                raise exception.InvalidVolume(
16d08ab96b7f 18686478 kstat warning every minute in nova-compute log on SPARC
david.comay@oracle.com
parents: 3178
diff changeset
   801
                    reason="No host Fibre Channel initiator found")
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   802
3178
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   803
            target_lun = data['target_lun']
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   804
            # If the volume was exported just a few seconds previously then
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   805
            # it will probably not be visible to the local adapter yet.
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   806
            # Invoke 'fcinfo remote-port' on all local HBA ports to trigger
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   807
            # a refresh.
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   808
            for wwpn in self._get_fc_wwpns():
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   809
                utils.execute('/usr/sbin/fcinfo', 'remote-port',
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   810
                              '-p', wwpn)
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   811
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   812
            # Use suriadm(1M) to generate a Fibre Channel storage URI.
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   813
            try:
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   814
                out, err = utils.execute('/usr/sbin/suriadm', 'lookup-uri',
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   815
                                         '-p', 'target=naa.%s' % target_wwn,
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   816
                                         '-p', 'lun=%s' % target_lun)
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   817
            except processutils.ProcessExecutionError as err:
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   818
                LOG.error(_("Lookup failure of Fibre Channel volume '%s', lun "
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   819
                          "%s: %s") % (target_wwn, target_lun, err.stderr))
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   820
                raise
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   821
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   822
            lines = out.split('\n')
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   823
            # Use the long form SURI on the second output line.
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   824
            suri = lines[1].strip()
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   825
        return suri
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   826
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   827
    def _set_global_properties(self, name, extra_specs, brand):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   828
        """Set Solaris Zone's global properties if supplied via flavor."""
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   829
        zone = self._get_zone_by_name(name)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   830
        if zone is None:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   831
            raise exception.InstanceNotFound(instance_id=name)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   832
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   833
        # TODO(dcomay): Should figure this out via the brands themselves.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   834
        zonecfg_items = [
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   835
            'bootargs',
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   836
            'brand',
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   837
            'hostid'
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   838
        ]
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   839
        if brand == ZONE_BRAND_SOLARIS:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   840
            zonecfg_items.extend(
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   841
                ['file-mac-profile', 'fs-allowed', 'limitpriv'])
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   842
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   843
        with ZoneConfig(zone) as zc:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   844
            for key, value in extra_specs.iteritems():
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   845
                # Ignore not-zonecfg-scoped brand properties.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   846
                if not key.startswith('zonecfg:'):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   847
                    continue
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   848
                _scope, prop = key.split(':', 1)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   849
                # Ignore the 'brand' property if present.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   850
                if prop == 'brand':
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   851
                    continue
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   852
                # Ignore but warn about unsupported zonecfg-scoped properties.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   853
                if prop not in zonecfg_items:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   854
                    LOG.warning(_("Ignoring unsupported zone property '%s' "
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   855
                                  "set on flavor for instance '%s'")
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   856
                                % (prop, name))
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   857
                    continue
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   858
                zc.setprop('global', prop, value)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   859
4629
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   860
    def _create_boot_volume(self, context, instance):
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   861
        """Create a (Cinder) volume service backed boot volume"""
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   862
        try:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   863
            vol = self._volume_api.create(
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   864
                context,
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   865
                instance['root_gb'],
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   866
                instance['display_name'] + "-rootzpool",
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   867
                "Boot volume for instance '%s' (%s)"
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   868
                % (instance['name'], instance['uuid']))
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   869
            # TODO(npower): Polling is what nova/compute/manager also does when
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   870
            # creating a new volume, so we do likewise here.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   871
            while True:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   872
                volume = self._volume_api.get(context, vol['id'])
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   873
                if volume['status'] != 'creating':
4629
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   874
                    return volume
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   875
                greenthread.sleep(1)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   876
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   877
        except Exception as reason:
3178
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   878
            LOG.error(_("Unable to create root zpool volume for instance '%s'"
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   879
                        ": %s") % (instance['name'], reason))
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   880
            raise
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   881
4629
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   882
    def _connect_boot_volume(self, volume, mountpoint, context, instance,
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   883
                             extra_specs):
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   884
        """Connect a (Cinder) volume service backed boot volume"""
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   885
        brand = extra_specs.get('zonecfg:brand', ZONE_BRAND_SOLARIS)
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   886
        instance_uuid = instance['uuid']
3178
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   887
        volume_id = volume['id']
4629
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   888
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   889
        connector = self.get_volume_connector(instance)
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   890
        connection_info = self._volume_api.initialize_connection(
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   891
            context, volume_id, connector)
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   892
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   893
        # Check connection_info to determine if the provided volume is
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   894
        # local to this compute node. If it is, then don't use it for
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   895
        # Solaris branded zones in order to avoid a known ZFS deadlock issue
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   896
        # when using a zpool within another zpool on the same system.
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   897
        if brand == ZONE_BRAND_SOLARIS:
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   898
            driver_type = connection_info['driver_volume_type']
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   899
            if driver_type == 'local':
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   900
                msg = _("Detected 'local' zvol driver volume type "
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   901
                        "from volume service, which should not be "
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   902
                        "used as a boot device for 'solaris' "
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   903
                        "branded zones.")
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   904
                raise exception.InvalidVolume(reason=msg)
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   905
            elif driver_type == 'iscsi':
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   906
                # Check for a potential loopback iSCSI situation
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   907
                data = connection_info['data']
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   908
                target_portal = data['target_portal']
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   909
                # Strip off the port number (eg. 127.0.0.1:3260)
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   910
                host = target_portal.rsplit(':', 1)
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   911
                # Strip any enclosing '[' and ']' brackets for
5409
2c588e2f06d9 20410887 Solaris Nova driver should be resilient when network info is None
saurabh.vyas@oracle.com
parents: 4679
diff changeset
   912
                # IPv6 addresses.
4629
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   913
                target_host = host[0].strip('[]')
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   914
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   915
                # Check if target_host is an IP or hostname matching the
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   916
                # connector host or IP, which would mean the provisioned
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   917
                # iSCSI LUN is on the same host as the instance.
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   918
                if target_host in [connector['ip'], connector['host']]:
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   919
                    msg = _("iSCSI connection info from volume "
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   920
                            "service indicates that the target is a "
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   921
                            "local volume, which should not be used "
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   922
                            "as a boot device for 'solaris' branded "
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   923
                            "zones.")
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   924
                    raise exception.InvalidVolume(reason=msg)
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   925
            # Assuming that fibre_channel is non-local
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   926
            elif driver_type != 'fibre_channel':
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   927
                # Some other connection type that we don't understand
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   928
                # Let zone use some local fallback instead.
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   929
                msg = _("Unsupported volume driver type '%s' can not be used "
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   930
                        "as a boot device for zones." % driver_type)
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   931
                raise exception.InvalidVolume(reason=msg)
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   932
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   933
        # Volume looks OK to use. Notify Cinder of the attachment.
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   934
        self._volume_api.attach(context, volume_id, instance_uuid,
4991a5f4f6b9 20052290 instance failed to launch with InvalidBDM: Block Device Mapping is Invalid
Niall Power <niall.power@oracle.com>
parents: 4628
diff changeset
   935
                                mountpoint)
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   936
        return connection_info
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   937
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   938
    def _set_boot_device(self, name, connection_info, brand):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   939
        """Set the boot device specified by connection_info"""
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   940
        zone = self._get_zone_by_name(name)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   941
        if zone is None:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   942
            raise exception.InstanceNotFound(instance_id=name)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   943
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   944
        suri = self._suri_from_volume_info(connection_info)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   945
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   946
        with ZoneConfig(zone) as zc:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   947
            # ZOSS device configuration is different for the solaris-kz brand
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   948
            if brand == ZONE_BRAND_SOLARIS_KZ:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   949
                zc.zone.setResourceProperties(
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   950
                    zonemgr.Resource(
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   951
                        "device",
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   952
                        [zonemgr.Property("bootpri", "0")]),
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   953
                    [zonemgr.Property("storage", suri)])
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   954
            else:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   955
                zc.addresource(
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   956
                    "rootzpool",
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   957
                    [zonemgr.Property("storage", listvalue=[suri])])
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   958
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   959
    def _set_num_cpu(self, name, vcpus, brand):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   960
        """Set number of VCPUs in a Solaris Zone configuration."""
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   961
        zone = self._get_zone_by_name(name)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   962
        if zone is None:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   963
            raise exception.InstanceNotFound(instance_id=name)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   964
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   965
        # The Solaris Zone brand type is used to specify the type of
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   966
        # 'cpu' resource set in the Solaris Zone configuration.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   967
        if brand == ZONE_BRAND_SOLARIS:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   968
            vcpu_resource = 'capped-cpu'
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   969
        else:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   970
            vcpu_resource = 'virtual-cpu'
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   971
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   972
        # TODO(dcomay): Until 17881862 is resolved, this should be turned into
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   973
        # an appropriate 'rctl' resource for the 'capped-cpu' case.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   974
        with ZoneConfig(zone) as zc:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   975
            zc.setprop(vcpu_resource, 'ncpus', str(vcpus))
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   976
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   977
    def _set_memory_cap(self, name, memory_mb, brand):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   978
        """Set memory cap in a Solaris Zone configuration."""
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   979
        zone = self._get_zone_by_name(name)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   980
        if zone is None:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   981
            raise exception.InstanceNotFound(instance_id=name)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   982
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   983
        # The Solaris Zone brand type is used to specify the type of
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   984
        # 'memory' cap set in the Solaris Zone configuration.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   985
        if brand == ZONE_BRAND_SOLARIS:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   986
            mem_resource = 'swap'
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   987
        else:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   988
            mem_resource = 'physical'
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   989
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   990
        with ZoneConfig(zone) as zc:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   991
            zc.setprop('capped-memory', mem_resource, '%dM' % memory_mb)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   992
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   993
    def _set_network(self, context, name, instance, network_info, brand,
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   994
                     sc_dir):
3178
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   995
        """add networking information to the zone."""
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   996
        zone = self._get_zone_by_name(name)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   997
        if zone is None:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   998
            raise exception.InstanceNotFound(instance_id=name)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   999
5409
2c588e2f06d9 20410887 Solaris Nova driver should be resilient when network info is None
saurabh.vyas@oracle.com
parents: 4679
diff changeset
  1000
        if not network_info:
2c588e2f06d9 20410887 Solaris Nova driver should be resilient when network info is None
saurabh.vyas@oracle.com
parents: 4679
diff changeset
  1001
            with ZoneConfig(zone) as zc:
2c588e2f06d9 20410887 Solaris Nova driver should be resilient when network info is None
saurabh.vyas@oracle.com
parents: 4679
diff changeset
  1002
                if brand == ZONE_BRAND_SOLARIS:
2c588e2f06d9 20410887 Solaris Nova driver should be resilient when network info is None
saurabh.vyas@oracle.com
parents: 4679
diff changeset
  1003
                    zc.removeresources("anet",
2c588e2f06d9 20410887 Solaris Nova driver should be resilient when network info is None
saurabh.vyas@oracle.com
parents: 4679
diff changeset
  1004
                                       [zonemgr.Property("linkname", "net0")])
2c588e2f06d9 20410887 Solaris Nova driver should be resilient when network info is None
saurabh.vyas@oracle.com
parents: 4679
diff changeset
  1005
                else:
2c588e2f06d9 20410887 Solaris Nova driver should be resilient when network info is None
saurabh.vyas@oracle.com
parents: 4679
diff changeset
  1006
                    zc.removeresources("anet", [zonemgr.Property("id", "0")])
2c588e2f06d9 20410887 Solaris Nova driver should be resilient when network info is None
saurabh.vyas@oracle.com
parents: 4679
diff changeset
  1007
                return
2c588e2f06d9 20410887 Solaris Nova driver should be resilient when network info is None
saurabh.vyas@oracle.com
parents: 4679
diff changeset
  1008
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1009
        tenant_id = None
4072
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
  1010
        network_plugin = neutronv2.get_client(context)
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1011
        for netid, network in enumerate(network_info):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1012
            if tenant_id is None: