diff options
| author | Dmitry Tantsur <dtantsur@protonmail.com> | 2021-05-18 14:11:04 +0200 |
|---|---|---|
| committer | Dmitry Tantsur <dtantsur@protonmail.com> | 2021-05-18 14:45:13 +0200 |
| commit | 606e50031240e3f5bc29aa04e77e2c2f718667ee (patch) | |
| tree | b0afc62f0902172dd16222ae5f1e083022fd9622 /ironic_python_agent/extensions | |
| parent | d1844c61b1a419dc39aca41c9266fb65eaff78e4 (diff) | |
| download | ironic-python-agent-606e50031240e3f5bc29aa04e77e2c2f718667ee.tar.gz | |
Rewrite write_image.sh in Python
Change-Id: I0caa65561948f4e0934943a7a0d3a209701b5a59
Diffstat (limited to 'ironic_python_agent/extensions')
| -rw-r--r-- | ironic_python_agent/extensions/standby.py | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/ironic_python_agent/extensions/standby.py b/ironic_python_agent/extensions/standby.py index ab1414df..74f244e0 100644 --- a/ironic_python_agent/extensions/standby.py +++ b/ironic_python_agent/extensions/standby.py @@ -23,6 +23,7 @@ from ironic_lib import exception from oslo_concurrency import processutils from oslo_config import cfg from oslo_log import log +from oslo_utils import units import requests from ironic_python_agent import errors @@ -46,16 +47,6 @@ def _image_location(image_info): return os.path.join(tempfile.gettempdir(), image_info['id']) -def _path_to_script(script): - """Get the location of a script which ships with ironic-python-agent. - - :param script: The script name as a string. - :returns: The relative path to the script. - """ - cwd = os.path.dirname(os.path.realpath(__file__)) - return os.path.join(cwd, '..', script) - - def _download_with_proxy(image_info, url, image_id): """Opens a download stream for the given URL. @@ -203,14 +194,24 @@ def _write_whole_disk_image(image, image_info, device): :raises: ImageWriteError if the command to write the image encounters an error. """ - script = _path_to_script('shell/write_image.sh') - command = ['/bin/bash', script, image, device] + # FIXME(dtantsur): pass the real node UUID for logging + disk_utils.destroy_disk_metadata(device, '') + disk_utils.udev_settle() + + command = ['qemu-img', 'convert', + '-t', 'directsync', '-O', 'host_device', '-W', + image, device] LOG.info('Writing image with command: {}'.format(' '.join(command))) try: - stdout, stderr = utils.execute(*command) + # TODO(dtantsur): switch to disk_utils.convert_image when it supports + # -t and -W flags and defaults to 2 GiB memory limit. + limits = processutils.ProcessLimits(address_space=2048 * units.Mi) + utils.execute(*command, prlimit=limits) except processutils.ProcessExecutionError as e: raise errors.ImageWriteError(device, e.exit_code, e.stdout, e.stderr) + disk_utils.trigger_device_rescan(device) + def _write_image(image_info, device): """Writes an image to the specified device. |
