"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "ironic/drivers/modules/image_utils.py" between
ironic-16.0.2.tar.gz and ironic-16.0.3.tar.gz

About: OpenStack Ironic (Optional Service: Bare-Metal Provisioning) aims to provision bare metal machines instead of virtual machines, forked from the Nova baremetal driver.
The "Victoria" series (latest release).

image_utils.py  (ironic-16.0.2):image_utils.py  (ironic-16.0.3)
skipping to change at line 25 skipping to change at line 25
import functools import functools
import json import json
import os import os
import shutil import shutil
import tempfile import tempfile
from urllib import parse as urlparse from urllib import parse as urlparse
from ironic_lib import utils as ironic_utils from ironic_lib import utils as ironic_utils
from oslo_log import log from oslo_log import log
from oslo_serialization import base64
from ironic.common import exception from ironic.common import exception
from ironic.common.i18n import _ from ironic.common.i18n import _
from ironic.common import images from ironic.common import images
from ironic.common import swift from ironic.common import swift
from ironic.conf import CONF from ironic.conf import CONF
from ironic.drivers.modules import boot_mode_utils from ironic.drivers.modules import boot_mode_utils
from ironic.drivers.modules import deploy_utils from ironic.drivers.modules import deploy_utils
LOG = log.getLogger(__name__) LOG = log.getLogger(__name__)
skipping to change at line 284 skipping to change at line 283
"""Deletes the floppy image if it was created for the node. """Deletes the floppy image if it was created for the node.
:param task: an ironic node object. :param task: an ironic node object.
""" """
floppy_object_name = _get_floppy_image_name(task.node) floppy_object_name = _get_floppy_image_name(task.node)
img_handler = ImageHandler(task.node.driver) img_handler = ImageHandler(task.node.driver)
img_handler.unpublish_image(floppy_object_name) img_handler.unpublish_image(floppy_object_name)
def _prepare_iso_image(task, kernel_href, ramdisk_href, def _prepare_iso_image(task, kernel_href, ramdisk_href,
bootloader_href=None, configdrive=None, bootloader_href=None, root_uuid=None, params=None,
root_uuid=None, params=None, base_iso=None): base_iso=None, inject_files=None):
"""Prepare an ISO to boot the node. """Prepare an ISO to boot the node.
Build bootable ISO out of `kernel_href` and `ramdisk_href` (and Build bootable ISO out of `kernel_href` and `ramdisk_href` (and
`bootloader` if it's UEFI boot), then push built image up to Swift and `bootloader` if it's UEFI boot), then push built image up to Swift and
return a temporary URL. return a temporary URL.
If `configdrive` is specified it will be eventually written onto
the boot ISO image.
:param task: a TaskManager instance containing the node to act on. :param task: a TaskManager instance containing the node to act on.
:param kernel_href: URL or Glance UUID of the kernel to use :param kernel_href: URL or Glance UUID of the kernel to use
:param ramdisk_href: URL or Glance UUID of the ramdisk to use :param ramdisk_href: URL or Glance UUID of the ramdisk to use
:param bootloader_href: URL or Glance UUID of the EFI bootloader :param bootloader_href: URL or Glance UUID of the EFI bootloader
image to use when creating UEFI bootbable ISO image to use when creating UEFI bootbable ISO
:param configdrive: URL to or a compressed blob of a ISO9660 or
FAT-formatted OpenStack config drive image. This image will be
written onto the built ISO image. Optional.
:param root_uuid: optional uuid of the root partition. :param root_uuid: optional uuid of the root partition.
:param params: a dictionary containing 'parameter name'->'value' :param params: a dictionary containing 'parameter name'->'value'
mapping to be passed to kernel command line. mapping to be passed to kernel command line.
:param inject_files: Mapping of local source file paths to their location
on the final ISO image.
:returns: bootable ISO HTTP URL. :returns: bootable ISO HTTP URL.
:raises: MissingParameterValue, if any of the required parameters are :raises: MissingParameterValue, if any of the required parameters are
missing. missing.
:raises: InvalidParameterValue, if any of the parameters have invalid :raises: InvalidParameterValue, if any of the parameters have invalid
value. value.
:raises: ImageCreationFailed, if creating ISO image failed. :raises: ImageCreationFailed, if creating ISO image failed.
""" """
if (not kernel_href or not ramdisk_href) and not base_iso: if (not kernel_href or not ramdisk_href) and not base_iso:
raise exception.InvalidParameterValue(_( raise exception.InvalidParameterValue(_(
"Unable to find kernel, ramdisk for " "Unable to find kernel, ramdisk for "
skipping to change at line 356 skipping to change at line 351
"", {'node': task.node.uuid, "", {'node': task.node.uuid,
'boot_mode': boot_mode, 'boot_mode': boot_mode,
'kernel_href': kernel_href, 'kernel_href': kernel_href,
'ramdisk_href': ramdisk_href, 'ramdisk_href': ramdisk_href,
'bootloader_href': bootloader_href, 'bootloader_href': bootloader_href,
'params': kernel_params}) 'params': kernel_params})
with tempfile.NamedTemporaryFile( with tempfile.NamedTemporaryFile(
dir=CONF.tempdir, suffix='.iso') as boot_fileobj: dir=CONF.tempdir, suffix='.iso') as boot_fileobj:
with tempfile.NamedTemporaryFile( boot_iso_tmp_file = boot_fileobj.name
dir=CONF.tempdir, suffix='.img') as cfgdrv_fileobj: images.create_boot_iso(
task.context, boot_iso_tmp_file,
configdrive_href = configdrive kernel_href, ramdisk_href,
esp_image_href=bootloader_href,
# FIXME(TheJulia): This is treated as conditional with root_uuid=root_uuid,
# a base_iso as the intent, eventually, is to support kernel_params=kernel_params,
# injection into the supplied image. boot_mode=boot_mode,
base_iso=base_iso,
if configdrive and not base_iso: inject_files=inject_files)
parsed_url = urlparse.urlparse(configdrive)
if not parsed_url.scheme:
cfgdrv_blob = base64.decode_as_bytes(configdrive)
with open(cfgdrv_fileobj.name, 'wb') as f:
f.write(cfgdrv_blob)
configdrive_href = urlparse.urlunparse(
('file', '', cfgdrv_fileobj.name, '', '', ''))
LOG.debug("Built configdrive out of configdrive blob "
"for node %(node)s", {'node': task.node.uuid})
boot_iso_tmp_file = boot_fileobj.name
images.create_boot_iso(
task.context, boot_iso_tmp_file,
kernel_href, ramdisk_href,
esp_image_href=bootloader_href,
configdrive_href=configdrive_href,
root_uuid=root_uuid,
kernel_params=kernel_params,
boot_mode=boot_mode,
base_iso=base_iso)
iso_object_name = _get_iso_image_name(task.node) iso_object_name = _get_iso_image_name(task.node)
image_url = img_handler.publish_image( image_url = img_handler.publish_image(
boot_iso_tmp_file, iso_object_name) boot_iso_tmp_file, iso_object_name)
LOG.debug("Created ISO %(name)s in object store for node %(node)s, " LOG.debug("Created ISO %(name)s in object store for node %(node)s, "
"exposed as temporary URL " "exposed as temporary URL "
"%(url)s", {'node': task.node.uuid, "%(url)s", {'node': task.node.uuid,
'name': iso_object_name, 'name': iso_object_name,
'url': image_url}) 'url': image_url})
return image_url return image_url
def _find_param(param_str, param_dict): def _find_param(param_str, param_dict):
skipping to change at line 420 skipping to change at line 392
def prepare_deploy_iso(task, params, mode, d_info): def prepare_deploy_iso(task, params, mode, d_info):
"""Prepare deploy or rescue ISO image """Prepare deploy or rescue ISO image
Build bootable ISO out of Build bootable ISO out of
`[driver_info]/deploy_kernel`/`[driver_info]/deploy_ramdisk` or `[driver_info]/deploy_kernel`/`[driver_info]/deploy_ramdisk` or
`[driver_info]/rescue_kernel`/`[driver_info]/rescue_ramdisk` `[driver_info]/rescue_kernel`/`[driver_info]/rescue_ramdisk`
and `[driver_info]/bootloader`, then push built image up to Glance and `[driver_info]/bootloader`, then push built image up to Glance
and return temporary Swift URL to the image. and return temporary Swift URL to the image.
If network interface supplies network configuration (`network_data`), If network interface supplies network configuration (`network_data`),
a new `configdrive` will be created with `network_data.json` inside, a `network_data.json` will be written into an appropriate location on
and eventually written down onto the boot ISO. the final ISO.
:param task: a TaskManager instance containing the node to act on. :param task: a TaskManager instance containing the node to act on.
:param params: a dictionary containing 'parameter name'->'value' :param params: a dictionary containing 'parameter name'->'value'
mapping to be passed to kernel command line. mapping to be passed to kernel command line.
:param mode: either 'deploy' or 'rescue'. :param mode: either 'deploy' or 'rescue'.
:param d_info: Deployment information of the node :param d_info: Deployment information of the node
:returns: bootable ISO HTTP URL. :returns: bootable ISO HTTP URL.
:raises: MissingParameterValue, if any of the required parameters are :raises: MissingParameterValue, if any of the required parameters are
missing. missing.
:raises: InvalidParameterValue, if any of the parameters have invalid :raises: InvalidParameterValue, if any of the parameters have invalid
skipping to change at line 451 skipping to change at line 423
ramdisk_href = _find_param(ramdisk_str, d_info) ramdisk_href = _find_param(ramdisk_str, d_info)
bootloader_href = _find_param(bootloader_str, d_info) bootloader_href = _find_param(bootloader_str, d_info)
# TODO(TheJulia): At some point we should support something like # TODO(TheJulia): At some point we should support something like
# boot_iso for the deploy interface, perhaps when we support config # boot_iso for the deploy interface, perhaps when we support config
# injection. # injection.
prepare_iso_image = functools.partial( prepare_iso_image = functools.partial(
_prepare_iso_image, task, kernel_href, ramdisk_href, _prepare_iso_image, task, kernel_href, ramdisk_href,
bootloader_href=bootloader_href, params=params) bootloader_href=bootloader_href, params=params)
inject_files = {}
network_data = task.driver.network.get_node_network_data(task) network_data = task.driver.network.get_node_network_data(task)
if network_data: if network_data:
LOG.debug('Injecting custom network data for node %s', LOG.debug('Injecting custom network data for node %s',
task.node.uuid) task.node.uuid)
with tempfile.NamedTemporaryFile(dir=CONF.tempdir, network_data = json.dumps(network_data, indent=2).encode('utf-8')
suffix='.iso') as metadata_fileobj: inject_files[network_data] = (
'openstack/latest/network_data.json'
with open(metadata_fileobj.name, 'w') as f: )
json.dump(network_data, f, indent=2)
files_info = {
metadata_fileobj.name: 'openstack/latest/network_data.json'
}
with tempfile.NamedTemporaryFile(
dir=CONF.tempdir, suffix='.img') as cfgdrv_fileobj:
images.create_vfat_image(cfgdrv_fileobj.name, files_info)
configdrive_href = urlparse.urlunparse(
('file', '', cfgdrv_fileobj.name, '', '', ''))
LOG.debug("Built configdrive %(name)s out of network data "
"for node %(node)s", {'name': configdrive_href,
'node': task.node.uuid})
return prepare_iso_image(configdrive=configdrive_href)
return prepare_iso_image() return prepare_iso_image(inject_files=inject_files)
def prepare_boot_iso(task, d_info, root_uuid=None): def prepare_boot_iso(task, d_info, root_uuid=None):
"""Prepare boot ISO image """Prepare boot ISO image
Build bootable ISO out of `[instance_info]/kernel`, Build bootable ISO out of `[instance_info]/kernel`,
`[instance_info]/ramdisk` and `[driver_info]/bootloader` if present. `[instance_info]/ramdisk` and `[driver_info]/bootloader` if present.
Otherwise, read `kernel_id` and `ramdisk_id` from Otherwise, read `kernel_id` and `ramdisk_id` from
`[instance_info]/image_source` Glance image metadata. `[instance_info]/image_source` Glance image metadata.
Push produced ISO image up to Glance and return temporary Swift Push produced ISO image up to Glance and return temporary Swift
 End of changes. 12 change blocks. 
71 lines changed or deleted 25 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)