Merge "Adds factory methods to load Hyper-V utils classes"
This commit is contained in:
commit
f34592b756
|
@ -2452,6 +2452,14 @@
|
|||
#instances_path_share=
|
||||
|
||||
|
||||
#
|
||||
# Options defined in nova.virt.hyperv.utilsfactory
|
||||
#
|
||||
|
||||
# Force V1 volume utility class (boolean value)
|
||||
#force_volumeutils_v1=false
|
||||
|
||||
|
||||
#
|
||||
# Options defined in nova.virt.hyperv.vif
|
||||
#
|
||||
|
@ -2494,9 +2502,6 @@
|
|||
# (integer value)
|
||||
#volume_attach_retry_interval=5
|
||||
|
||||
# Force volumeutils v1 (boolean value)
|
||||
#force_volumeutils_v1=false
|
||||
|
||||
|
||||
[osapi_v3]
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@ from nova.virt.hyperv import hostutils
|
|||
from nova.virt.hyperv import livemigrationutils
|
||||
from nova.virt.hyperv import networkutils
|
||||
from nova.virt.hyperv import pathutils
|
||||
from nova.virt.hyperv import utilsfactory
|
||||
from nova.virt.hyperv import vhdutils
|
||||
from nova.virt.hyperv import vmutils
|
||||
from nova.virt.hyperv import volumeutils
|
||||
|
@ -1011,25 +1012,38 @@ class HyperVAPITestCase(test.TestCase):
|
|||
fake_mounted_disk)
|
||||
m.WithSideEffects(self._add_volume_disk)
|
||||
|
||||
def _test_volumeutils_version(self, is_hyperv_2012=True,
|
||||
force_volumeutils_v1=False):
|
||||
def _test_util_class_version(self, v1_class, v2_class,
|
||||
get_instance_action, is_hyperv_2012,
|
||||
force_v1_flag, force_utils_v1):
|
||||
self._check_min_windows_version_satisfied = is_hyperv_2012
|
||||
self.flags(force_volumeutils_v1=force_volumeutils_v1, group='hyperv')
|
||||
CONF.set_override(force_v1_flag, force_v1_flag, 'hyperv')
|
||||
self._conn = driver_hyperv.HyperVDriver(None)
|
||||
is_volutils_v2 = isinstance(self._conn._volumeops._volutils,
|
||||
volumeutilsv2.VolumeUtilsV2)
|
||||
|
||||
self.assertTrue((is_hyperv_2012 and not force_volumeutils_v1) ^
|
||||
(not is_volutils_v2))
|
||||
instance = get_instance_action()
|
||||
is_v1 = isinstance(instance, v1_class)
|
||||
# v2_class can inherit from v1_class
|
||||
is_v2 = isinstance(instance, v2_class)
|
||||
|
||||
self.assertTrue((is_hyperv_2012 and not force_v1_flag) ^
|
||||
(is_v1 and not is_v2))
|
||||
|
||||
def test_volumeutils_version_hyperv_2012(self):
|
||||
self._test_volumeutils_version(True, False)
|
||||
self._test_util_class_version(volumeutils.VolumeUtils,
|
||||
volumeutilsv2.VolumeUtilsV2,
|
||||
lambda: utilsfactory.get_volumeutils(),
|
||||
True, 'force_volumeutils_v1', False)
|
||||
|
||||
def test_volumeutils_version_hyperv_2012_force_v1(self):
|
||||
self._test_volumeutils_version(True, True)
|
||||
self._test_util_class_version(volumeutils.VolumeUtils,
|
||||
volumeutilsv2.VolumeUtilsV2,
|
||||
lambda: utilsfactory.get_volumeutils(),
|
||||
True, 'force_volumeutils_v1', True)
|
||||
|
||||
def test_volumeutils_version_hyperv_2008R2(self):
|
||||
self._test_volumeutils_version(False, False)
|
||||
self._test_util_class_version(volumeutils.VolumeUtils,
|
||||
volumeutilsv2.VolumeUtilsV2,
|
||||
lambda: utilsfactory.get_volumeutils(),
|
||||
False, 'force_volumeutils_v1', False)
|
||||
|
||||
def test_attach_volume(self):
|
||||
instance_data = self._get_instance_data()
|
||||
|
|
|
@ -27,8 +27,7 @@ from nova.openstack.common.gettextutils import _
|
|||
from nova.openstack.common import jsonutils
|
||||
from nova.openstack.common import log as logging
|
||||
from nova.virt.hyperv import constants
|
||||
from nova.virt.hyperv import hostutils
|
||||
from nova.virt.hyperv import pathutils
|
||||
from nova.virt.hyperv import utilsfactory
|
||||
|
||||
CONF = cfg.CONF
|
||||
CONF.import_opt('my_ip', 'nova.netconf')
|
||||
|
@ -38,8 +37,8 @@ LOG = logging.getLogger(__name__)
|
|||
class HostOps(object):
|
||||
def __init__(self):
|
||||
self._stats = None
|
||||
self._hostutils = hostutils.HostUtils()
|
||||
self._pathutils = pathutils.PathUtils()
|
||||
self._hostutils = utilsfactory.get_hostutils()
|
||||
self._pathutils = utilsfactory.get_pathutils()
|
||||
|
||||
def _get_cpu_info(self):
|
||||
"""Get the CPU information.
|
||||
|
|
|
@ -26,8 +26,7 @@ from nova.openstack.common import excutils
|
|||
from nova.openstack.common.gettextutils import _
|
||||
from nova.openstack.common import log as logging
|
||||
from nova import utils
|
||||
from nova.virt.hyperv import pathutils
|
||||
from nova.virt.hyperv import vhdutils
|
||||
from nova.virt.hyperv import utilsfactory
|
||||
from nova.virt.hyperv import vmutils
|
||||
from nova.virt import images
|
||||
|
||||
|
@ -39,8 +38,8 @@ CONF.import_opt('use_cow_images', 'nova.virt.driver')
|
|||
|
||||
class ImageCache(object):
|
||||
def __init__(self):
|
||||
self._pathutils = pathutils.PathUtils()
|
||||
self._vhdutils = vhdutils.VHDUtils()
|
||||
self._pathutils = utilsfactory.get_pathutils()
|
||||
self._vhdutils = utilsfactory.get_vhdutils()
|
||||
|
||||
def _validate_vhd_image(self, vhd_path):
|
||||
try:
|
||||
|
|
|
@ -25,10 +25,8 @@ from oslo.config import cfg
|
|||
from nova.openstack.common import excutils
|
||||
from nova.openstack.common.gettextutils import _
|
||||
from nova.openstack.common import log as logging
|
||||
from nova.virt.hyperv import hostutils
|
||||
from nova.virt.hyperv import imagecache
|
||||
from nova.virt.hyperv import livemigrationutils
|
||||
from nova.virt.hyperv import pathutils
|
||||
from nova.virt.hyperv import utilsfactory
|
||||
from nova.virt.hyperv import volumeops
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
@ -50,12 +48,12 @@ def check_os_version_requirement(function):
|
|||
class LiveMigrationOps(object):
|
||||
def __init__(self):
|
||||
# Live migration is supported starting from Hyper-V Server 2012
|
||||
if hostutils.HostUtils().check_min_windows_version(6, 2):
|
||||
self._livemigrutils = livemigrationutils.LiveMigrationUtils()
|
||||
if utilsfactory.get_hostutils().check_min_windows_version(6, 2):
|
||||
self._livemigrutils = utilsfactory.get_livemigrationutils()
|
||||
else:
|
||||
self._livemigrutils = None
|
||||
|
||||
self._pathutils = pathutils.PathUtils()
|
||||
self._pathutils = utilsfactory.get_pathutils()
|
||||
self._volumeops = volumeops.VolumeOps()
|
||||
self._imagecache = imagecache.ImageCache()
|
||||
|
||||
|
|
|
@ -23,10 +23,8 @@ import os
|
|||
from nova.openstack.common import excutils
|
||||
from nova.openstack.common.gettextutils import _
|
||||
from nova.openstack.common import log as logging
|
||||
from nova.virt.hyperv import hostutils
|
||||
from nova.virt.hyperv import imagecache
|
||||
from nova.virt.hyperv import pathutils
|
||||
from nova.virt.hyperv import vhdutils
|
||||
from nova.virt.hyperv import utilsfactory
|
||||
from nova.virt.hyperv import vmops
|
||||
from nova.virt.hyperv import vmutils
|
||||
from nova.virt.hyperv import volumeops
|
||||
|
@ -36,10 +34,10 @@ LOG = logging.getLogger(__name__)
|
|||
|
||||
class MigrationOps(object):
|
||||
def __init__(self):
|
||||
self._hostutils = hostutils.HostUtils()
|
||||
self._vmutils = vmutils.VMUtils()
|
||||
self._vhdutils = vhdutils.VHDUtils()
|
||||
self._pathutils = pathutils.PathUtils()
|
||||
self._hostutils = utilsfactory.get_hostutils()
|
||||
self._vmutils = utilsfactory.get_vmutils()
|
||||
self._vhdutils = utilsfactory.get_vhdutils()
|
||||
self._pathutils = utilsfactory.get_pathutils()
|
||||
self._volumeops = volumeops.VolumeOps()
|
||||
self._vmops = vmops.VMOps()
|
||||
self._imagecache = imagecache.ImageCache()
|
||||
|
|
|
@ -26,9 +26,7 @@ from nova.compute import task_states
|
|||
from nova.image import glance
|
||||
from nova.openstack.common.gettextutils import _
|
||||
from nova.openstack.common import log as logging
|
||||
from nova.virt.hyperv import pathutils
|
||||
from nova.virt.hyperv import vhdutils
|
||||
from nova.virt.hyperv import vmutils
|
||||
from nova.virt.hyperv import utilsfactory
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
@ -36,9 +34,9 @@ LOG = logging.getLogger(__name__)
|
|||
|
||||
class SnapshotOps(object):
|
||||
def __init__(self):
|
||||
self._pathutils = pathutils.PathUtils()
|
||||
self._vmutils = vmutils.VMUtils()
|
||||
self._vhdutils = vhdutils.VHDUtils()
|
||||
self._pathutils = utilsfactory.get_pathutils()
|
||||
self._vmutils = utilsfactory.get_vmutils()
|
||||
self._vhdutils = utilsfactory.get_vhdutils()
|
||||
|
||||
def _save_glance_image(self, context, name, image_vhd_path):
|
||||
(glance_image_service,
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2013 Cloudbase Solutions Srl
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
from nova.openstack.common import log as logging
|
||||
from nova.virt.hyperv import hostutils
|
||||
from nova.virt.hyperv import livemigrationutils
|
||||
from nova.virt.hyperv import networkutils
|
||||
from nova.virt.hyperv import pathutils
|
||||
from nova.virt.hyperv import vhdutils
|
||||
from nova.virt.hyperv import vmutils
|
||||
from nova.virt.hyperv import volumeutils
|
||||
from nova.virt.hyperv import volumeutilsv2
|
||||
|
||||
hyper_opts = [
|
||||
cfg.BoolOpt('force_volumeutils_v1',
|
||||
default=False,
|
||||
help='Force V1 volume utility class'),
|
||||
]
|
||||
|
||||
CONF = cfg.CONF
|
||||
CONF.register_opts(hyper_opts, 'hyperv')
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _get_class(v1_class, v2_class, force_v1_flag):
|
||||
# V2 classes are supported starting from Hyper-V Server 2012 and
|
||||
# Windows Server 2012 (kernel version 6.2)
|
||||
if not force_v1_flag and get_hostutils().check_min_windows_version(6, 2):
|
||||
cls = v2_class
|
||||
else:
|
||||
cls = v1_class
|
||||
LOG.debug("Loading class: %(module_name)s.%(class_name)s",
|
||||
{'module_name': cls.__module__, 'class_name': cls.__name__})
|
||||
return cls
|
||||
|
||||
|
||||
def get_vmutils(host='.'):
|
||||
return vmutils.VMUtils(host)
|
||||
|
||||
|
||||
def get_vhdutils():
|
||||
return vhdutils.VHDUtils()
|
||||
|
||||
|
||||
def get_networkutils():
|
||||
return networkutils.NetworkUtils()
|
||||
|
||||
|
||||
def get_hostutils():
|
||||
return hostutils.HostUtils()
|
||||
|
||||
|
||||
def get_pathutils():
|
||||
return pathutils.PathUtils()
|
||||
|
||||
|
||||
def get_volumeutils():
|
||||
return _get_class(volumeutils.VolumeUtils, volumeutilsv2.VolumeUtilsV2,
|
||||
CONF.hyperv.force_volumeutils_v1)()
|
||||
|
||||
|
||||
def get_livemigrationutils():
|
||||
return livemigrationutils.LiveMigrationUtils()
|
|
@ -22,8 +22,7 @@ from oslo.config import cfg
|
|||
|
||||
from nova.openstack.common.gettextutils import _
|
||||
from nova.openstack.common import log as logging
|
||||
from nova.virt.hyperv import networkutils
|
||||
from nova.virt.hyperv import vmutils
|
||||
from nova.virt.hyperv import utilsfactory
|
||||
|
||||
hyperv_opts = [
|
||||
cfg.StrOpt('vswitch_name',
|
||||
|
@ -65,8 +64,8 @@ class HyperVNovaNetworkVIFDriver(HyperVBaseVIFDriver):
|
|||
"""Nova network VIF driver."""
|
||||
|
||||
def __init__(self):
|
||||
self._vmutils = vmutils.VMUtils()
|
||||
self._netutils = networkutils.NetworkUtils()
|
||||
self._vmutils = utilsfactory.get_vmutils()
|
||||
self._netutils = utilsfactory.get_networkutils()
|
||||
|
||||
def plug(self, instance, vif):
|
||||
vswitch_path = self._netutils.get_external_vswitch(
|
||||
|
|
|
@ -33,10 +33,8 @@ from nova.openstack.common import processutils
|
|||
from nova import utils
|
||||
from nova.virt import configdrive
|
||||
from nova.virt.hyperv import constants
|
||||
from nova.virt.hyperv import hostutils
|
||||
from nova.virt.hyperv import imagecache
|
||||
from nova.virt.hyperv import pathutils
|
||||
from nova.virt.hyperv import vhdutils
|
||||
from nova.virt.hyperv import utilsfactory
|
||||
from nova.virt.hyperv import vmutils
|
||||
from nova.virt.hyperv import volumeops
|
||||
|
||||
|
@ -75,10 +73,9 @@ class VMOps(object):
|
|||
}
|
||||
|
||||
def __init__(self):
|
||||
self._hostutils = hostutils.HostUtils()
|
||||
self._vmutils = vmutils.VMUtils()
|
||||
self._vhdutils = vhdutils.VHDUtils()
|
||||
self._pathutils = pathutils.PathUtils()
|
||||
self._vmutils = utilsfactory.get_vmutils()
|
||||
self._vhdutils = utilsfactory.get_vhdutils()
|
||||
self._pathutils = utilsfactory.get_pathutils()
|
||||
self._volumeops = volumeops.VolumeOps()
|
||||
self._imagecache = imagecache.ImageCache()
|
||||
self._vif_driver = None
|
||||
|
|
|
@ -27,10 +27,8 @@ from nova import exception
|
|||
from nova.openstack.common.gettextutils import _
|
||||
from nova.openstack.common import log as logging
|
||||
from nova.virt import driver
|
||||
from nova.virt.hyperv import hostutils
|
||||
from nova.virt.hyperv import utilsfactory
|
||||
from nova.virt.hyperv import vmutils
|
||||
from nova.virt.hyperv import volumeutils
|
||||
from nova.virt.hyperv import volumeutilsv2
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
@ -41,9 +39,6 @@ hyper_volumeops_opts = [
|
|||
cfg.IntOpt('volume_attach_retry_interval',
|
||||
default=5,
|
||||
help='Interval between volume attachment attempts, in seconds'),
|
||||
cfg.BoolOpt('force_volumeutils_v1',
|
||||
default=False,
|
||||
help='Force volumeutils v1'),
|
||||
]
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
@ -57,19 +52,12 @@ class VolumeOps(object):
|
|||
"""
|
||||
|
||||
def __init__(self):
|
||||
self._hostutils = hostutils.HostUtils()
|
||||
self._vmutils = vmutils.VMUtils()
|
||||
self._volutils = self._get_volume_utils()
|
||||
self._hostutils = utilsfactory.get_hostutils()
|
||||
self._vmutils = utilsfactory.get_vmutils()
|
||||
self._volutils = utilsfactory.get_volumeutils()
|
||||
self._initiator = None
|
||||
self._default_root_device = 'vda'
|
||||
|
||||
def _get_volume_utils(self):
|
||||
if(not CONF.hyperv.force_volumeutils_v1 and
|
||||
self._hostutils.check_min_windows_version(6, 2)):
|
||||
return volumeutilsv2.VolumeUtilsV2()
|
||||
else:
|
||||
return volumeutils.VolumeUtils()
|
||||
|
||||
def ebs_root_in_block_devices(self, block_device_info):
|
||||
return self._volutils.volume_in_mapping(self._default_root_device,
|
||||
block_device_info)
|
||||
|
|
Loading…
Reference in New Issue