components/openstack/nova/files/solariszones/driver.py
author Danek Duvall <danek.duvall@oracle.com>
Tue, 07 Apr 2015 13:31:20 -0700
branchs11-update
changeset 4072 db0cec748ec0
parent 3809 eb8d6ce0657e
child 4569 e6bd6f2f307f
permissions -rw-r--r--
PSARC 2015/110 OpenStack service updates for Juno PSARC 2014/302 oslo.messaging - OpenStack RPC and notifications PSARC 2014/303 concurrent.futures - high-level Python interface for asynchronous execution PSARC 2014/304 networkx - Python module for complex networks PSARC 2014/305 taskflow - Python module for task execution PSARC 2014/329 pycadf - Python interface for CADF (cloud auditing) PSARC 2014/330 posix_ipc - POSIX IPC primitives for Python PSARC 2014/331 oauthlib - Python implementation of OAuth request-signing logic PSARC 2015/058 oslo - OpenStack common libraries (context, db, i18n, middleware, serialization, utils, vmware) PSARC 2015/059 glance_store - Glance storage library PSARC 2015/060 ipaddr - an IPv4/IPv6 manipulation library in Python PSARC 2015/061 simplegeneric - single-dispatch generic Python functions PSARC 2015/062 wsme - Web Services Made Easy PSARC 2015/063 retrying - General purpose Python retrying library PSARC 2015/065 osprofiler - an OpenStack cross-project profiling library PSARC 2015/066 OpenStack client for Sahara (Hadoop as a Service) PSARC 2015/067 keystonemiddleware - Middleware for OpenStack Identity PSARC 2015/068 pyScss - Compiler for the SCSS flavor of the Sass language PSARC 2015/069 django-pyscss - pyScss support for Django PSARC 2015/073 barbicanclient - OpenStack client for Barbican (Key Management) PSARC 2015/074 pysendfile - Python interface to sendfile PSARC 2015/097 ldappool - a connection pool for python-ldap PSARC 2015/098 rfc3986 - URI reference validation module for Python PSARC 2015/102 iniparse - python .ini file parsing module 20667775 OpenStack service updates for Juno (Umbrella) 17511386 sqlalchemy-migrate should lose its bypass-gen tags once sqlalchemy is in the CBE 18293987 /usr/bin/alembic should be shipped 18293992 boto's demo scripts aren't delivered executable 18377642 py.test has a requirement on py 18615101 Horizon should prevent network, subnet, and port names with hyphens in them 18772068 instance failed to launch with NoValidHost but no reason 18887457 openstack shouldn't deliver .po files 18905324 hostname.xml should set config/ignore_dhcp_hostname = true 18961031 Duplicate names for role-create and user-create are allowed 19015363 Users should not be allowed to attempt to create volumes when quota exceed 19044301 boto's dependencies need work 19050335 user appears logged in but unauthorised after horizon reboot 19065699 cinderclient-34 lost in recent upgrade 19131218 solaris.css: 'Delete Interface' button in Router pop-up menu broken 19131507 solaris.css: 'Project Limits' section of Launch Instance pop-up menu broken 19144215 Instance manipulation buttons greyed out after all instances terminated 19249066 heat stack-preview doesn't appear to do anything 19313272 Need bottom slidebar in horizon for small browser windows 19439030 'nova migration-list' returns python error 19462265 The Python module oslo.messaging should be added to Userland 19462397 The Python module futures should be added to Userland 19476604 The Python module networkx should be added to Userland 19476953 The Python module taskflow should be added to Userland 19519227 The Python module pycadf should be added to Userland 19582394 The Python module posix_ipc should be added to Userland 19596691 instance failed to launch, cinder hit resource busy in stmfadm 19598430 The Python module oauthlib should be added to Userland 19649055 FC connection fails when the target_lun is assigned 0 19815780 nova package should have dependencies on brand-solaris and brand-solaris-kz 19883623 Image snapshots are missing 'instance_uuid' property 19887874 horizon should set up apache log rotation 19888859 six should enable its tests now. 19987962 Cinder lists additional volumes attached to instance with linuxy device names 20027791 horizon should be migrated to Apache 2.4 20046570 rabbitmq & rad-evs-controller should be added to group package 20052466 remove _ai_health_check() from driver.py now that 18857274 is integrated 20164815 The Python module django-pyscss should be added to Userland 20173049 The Python module retrying should be added to Userland 20174489 The Python module WSME should be added to Userland 20176001 The Python module keystonemiddleware should be added to Userland 20182039 The Python module pysendfile should be added to Userland 20200162 The Python module pyScss should be added to Userland 20222184 horizon doesn't send start request on shutdown instance 20312312 The Python module python-saharaclient should be added to Userland 20388250 problem in SERVICE/GLANCE 20433402 The fix for 20388250 is incomplete 20514287 wrong vnic label name used for dhcp vnic in evs 20596802 The Python module oslo.middleware should be added to Userland 20596803 The Python module barbicanclient should be added to Userland 20596804 The Python module oslo.context should be added to Userland 20596805 The Python module iniparse should be added to Userland 20596806 The Python module oslo.vmware should be added to Userland 20596807 The Python module osprofiler should be added to Userland 20596808 The Python module oslo.i18n should be added to Userland 20596809 The Python module oslo.utils should be added to Userland 20596811 The Python module ipaddr should be added to Userland 20596812 The Python module glance_store should be added to Userland 20596813 The Python module oslo.serialization should be added to Userland 20596814 The Python module oslo.db should be added to Userland 20596815 The Python module simplegeneric should be added to Userland 20602690 The Python module ldappool should be added to Userland 20602722 The Python module rfc3986 should be added to Userland 20638369 compilemessages.py requires GNU msgfmt without calling gmsgfmt 20715741 cinder 2014.2.2 20715742 glance 2014.2.2 20715743 heat 2014.2.2 20715744 horizon 2014.2.2 20715745 keystone 2014.2.2 20715746 neutron 2014.2.2 20715747 nova 2014.2.2 20715748 swift 2.2.2 20715749 alembic 0.7.4 20715750 amqp 1.4.6 20715751 boto 2.34.0 20715752 ceilometerclient 1.0.12 20715753 cinderclient 1.1.1 20715754 cliff 1.9.0 20715756 django 1.4.19 20739229 Update django to 1.4.20 20715757 django_compressor 1.4 20715758 django_openstack_auth 1.1.9 20715759 eventlet 0.15.2 20715761 glanceclient 0.15.0 20715762 greenlet 0.4.5 20715763 heatclient 0.2.12 20715764 keystoneclient 1.0.0 20715765 kombu 3.0.7 20715766 mysql 1.2.5 20715767 netaddr 0.7.13 20715769 netifaces 0.10.4 20715770 neutronclient 2.3.10 20715771 novaclient 2.20.0 20715772 oslo.config 1.6.0 20715773 py 1.4.26 20715774 pyflakes 0.8.1 20715775 pytest 2.6.4 20715776 pytz 2014.10 20715777 requests 2.6.0 20715778 simplejson 3.6.5 20715779 six 1.9.0 20715780 sqlalchemy-migrate 0.9.1 20715781 sqlalchemy 0.9.8 20715782 stevedore 1.2.0 20715783 swiftclient 2.3.1 20715784 tox 1.8.1 20715785 troveclient 1.0.8 20715786 virtualenv 12.0.7 20715787 websockify 0.6.0 20739215 problem in PYTHON-MOD/DJANGO 20739295 problem in PYTHON-MOD/DJANGO 20816861 zone-vnc-console instance goes in to maintenance 20829672 support flat network type in neutron
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
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    29
import rad.bindings.com.oracle.solaris.rad.kstat as kstat
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    30
import rad.bindings.com.oracle.solaris.rad.zonemgr as zonemgr
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
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    41
from oslo.config import cfg
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
4072
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
    53
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
    54
from nova.openstack.common import fileutils
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    55
from nova.openstack.common import jsonutils
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    56
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
    57
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
    58
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
    59
from nova.openstack.common import strutils
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    60
from nova import utils
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    61
from nova.virt import driver
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    62
from nova.virt import event as virtevent
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    63
from nova.virt import images
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    64
from nova.virt.solariszones import sysconfig
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    65
from nova import volume
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    66
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    67
solariszones_opts = [
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    68
    cfg.StrOpt('glancecache_dirname',
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    69
               default='$state_path/images',
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    70
               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
    71
    cfg.StrOpt('solariszones_snapshots_directory',
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    72
               default='$instances_path/snapshots',
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    73
               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
    74
                    '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
    75
]
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
CONF = cfg.CONF
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    78
CONF.register_opts(solariszones_opts)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    79
LOG = logging.getLogger(__name__)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    80
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    81
# 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
    82
# 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
    83
# 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
    84
# the zonemgr(3RAD) provider.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    85
ZONE_STATE_CONFIGURED = 'configured'
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    86
ZONE_STATE_INCOMPLETE = 'incomplete'
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    87
ZONE_STATE_UNAVAILABLE = 'unavailable'
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    88
ZONE_STATE_INSTALLED = 'installed'
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    89
ZONE_STATE_READY = 'ready'
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    90
ZONE_STATE_RUNNING = 'running'
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    91
ZONE_STATE_SHUTTING_DOWN = 'shutting_down'
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    92
ZONE_STATE_DOWN = 'down'
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    93
ZONE_STATE_MOUNTED = 'mounted'
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    94
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    95
# 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
    96
SOLARISZONES_POWER_STATE = {
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    97
    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
    98
    ZONE_STATE_INCOMPLETE:      power_state.NOSTATE,
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    99
    ZONE_STATE_UNAVAILABLE:     power_state.NOSTATE,
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   100
    ZONE_STATE_INSTALLED:       power_state.SHUTDOWN,
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   101
    ZONE_STATE_READY:           power_state.RUNNING,
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   102
    ZONE_STATE_RUNNING:         power_state.RUNNING,
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   103
    ZONE_STATE_SHUTTING_DOWN:   power_state.RUNNING,
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   104
    ZONE_STATE_DOWN:            power_state.RUNNING,
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   105
    ZONE_STATE_MOUNTED:         power_state.NOSTATE
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   106
}
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   107
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   108
# 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
   109
ZONE_BRAND_LABELED = 'labeled'
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   110
ZONE_BRAND_SOLARIS = 'solaris'
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   111
ZONE_BRAND_SOLARIS_KZ = 'solaris-kz'
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   112
ZONE_BRAND_SOLARIS10 = 'solaris10'
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   113
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   114
# 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
   115
# brand template.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   116
ZONE_BRAND_TEMPLATE = {
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   117
    ZONE_BRAND_SOLARIS:         'SYSdefault',
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   118
    ZONE_BRAND_SOLARIS_KZ:      'SYSsolaris-kz',
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   119
}
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   120
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   121
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
   122
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
   123
# 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
   124
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
   125
XTERM_PATH = '/usr/bin/xterm'
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   126
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   127
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   128
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
   129
    """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
   130
    try:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   131
        val = zone.getResourceProperties(zonemgr.Resource(resource, filter),
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   132
                                         [prop])
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   133
    except rad.client.ObjectError:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   134
        return None
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   135
    except Exception:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   136
        raise
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   137
    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
   138
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   139
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   140
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
   141
    """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
   142
    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
   143
    """
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   144
    try:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   145
        resources = zone.getResources(zonemgr.Resource(resource))
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   146
        for resource in resources:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   147
            for propertee in resource.properties:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   148
                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
   149
                    return propertee
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   150
        else:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   151
            return None
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   152
    except rad.client.ObjectError:
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 Exception:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   155
        raise
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   156
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   157
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   158
class ZoneConfig(object):
3178
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   159
    """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
   160
    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
   161
    before exiting
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   162
    """
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   163
    def __init__(self, zone):
3178
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   164
        """zone is a zonemgr object representing either a kernel zone or
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   165
        non-glboal zone.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   166
        """
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   167
        self.zone = zone
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   168
        self.editing = False
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   169
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   170
    def __enter__(self):
3178
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   171
        """enables the editing of the zone."""
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   172
        try:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   173
            self.zone.editConfig()
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   174
            self.editing = True
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   175
            return self
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   176
        except rad.client.ObjectError as err:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   177
            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
   178
                        "zonemgr(3RAD): %s") % (self.zone.name, err))
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   179
            raise
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   180
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   181
    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
   182
        """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
   183
        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
   184
        commit the new configuration.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   185
        """
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   186
        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
   187
            # 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
   188
            self.zone.cancelConfig()
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   189
            raise
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   190
        else:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   191
            # commit the config
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   192
            try:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   193
                self.zone.commitConfig()
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   194
            except rad.client.ObjectError as err:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   195
                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
   196
                            "instance '%s' via zonemgr(3RAD): %s")
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   197
                          % (self.zone.name, err))
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   198
                raise
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   199
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   200
    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
   201
        """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
   202
        with the given property(s).
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   203
        """
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   204
        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
   205
        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
   206
            # the value is already set
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   207
            return
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
        try:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   210
            if current is None:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   211
                self.zone.addResource(zonemgr.Resource(
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   212
                    resource, [zonemgr.Property(prop, value)]))
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   213
            else:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   214
                self.zone.setResourceProperties(
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   215
                    zonemgr.Resource(resource),
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   216
                    [zonemgr.Property(prop, value)])
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   217
        except rad.client.ObjectError as err:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   218
            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
   219
                        "instance '%s' via zonemgr(3RAD): %s")
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   220
                      % (prop, resource, self.zone.name, err))
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   221
            raise
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   222
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   223
    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
   224
        """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
   225
        if props is None:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   226
            props = []
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
        try:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   229
            self.zone.addResource(zonemgr.Resource(resource, props))
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   230
        except rad.client.ObjectError as err:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   231
            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
   232
                        "via zonemgr(3RAD): %s")
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   233
                      % (resource, self.zone.name, err))
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   234
            raise
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   235
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   236
    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
   237
        """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
   238
        list specified in props.
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   239
        """
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   240
        if props is None:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   241
            props = []
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   242
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   243
        try:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   244
            self.zone.removeResources(zonemgr.Resource(resource, props))
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   245
        except rad.client.ObjectError as err:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   246
            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
   247
                        "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
   248
            raise
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   249
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   250
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   251
class SolarisZonesDriver(driver.ComputeDriver):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   252
    """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
   253
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   254
    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
   255
    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
   256
    (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
   257
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   258
    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
   259
    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
   260
    '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
   261
    'instance name' are synonyms.
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
    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
   264
    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
   265
    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
   266
    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
   267
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   268
    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
   269
    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
   270
    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
   271
    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
   272
    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
   273
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   274
    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
   275
    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
   276
    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
   277
    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
   278
    virtualization platform.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   279
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   280
    """
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   281
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   282
    capabilities = {
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   283
        "has_imagecache": False,
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   284
        "supports_recreate": False,
4072
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   285
        }
3028
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
    def __init__(self, virtapi):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   288
        self.virtapi = virtapi
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   289
        self._compute_event_callback = None
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   290
        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
   291
        self._fc_hbas = None
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   292
        self._fc_wwnns = None
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   293
        self._fc_wwpns = None
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   294
        self._host_stats = {}
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   295
        self._initiator = None
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   296
        self._install_engine = None
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   297
        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
   298
        self._rad_connection = None
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   299
        self._uname = os.uname()
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   300
        self._validated_archives = list()
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   301
        self._volume_api = volume.API()
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   302
4072
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   303
    @property
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   304
    def rad_connection(self):
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   305
        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
   306
            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
   307
        else:
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   308
            # 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
   309
            # closed connection
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   310
            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
   311
                # 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
   312
                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
   313
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   314
        return self._rad_connection
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   315
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   316
    def _init_rad(self):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   317
        """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
   318
        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
   319
        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
   320
        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
   321
        via zonemgr(3RAD).
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   322
        """
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   323
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   324
        try:
4072
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   325
            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
   326
                kstat.Control())
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   327
        except Exception as reason:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   328
            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
   329
                   % reason)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   330
            raise exception.NovaException(msg)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   331
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   332
    def init_host(self, host):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   333
        """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
   334
        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
   335
        """
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   336
        # 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
   337
        self._init_rad()
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   338
4072
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   339
    def cleanup_host(self, host):
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   340
        """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
   341
        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
   342
        """
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   343
        pass
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   344
3178
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   345
    def _get_fc_hbas(self):
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   346
        """Get Fibre Channel HBA information."""
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   347
        if self._fc_hbas:
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   348
            return self._fc_hbas
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   349
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   350
        out = None
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   351
        try:
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   352
            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
   353
        except processutils.ProcessExecutionError as err:
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   354
            return []
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   355
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   356
        if out is None:
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   357
            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
   358
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   359
        hbas = []
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   360
        hba = {}
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   361
        for line in out.splitlines():
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   362
            line = line.strip()
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   363
            # 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
   364
            # 1: Port WWN
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   365
            # 2: State (online|offline)
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   366
            # 3: Node WWN
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   367
            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
   368
                # New HBA port entry
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   369
                hba = {}
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   370
                wwpn = line.split()[-1]
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   371
                hba['port_name'] = wwpn
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   372
                continue
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   373
            elif line.startswith("Port Mode:"):
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   374
                mode = line.split()[-1]
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   375
                # Skip Target mode ports
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   376
                if mode != 'Initiator':
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   377
                    break
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   378
            elif line.startswith("State:"):
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   379
                state = line.split()[-1]
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   380
                hba['port_state'] = state
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   381
                continue
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   382
            elif line.startswith("Node WWN:"):
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   383
                wwnn = line.split()[-1]
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   384
                hba['node_name'] = wwnn
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   385
                continue
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   386
            if len(hba) == 3:
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   387
                hbas.append(hba)
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   388
                hba = {}
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   389
        self._fc_hbas = hbas
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   390
        return self._fc_hbas
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   391
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   392
    def _get_fc_wwnns(self):
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   393
        """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
   394
        hbas = self._get_fc_hbas()
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   395
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   396
        wwnns = []
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   397
        for hba in hbas:
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   398
            if hba['port_state'] == 'online':
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   399
                wwnn = hba['node_name']
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   400
                wwnns.append(wwnn)
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   401
        return wwnns
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   402
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   403
    def _get_fc_wwpns(self):
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   404
        """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
   405
        hbas = self._get_fc_hbas()
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   406
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   407
        wwpns = []
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   408
        for hba in hbas:
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   409
            if hba['port_state'] == 'online':
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   410
                wwpn = hba['port_name']
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   411
                wwpns.append(wwpn)
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   412
        return wwpns
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   413
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   414
    def _get_iscsi_initiator(self):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   415
        """ 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
   416
        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
   417
                                 'initiator-node')
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   418
        # Sample first line of command output:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   419
        # 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
   420
        initiator_name_line = out.splitlines()[0]
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   421
        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
   422
        return initiator_iqn
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   423
3178
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   424
    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
   425
        """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
   426
           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
   427
        """
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   428
        try:
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   429
            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
   430
                                     '/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
   431
                                     'auto-installer:default')
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   432
            return out.strip()
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   433
        except processutils.ProcessExecutionError as err:
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   434
            # 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
   435
            return None
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   436
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   437
    def _get_zone_by_name(self, name):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   438
        """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
   439
        try:
4072
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   440
            zone = self.rad_connection.get_object(
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   441
                zonemgr.Zone(), rad.client.ADRGlobPattern({'name': name}))
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   442
        except rad.client.NotFoundError:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   443
            return None
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   444
        except Exception:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   445
            raise
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   446
        return zone
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   447
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   448
    def _get_state(self, zone):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   449
        """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
   450
        return SOLARISZONES_POWER_STATE[zone.state]
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   451
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   452
    def _pages_to_kb(self, pages):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   453
        """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
   454
        return (pages * self._pagesize) / 1024
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   455
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   456
    def _get_max_mem(self, zone):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   457
        """Return the maximum memory in KBytes allowed."""
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   458
        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
   459
        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
   460
            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
   461
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   462
        # 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
   463
        # 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
   464
        # memory.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   465
        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
   466
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   467
    def _get_mem(self, zone):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   468
        """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
   469
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   470
        # 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
   471
        # 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
   472
        # for now.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   473
        return self._get_max_mem(zone)
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
    def _get_num_cpu(self, zone):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   476
        """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
   477
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   478
        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
   479
        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
   480
        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
   481
        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
   482
        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
   483
        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
   484
        """
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   485
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   486
        # 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
   487
        # CPUs defined there.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   488
        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
   489
        if ncpus is not None:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   490
            min = ncpus.split('-', 1)[0]
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   491
            if min.isdigit():
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   492
                return int(min)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   493
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   494
        # 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
   495
        # number of CPUs defined there.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   496
        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
   497
        if ncpus is not None:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   498
            max = ncpus.split('-', 1)[-1]
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   499
            if max.isdigit():
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   500
                return int(max)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   501
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   502
        # 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
   503
        # 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
   504
        # 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
   505
        # 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
   506
        # of online CPUs.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   507
        return os.sysconf('SC_NPROCESSORS_ONLN')
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   508
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   509
    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
   510
        """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
   511
        pattern = {
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   512
            'class':    kstat_class,
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   513
            'module':   module,
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   514
            'instance': instance,
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   515
            'name':     name
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   516
        }
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   517
        try:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   518
            self._kstat_control.update()
4072
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   519
            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
   520
                kstat.Kstat(), rad.client.ADRGlobPattern(pattern))
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   521
        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
   522
            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
   523
                       "'%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
   524
                     % (module, instance, name, kstat_class, reason))
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   525
            return None
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   526
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   527
        kstat_data = {}
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   528
        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
   529
            kstat_data[named.name] = getattr(named.value,
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   530
                                             str(named.value.discriminant))
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   531
        return kstat_data
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   532
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   533
    def _get_cpu_time(self, zone):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   534
        """Return the CPU time used in nanoseconds."""
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   535
        if zone.id == -1:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   536
            return 0
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
        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
   539
                                             'sys_zone_aggr')
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   540
        if kstat_data is None:
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
        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
   544
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   545
    def get_info(self, instance):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   546
        """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
   547
4072
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   548
        :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
   549
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   550
        Returns a dict containing:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   551
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   552
        :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
   553
        :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
   554
        :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
   555
        :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
   556
        :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
   557
        """
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   558
        # 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
   559
        name = instance['name']
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   560
        zone = self._get_zone_by_name(name)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   561
        if zone is None:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   562
            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
   563
                      % name)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   564
            raise exception.InstanceNotFound(instance_id=name)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   565
        return {
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   566
            'state':    self._get_state(zone),
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   567
            'max_mem':  self._get_max_mem(zone),
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   568
            'mem':      self._get_mem(zone),
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   569
            'num_cpu':  self._get_num_cpu(zone),
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   570
            'cpu_time': self._get_cpu_time(zone)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   571
        }
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   572
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   573
    def get_num_instances(self):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   574
        """Return the total number of virtual machines.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   575
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   576
        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
   577
        about.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   578
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   579
        .. note::
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
            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
   582
            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
   583
            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
   584
            efficient.
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
        return len(self.list_instances())
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   587
4072
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   588
    def instance_exists(self, instance):
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   589
        """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
   590
4072
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   591
        :param instance: The instance to lookup
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   592
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   593
        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
   594
        the host, False otherwise.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   595
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   596
        .. note::
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
            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
   599
            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
   600
            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
   601
            efficient.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   602
        """
4072
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   603
        try:
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   604
            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
   605
        except NotImplementedError:
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   606
            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
   607
3178
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   608
    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
   609
        """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
   610
        of the given flavor.
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   611
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   612
        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
   613
        calculations are desired.
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   614
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   615
        :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
   616
        :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
   617
        """
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   618
        return {'memory_mb': 0}
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   619
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   620
    def _get_list_zone_object(self):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   621
        """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
   622
        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
   623
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   624
    def list_instances(self):
4072
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   625
        """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
   626
        layer, as a list.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   627
        """
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   628
        # 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
   629
        instances_list = []
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   630
        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
   631
            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
   632
        return instances_list
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   633
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   634
    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
   635
        """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
   636
        layer, as a list.
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   637
        """
4072
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   638
        raise NotImplementedError()
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   639
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   640
    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
   641
                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
   642
                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
   643
                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
   644
                preserve_ephemeral=False):
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   645
        """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
   646
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   647
        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
   648
        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
   649
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   650
        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
   651
        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
   652
        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
   653
        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
   654
        up steps.
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   655
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   656
        :param context: security context
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   657
        :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
   658
                         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
   659
                         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
   660
        :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
   661
                           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
   662
        :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
   663
        :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
   664
        :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
   665
        :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
   666
            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
   667
            usage.
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   668
        :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
   669
            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
   670
            usage.
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   671
        :param network_info:
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   672
           :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
   673
        :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
   674
            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
   675
        :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
   676
                                  attached to the instance.
db0cec748ec0 PSARC 2015/110 OpenStack service updates for Juno
Danek Duvall <danek.duvall@oracle.com>
parents: 3809
diff changeset
   677
        :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
   678
                                   partition must be preserved on rebuild
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   679
        """
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   680
        raise NotImplementedError()
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   681
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   682
    def _fetch_image(self, context, instance):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   683
        """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
   684
        glancecache_dirname = CONF.glancecache_dirname
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   685
        fileutils.ensure_tree(glancecache_dirname)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   686
        image = ''.join([glancecache_dirname, '/', instance['image_ref']])
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   687
        if os.path.exists(image):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   688
            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
   689
                      % instance['image_ref'])
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   690
            return image
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   691
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   692
        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
   693
                  % instance['image_ref'])
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   694
        try:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   695
            images.fetch(context, instance['image_ref'], image,
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   696
                         instance['user_id'], instance['project_id'])
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   697
        except Exception as reason:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   698
            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
   699
                      % (instance['image_ref'], reason))
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   700
            raise
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   701
        return image
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   702
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   703
    def _validate_image(self, image, instance):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   704
        """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
   705
        # 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
   706
        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
   707
            return
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   708
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   709
        if self._install_engine is None:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   710
            self._install_engine = InstallEngine(ARCHIVE_LOGFILE)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   711
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   712
        try:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   713
            init_ua_cp = InstantiateUnifiedArchive(instance['image_ref'],
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   714
                                                   image)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   715
            init_ua_cp.execute()
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   716
        except Exception:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   717
            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
   718
                        "Log file location: %s:%s")
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   719
                      % (self._uname[1], ARCHIVE_LOGFILE))
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   720
            LOG.error(reason)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   721
            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
   722
                                              reason=reason)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   723
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   724
        try:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   725
            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
   726
                class_type=UnifiedArchive)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   727
            # 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
   728
            # - contains one deployable system
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   729
            deployables = ua.archive_objects
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   730
            if len(deployables) != 1:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   731
                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
   732
                raise exception.ImageUnacceptable(
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   733
                    image_id=instance['image_ref'],
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   734
                    reason=reason)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   735
            # - matching architecture
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   736
            deployable_arch = deployables[0].system.arch
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   737
            compute_arch = platform.processor()
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   738
            if deployable_arch != compute_arch:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   739
                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
   740
                          'compute host architecture: "%s"')
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   741
                          % (deployable_arch, compute_arch))
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   742
                raise exception.ImageUnacceptable(
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   743
                    image_id=instance['image_ref'],
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   744
                    reason=reason)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   745
            # - single root pool only
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   746
            streams = deployables[0].zfs_streams
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   747
            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
   748
            if len(stream_pools) > 1:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   749
                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
   750
                          % (stream_pools))
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   751
                raise exception.ImageUnacceptable(
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   752
                    image_id=instance['image_ref'],
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   753
                    reason=reason)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   754
            # - looks like it's OK
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   755
            self._validated_archives.append(instance['image_ref'])
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   756
        finally:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   757
            # 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
   758
            # 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
   759
            self._install_engine.doc.volatile.delete_children(
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   760
                class_type=UnifiedArchive)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   761
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   762
    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
   763
        """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
   764
        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
   765
        """
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   766
        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
   767
        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
   768
            raise exception.VolumeDriverNotFound(driver_type=driver_type)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   769
        if driver_type == 'local':
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   770
            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
   771
        elif driver_type == 'iscsi':
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   772
            data = connection_info['data']
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   773
            # suri(5) format:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   774
            #       iscsi://<host>[:<port>]/target.<IQN>,lun.<LUN>
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   775
            # Sample iSCSI connection data values:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   776
            # target_portal: 192.168.1.244:3260
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   777
            # 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
   778
            # target_lun: 1
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   779
            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
   780
                                                    data['target_iqn'],
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   781
                                                    data['target_lun'])
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   782
            # 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
   783
        elif driver_type == 'fibre_channel':
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   784
            data = connection_info['data']
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   785
            target_wwn = data['target_wwn']
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   786
            # 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
   787
            if isinstance(target_wwn, list):
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   788
                target_wwn = target_wwn[0]
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   789
            # 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
   790
            hbas = self._get_fc_hbas()
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   791
            if not hbas:
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   792
                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
   793
                          "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
   794
                          % (target_wwn))
3200
16d08ab96b7f 18686478 kstat warning every minute in nova-compute log on SPARC
david.comay@oracle.com
parents: 3178
diff changeset
   795
                raise exception.InvalidVolume(
16d08ab96b7f 18686478 kstat warning every minute in nova-compute log on SPARC
david.comay@oracle.com
parents: 3178
diff changeset
   796
                    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
   797
3178
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   798
            target_lun = data['target_lun']
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   799
            # 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
   800
            # 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
   801
            # 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
   802
            # a refresh.
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   803
            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
   804
                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
   805
                              '-p', wwpn)
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   806
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   807
            # 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
   808
            try:
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   809
                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
   810
                                         '-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
   811
                                         '-p', 'lun=%s' % target_lun)
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   812
            except processutils.ProcessExecutionError as err:
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   813
                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
   814
                          "%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
   815
                raise
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   816
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   817
            lines = out.split('\n')
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   818
            # 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
   819
            suri = lines[1].strip()
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   820
        return suri
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   821
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   822
    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
   823
        """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
   824
        zone = self._get_zone_by_name(name)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   825
        if zone is None:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   826
            raise exception.InstanceNotFound(instance_id=name)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   827
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   828
        # 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
   829
        zonecfg_items = [
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   830
            'bootargs',
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   831
            'brand',
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   832
            'hostid'
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   833
        ]
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   834
        if brand == ZONE_BRAND_SOLARIS:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   835
            zonecfg_items.extend(
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   836
                ['file-mac-profile', 'fs-allowed', 'limitpriv'])
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   837
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   838
        with ZoneConfig(zone) as zc:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   839
            for key, value in extra_specs.iteritems():
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   840
                # Ignore not-zonecfg-scoped brand properties.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   841
                if not key.startswith('zonecfg:'):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   842
                    continue
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   843
                _scope, prop = key.split(':', 1)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   844
                # Ignore the 'brand' property if present.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   845
                if prop == 'brand':
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   846
                    continue
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   847
                # 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
   848
                if prop not in zonecfg_items:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   849
                    LOG.warning(_("Ignoring unsupported zone property '%s' "
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   850
                                  "set on flavor for instance '%s'")
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   851
                                % (prop, name))
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   852
                    continue
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   853
                zc.setprop('global', prop, value)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   854
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   855
    def _connect_boot_volume(self, context, instance, extra_specs):
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   856
        """Provision a (Cinder) volume service backed boot volume"""
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   857
        brand = extra_specs.get('zonecfg:brand', ZONE_BRAND_SOLARIS)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   858
        connection_info = None
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   859
        try:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   860
            vol = self._volume_api.create(
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   861
                context,
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   862
                instance['root_gb'],
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   863
                instance['display_name'] + "-rootzpool",
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   864
                "Boot volume for instance '%s' (%s)"
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   865
                % (instance['name'], instance['uuid']))
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   866
            # 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
   867
            # 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
   868
            while True:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   869
                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
   870
                if volume['status'] != 'creating':
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   871
                    break
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   872
                greenthread.sleep(1)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   873
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   874
        except Exception as reason:
3178
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   875
            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
   876
                        ": %s") % (instance['name'], reason))
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   877
            raise
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   878
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   879
        instance_uuid = instance['uuid']
3178
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   880
        volume_id = volume['id']
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   881
        # TODO(npower): Adequate for default boot device. We currently
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   882
        # ignore this value, but cinder gets stroppy about this if we set it to
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   883
        # None
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   884
        mountpoint = "c1d0"
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   885
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   886
        try:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   887
            connector = self.get_volume_connector(instance)
3178
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   888
            connection_info = self._volume_api.initialize_connection(
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   889
                context, volume_id, connector)
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   890
            # Check connection_info to determine if the provided volume is
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   891
            # local to this compute node. If it is, then don't use it for
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   892
            # Solaris branded zones in order to avoid a know ZFS deadlock issue
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   893
            # when using a zpool within another zpool on the same system.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   894
            delete_boot_volume = False
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   895
            if brand == ZONE_BRAND_SOLARIS:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   896
                driver_type = connection_info['driver_volume_type']
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   897
                if driver_type == 'local':
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   898
                    LOG.warning(_("Detected 'local' zvol driver volume type "
3809
eb8d6ce0657e PSARC/2014/377 noVNC - A browser based VNC client
Niall Power <niall.power@oracle.com>
parents: 3200
diff changeset
   899
                                  "from volume service, which should not be "
eb8d6ce0657e PSARC/2014/377 noVNC - A browser based VNC client
Niall Power <niall.power@oracle.com>
parents: 3200
diff changeset
   900
                                  "used as a boot device for 'solaris' "
eb8d6ce0657e PSARC/2014/377 noVNC - A browser based VNC client
Niall Power <niall.power@oracle.com>
parents: 3200
diff changeset
   901
                                  "branded zones."))
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   902
                    delete_boot_volume = True
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   903
                elif driver_type == 'iscsi':
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   904
                    # Check for a potential loopback iSCSI situation
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   905
                    data = connection_info['data']
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   906
                    target_portal = data['target_portal']
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   907
                    # Strip off the port number (eg. 127.0.0.1:3260)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   908
                    host = target_portal.rsplit(':', 1)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   909
                    # Strip any enclosing '[' and ']' brackets for
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   910
                    # IPV6 addresses.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   911
                    target_host = host[0].strip('[]')
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   912
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   913
                    # Check if target_host is an IP or hostname matching the
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   914
                    # connector host or IP, which would mean the provisioned
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   915
                    # iSCSI LUN is on the same host as the instance.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   916
                    if target_host in [connector['ip'], connector['host']]:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   917
                        LOG.warning(_("iSCSI connection info from volume "
3809
eb8d6ce0657e PSARC/2014/377 noVNC - A browser based VNC client
Niall Power <niall.power@oracle.com>
parents: 3200
diff changeset
   918
                                      "service indicates that the target is a "
eb8d6ce0657e PSARC/2014/377 noVNC - A browser based VNC client
Niall Power <niall.power@oracle.com>
parents: 3200
diff changeset
   919
                                      "local volume, which should not be used "
eb8d6ce0657e PSARC/2014/377 noVNC - A browser based VNC client
Niall Power <niall.power@oracle.com>
parents: 3200
diff changeset
   920
                                      "as a boot device for 'solaris' branded "
eb8d6ce0657e PSARC/2014/377 noVNC - A browser based VNC client
Niall Power <niall.power@oracle.com>
parents: 3200
diff changeset
   921
                                      "zones."))
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   922
                        delete_boot_volume = True
3178
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   923
                # Assuming that fibre_channel is non-local
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   924
                elif driver_type != 'fibre_channel':
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   925
                    # Some other connection type that we don't understand
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   926
                    # Let zone use some local fallback instead.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   927
                    LOG.warning(_("Unsupported volume driver type '%s' "
3809
eb8d6ce0657e PSARC/2014/377 noVNC - A browser based VNC client
Niall Power <niall.power@oracle.com>
parents: 3200
diff changeset
   928
                                  "can not be used as a boot device for "
eb8d6ce0657e PSARC/2014/377 noVNC - A browser based VNC client
Niall Power <niall.power@oracle.com>
parents: 3200
diff changeset
   929
                                  "'solaris' branded zones."))
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   930
                    delete_boot_volume = True
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   931
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   932
            if delete_boot_volume:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   933
                LOG.warning(_("Volume '%s' is being discarded") % volume['id'])
3178
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   934
                self._volume_api.delete(context, volume_id)
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   935
                return None
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   936
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   937
            # Notify Cinder DB of the volume attachment.
3178
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   938
            self._volume_api.attach(context, volume_id, instance_uuid,
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   939
                                    mountpoint)
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   940
            values = {
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   941
                'instance_uuid': instance['uuid'],
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   942
                'connection_info': jsonutils.dumps(connection_info),
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   943
                # TODO(npower): device_name also ignored currently, but Cinder
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   944
                # breaks without it. Figure out a sane mapping scheme.
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   945
                'device_name': mountpoint,
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   946
                'delete_on_termination': True,
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   947
                'virtual_name': None,
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   948
                'snapshot_id': None,
3178
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   949
                'volume_id': volume_id,
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   950
                'volume_size': instance['root_gb'],
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   951
                'no_device': None}
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   952
            self._conductor_api.block_device_mapping_update_or_create(context,
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   953
                                                                      values)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   954
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   955
        except Exception as reason:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   956
            LOG.error(_("Unable to attach root zpool volume '%s' to instance "
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   957
                        "%s: %s") % (volume['id'], instance['name'], reason))
3178
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   958
            self._volume_api.detach(context, volume_id)
77584387a894 PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 3141
diff changeset
   959
            self._volume_api.delete(context, volume_id)
3028
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   960
            raise
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   961
        return connection_info
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   962
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   963
    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
   964
        """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
   965
        zone = self._get_zone_by_name(name)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   966
        if zone is None:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   967
            raise exception.InstanceNotFound(instance_id=name)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   968
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   969
        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
   970
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   971
        with ZoneConfig(zone) as zc:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   972
            # 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
   973
            if brand == ZONE_BRAND_SOLARIS_KZ:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   974
                zc.zone.setResourceProperties(
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   975
                    zonemgr.Resource(
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   976
                        "device",
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   977
                        [zonemgr.Property("bootpri", "0")]),
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   978
                    [zonemgr.Property("storage", suri)])
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   979
            else:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   980
                zc.addresource(
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   981
                    "rootzpool",
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   982
                    [zonemgr.Property("storage", listvalue=[suri])])
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   983
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   984
    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
   985
        """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
   986
        zone = self._get_zone_by_name(name)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   987
        if zone is None:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   988
            raise exception.InstanceNotFound(instance_id=name)
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
        # 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
   991
        # '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
   992
        if brand == ZONE_BRAND_SOLARIS:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   993
            vcpu_resource = 'capped-cpu'
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   994
        else:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   995
            vcpu_resource = 'virtual-cpu'
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   996
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   997
        # 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
   998
        # 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
   999
        with ZoneConfig(zone) as zc:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1000
            zc.setprop(vcpu_resource, 'ncpus', str(vcpus))
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1001
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1002
    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
  1003
        """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
  1004
        zone = self._get_zone_by_name(name)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1005
        if zone is None:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1006
            raise exception.InstanceNotFound(instance_id=name)
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1007
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1008
        # 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
  1009
        # '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
  1010
        if brand == ZONE_BRAND_SOLARIS:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1011
            mem_resource = 'swap'
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1012
        else:
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
  1013
            mem_resource = 'physical'
5e73a3a3f66a PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@&#