summaryrefslogtreecommitdiffstats
path: root/nova/virt
diff options
context:
space:
mode:
authorAlessandro Pilotti <ap@pilotti.it>2013-05-07 01:04:22 +0300
committerAlessandro Pilotti <ap@pilotti.it>2013-05-08 01:15:30 +0300
commitd50d69cbd807dfb67427b39e03fd4156479c1997 (patch)
tree4bacc9070f6be88fb4524409dcbd882bda735682 /nova/virt
parent7be2809c67aa0658d7d4c6666a754b5334d96c11 (diff)
Adds instance root disk size checks during resize
Fixes bug: #1163844 The Hyper-V driver does not support disk resizes to a smaller size. This patch verifies the disk size compatibility before the migration starts in order to avoid data losses. Change-Id: Ie99bf8779d583e97b911c9a136cee1bca9a1ecdc
Diffstat (limited to 'nova/virt')
-rw-r--r--nova/virt/hyperv/migrationops.py18
-rw-r--r--nova/virt/hyperv/vmutils.py8
2 files changed, 24 insertions, 2 deletions
diff --git a/nova/virt/hyperv/migrationops.py b/nova/virt/hyperv/migrationops.py
index 07bf453e5..ff8651efe 100644
--- a/nova/virt/hyperv/migrationops.py
+++ b/nova/virt/hyperv/migrationops.py
@@ -95,11 +95,25 @@ class MigrationOps(object):
LOG.exception(ex)
LOG.error(_("Cannot cleanup migration files"))
+ def _check_target_instance_type(self, instance, instance_type):
+ new_root_gb = instance_type['root_gb']
+ curr_root_gb = instance['root_gb']
+
+ if new_root_gb < curr_root_gb:
+ raise vmutils.VHDResizeException(_("Cannot resize the root disk "
+ "to a smaller size. Current "
+ "size: %(curr_root_gb)s GB. "
+ "Requested size: "
+ "%(new_root_gb)s GB") %
+ locals())
+
def migrate_disk_and_power_off(self, context, instance, dest,
instance_type, network_info,
block_device_info=None):
LOG.debug(_("migrate_disk_and_power_off called"), instance=instance)
+ self._check_target_instance_type(instance, instance_type)
+
self._vmops.power_off(instance)
instance_name = instance["name"]
@@ -218,8 +232,8 @@ class MigrationOps(object):
curr_size = vhd_info['MaxInternalSize']
new_size = instance['root_gb'] * 1024 ** 3
if new_size < curr_size:
- raise vmutils.HyperVException(_("Cannot resize a VHD to a "
- "smaller size"))
+ raise vmutils.VHDResizeException(_("Cannot resize a VHD "
+ "to a smaller size"))
elif new_size > curr_size:
self._resize_vhd(root_vhd_path, new_size)
diff --git a/nova/virt/hyperv/vmutils.py b/nova/virt/hyperv/vmutils.py
index 45fea329d..680ec2d61 100644
--- a/nova/virt/hyperv/vmutils.py
+++ b/nova/virt/hyperv/vmutils.py
@@ -37,11 +37,19 @@ CONF = cfg.CONF
LOG = logging.getLogger(__name__)
+# TODO(alexpilotti): Move the exceptions to a separate module
+# TODO(alexpilotti): Add more domain exceptions
class HyperVException(exception.NovaException):
def __init__(self, message=None):
super(HyperVException, self).__init__(message)
+# TODO(alexpilotti): Add a storage exception base class
+class VHDResizeException(HyperVException):
+ def __init__(self, message=None):
+ super(HyperVException, self).__init__(message)
+
+
class VMUtils(object):
def __init__(self, host='.'):