Syncronises code with the nova driver

A few different commits merged in nova that changes slightly
the HyperVDriver. Those changes should be included in
compute-hyperv as well.

Most significant changes:
- usage of six.moves.range instead of xrange
- usage of six.iteritems
- VIFDriver using @abs.abstractmethod
- vhdutilsv2 get_internal_vhd_size_by_file_size updated docstring
- eventhandler VM State Suspended to transition map

Change-Id: I850ba905b2418fb8edb4fd92a8afc7f2f1eac646
This commit is contained in:
Claudiu Belu
2015-08-13 18:01:26 +03:00
parent da2ce98e7b
commit db3e8b1dbd
8 changed files with 31 additions and 22 deletions

View File

@@ -56,14 +56,8 @@ class InstanceEventHandler(object):
constants.HYPERV_VM_STATE_ENABLED: virtevent.EVENT_LIFECYCLE_STARTED,
constants.HYPERV_VM_STATE_DISABLED: virtevent.EVENT_LIFECYCLE_STOPPED,
constants.HYPERV_VM_STATE_PAUSED: virtevent.EVENT_LIFECYCLE_PAUSED,
# We ignore the suspended state transition because
# this cannot be handled by the manager at the moment.
#
# TODO(lpetrut): Uncomment this after this patch gets in:
# I0fad28025785e77ef32b88ff813f39000d9f9e35
#
# constants.HYPERV_VM_STATE_SUSPENDED:
# virtevent.EVENT_LIFECYCLE_SUSPENDED
constants.HYPERV_VM_STATE_SUSPENDED:
virtevent.EVENT_LIFECYCLE_SUSPENDED
}
def __init__(self, state_change_callback=None):

View File

@@ -242,8 +242,8 @@ class PathUtils(object):
return self._get_instances_sub_dir(dir_name, create_dir=True,
remove_dir=True)
def get_vm_console_log_paths(self, instance_name, remote_server=None):
instance_dir = self.get_instance_dir(instance_name,
def get_vm_console_log_paths(self, vm_name, remote_server=None):
instance_dir = self.get_instance_dir(vm_name,
remote_server)
console_log_path = os.path.join(instance_dir, 'console.log')
return console_log_path, console_log_path + '.1'

View File

@@ -124,13 +124,18 @@ class VHDUtilsV2(vhdutils.VHDUtils):
def get_internal_vhd_size_by_file_size(self, vhd_path,
new_vhd_file_size):
"""VHDX Size = Header (1 MB)
+ Log
+ Metadata Region
+ BAT
+ Payload Blocks
Chunk size = maximum number of bytes described by a SB block
= 2 ** 23 * LogicalSectorSize
"""Get internal size of a VHD according to new VHD file size.
VHDX Size = Header (1MB) + Log + Metadata Region + BAT + Payload Blocks
The chunk size is the maximum number of bytes described by a SB
block.
Chunk size = 2^{23} * LogicalSectorSize
:param str vhd_path: VHD file path
:param new_vhd_file_size: Size of the new VHD file.
:return: Internal VHD size according to new VHD file size.
"""
vhd_format = self.get_vhd_format(vhd_path)
if vhd_format == constants.DISK_FORMAT_VHD:

View File

@@ -14,6 +14,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import abc
from nova.i18n import _
from nova.network import model as network_model
from oslo_config import cfg
@@ -38,12 +40,15 @@ LOG = logging.getLogger(__name__)
class HyperVBaseVIFDriver(object):
@abc.abstractmethod
def plug(self, instance, vif):
pass
@abc.abstractmethod
def post_start(self, instance, vif):
pass
@abc.abstractmethod
def unplug(self, instance, vif):
pass

View File

@@ -29,6 +29,8 @@ from nova import exception
from oslo_config import cfg
from oslo_log import log as logging
from oslo_utils import uuidutils
import six
from six.moves import range
from hyperv.i18n import _, _LW
from hyperv.nova import constants
@@ -104,7 +106,7 @@ class VMUtils(object):
def __init__(self, host='.'):
self._enabled_states_map = {v: k for k, v in
self._vm_power_states_map.iteritems()}
six.iteritems(self._vm_power_states_map)}
if sys.platform == 'win32':
self._init_hyperv_wmi_conn(host)
self._conn_cimv2 = wmi.WMI(moniker='//%s/root/cimv2' % host)
@@ -750,7 +752,7 @@ class VMUtils(object):
used_slots = [int(self._get_disk_resource_address(disk))
for disk in attached_disks]
for slot in xrange(constants.SCSI_CONTROLLER_SLOTS_NUMBER):
for slot in range(constants.SCSI_CONTROLLER_SLOTS_NUMBER):
if slot not in used_slots:
return slot
raise HyperVException(_("Exceeded the maximum number of slots"))

View File

@@ -28,6 +28,7 @@ from oslo_config import cfg
from oslo_log import log as logging
from oslo_utils import excutils
from oslo_utils import units
from six.moves import range
from hyperv.i18n import _, _LE, _LW
from hyperv.nova import utilsfactory
@@ -332,7 +333,7 @@ class ISCSIVolumeDriver(object):
# The WMI query in get_device_number_for_target can incorrectly
# return no data when the system is under load. This issue can
# be avoided by adding a retry.
for i in xrange(CONF.hyperv.mounted_disk_query_retry_count):
for i in range(CONF.hyperv.mounted_disk_query_retry_count):
device_number = self._volutils.get_device_number_for_target(
target_iqn, target_lun)
if device_number in (None, -1):

View File

@@ -29,6 +29,7 @@ import time
from nova import utils
from oslo_config import cfg
from oslo_log import log as logging
from six.moves import range
from hyperv.i18n import _
from hyperv.nova import basevolumeutils
@@ -86,7 +87,7 @@ class VolumeUtils(basevolumeutils.BaseVolumeUtils):
if retry_count < 2:
retry_count = 2
for attempt in xrange(retry_count):
for attempt in range(retry_count):
try:
session_info = self.execute('iscsicli.exe', 'SessionList')
if session_info.find(target_iqn) == -1:

View File

@@ -27,6 +27,7 @@ if sys.platform == 'win32':
from nova import utils
from oslo_config import cfg
from oslo_log import log as logging
from six.moves import range
from hyperv.i18n import _
from hyperv.nova import basevolumeutils
@@ -78,7 +79,7 @@ class VolumeUtilsV2(basevolumeutils.BaseVolumeUtils):
if retry_count < 2:
retry_count = 2
for attempt in xrange(retry_count):
for attempt in range(retry_count):
target = self._conn_storage.query("SELECT * FROM MSFT_iSCSITarget "
"WHERE NodeAddress='%s' " %
target_iqn)