def _check_resize_vhd(self, vhd_path, vhd_info, new_size): curr_size = vhd_info['MaxInternalSize'] if new_size < curr_size: raise vmutils.VHDResizeException(_("Cannot resize a VHD " "to a smaller size")) elif new_size > curr_size: self._resize_vhd(vhd_path, new_size)
def finish_migration(self, context, migration, instance, disk_info, network_info, image_meta, resize_instance=False, block_device_info=None, power_on=True): LOG.debug(_("finish_migration called"), instance=instance) instance_name = instance['name'] if self._volumeops.ebs_root_in_block_devices(block_device_info): root_vhd_path = None else: root_vhd_path = self._pathutils.get_vhd_path(instance_name) if not self._pathutils.exists(root_vhd_path): raise vmutils.HyperVException(_("Cannot find boot VHD " "file: %s") % root_vhd_path) vhd_info = self._vhdutils.get_vhd_info(root_vhd_path) src_base_disk_path = vhd_info.get("ParentPath") if src_base_disk_path: self._check_base_disk(context, instance, root_vhd_path, src_base_disk_path) if resize_instance: curr_size = vhd_info['MaxInternalSize'] new_size = instance['root_gb'] * 1024 ** 3 if new_size < curr_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) self._vmops.create_instance(instance, network_info, block_device_info, root_vhd_path) if power_on: self._vmops.power_on(instance)
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") % {'curr_root_gb': curr_root_gb, 'new_root_gb': new_root_gb})
def _check_target_flavor(self, instance, flavor): new_root_gb = flavor['root_gb'] curr_root_gb = instance.root_gb if new_root_gb < curr_root_gb: raise exception.InstanceFaultRollback( 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") % {'curr_root_gb': curr_root_gb, 'new_root_gb': new_root_gb}))
def _is_resize_needed(self, vhd_path, old_size, new_size, instance): if new_size < old_size: error_msg = _("Cannot resize a VHD to a smaller size, the" " original size is %(old_size)s, the" " newer size is %(new_size)s" ) % {'old_size': old_size, 'new_size': new_size} raise vmutils.VHDResizeException(error_msg) elif new_size > old_size: LOG.debug("Resizing VHD %(vhd_path)s to new " "size %(new_size)s" % {'new_size': new_size, 'vhd_path': vhd_path}, instance=instance) return True return False