def run(self): """Add a new device to the device tree. :raise: StorageConfigurationError if the device cannot be created """ log.debug("Add device: %s", self._request) # Complete the device info. self._complete_device_factory_request(self._storage, self._request) try: # Trying to use a new container. self._add_device(self._storage, self._request, use_existing_container=False) return except InconsistentPVSectorSize as e: exception = e message = "\n\n".join([ _("Failed to add a device."), str(e).strip(), _(INCONSISTENT_SECTOR_SIZES_SUGGESTIONS) ]) except StorageError as e: exception = e message = str(e) try: # Trying to use an existing container. self._add_device(self._storage, self._request, use_existing_container=True) return except StorageError: # Ignore the second error. pass log.error("Failed to add a device: %s", message) raise StorageConfigurationError(message) from exception
def run(self): """Change a device in the device tree. :raise: StorageConfigurationError if the device cannot be changed """ log.debug("Change device: %s", self._request) # Nothing to do. Skip. if compare_data(self._request, self._original_request): log.debug("Nothing to change.") return try: # Change the container. self._rename_container() # Change or replace the device. if not self._device.raw_device.exists: self._replace_device() else: self._change_device() except StorageError as e: log.error("Failed to change a device: %s", e) raise StorageConfigurationError(str(e)) from e
def run(self): """Add a new device to the device tree. :raise: StorageConfigurationError if the device cannot be created """ log.debug("Add device: %s", self._request) # Complete the device info. self._complete_device_factory_request(self._storage, self._request) try: # Trying to use a new container. self._add_device(self._storage, self._request, use_existing_container=False) return except StorageError as e: # Keep the first error. error = e try: # Trying to use an existing container. self._add_device(self._storage, self._request, use_existing_container=True) return except StorageError: # Ignore the second error. pass log.error("Failed to add a device: %s", error) raise StorageConfigurationError(str(error))
def run(self): """Do the partitioning and handle the errors.""" try: self._run(self._storage) except (StorageError, KickstartParseError, ValueError) as e: log.error("Storage configuration has failed: %s", e) raise StorageConfigurationError(str(e)) from e except BootLoaderError as e: log.error("Bootloader configuration has failed: %s", e) raise BootloaderConfigurationError(str(e)) from e
def destroy_device(storage, device): """Destroy the given device in the storage model. :param storage: an instance of Blivet :param device: an instance of a device :raise: StorageConfigurationError in case of failure """ log.debug("Destroy device: %s", device.name) try: _destroy_device(storage, device) except (StorageError, ValueError) as e: log.error("Failed to destroy a device: %s", e) raise StorageConfigurationError(str(e)) from None
def _handle_storage_error(self, exception, message): """Handle the storage error. :param exception: an exception to handle :param message: an error message to use :raise: StorageConfigurationError """ log.error("Storage configuration has failed: %s", message) # Reset the boot loader configuration. # FIXME: Handle the boot loader reset in a better way. self._storage.bootloader.reset() raise StorageConfigurationError(message) from exception
def _reconfigure_namespace(self, namespace, mode, sector_size): """Reconfigure a namespace. :param namespace: a device name of the namespace :param mode: a new mode of the namespace :param sector_size: a size of the sector :raise: StorageConfigurationError in a case of failure """ try: nvdimm.reconfigure_namespace(namespace, mode, sector_size=sector_size) except Exception as e: # pylint: disable=broad-except raise StorageConfigurationError(str(e)) from e
def _configure_storage(self, storage, partitioning): """Configure the storage model. :param storage: an instance of Blivet :param partitioning: a partitioning executor :raises: StorageConfigurationError if the storage configuration fails :raises: BootloaderConfigurationError if the boot loader configuration fails """ try: do_kickstart_storage(storage=storage, partitioning=partitioning) except (StorageError, KickstartParseError, ValueError) as e: log.error("Storage configuration has failed: %s", e) raise StorageConfigurationError(str(e)) from e except BootLoaderError as e: log.error("Boot loader configuration has failed: %s", e) raise BootloaderConfigurationError(str(e)) from e
def reset_device(storage, device): """Reset the given device in the storage model. FIXME: Merge with destroy_device. :param storage: an instance of Blivet :param device: an instance of a device :raise: StorageConfigurationError in case of failure """ log.debug("Reset device: %s", device.name) try: if device.exists: # Revert changes done to an existing device. storage.reset_device(device) else: # Destroy a non-existing device. _destroy_device(storage, device) except (StorageError, ValueError) as e: log.exception("Failed to reset a device: %s", e) raise StorageConfigurationError(str(e)) from None
def _handle_storage_error(self, exception, message): """Handle the storage error.""" log.error("Failed to change a device: %s", message) raise StorageConfigurationError(message) from exception