ironic.common.image_service module

class ironic.common.image_service.BaseImageService[source]

Bases: object

Provides retrieval of disk images.

abstract download(image_href, image_file)[source]

Downloads image to specified location.

Parameters:
  • image_href – Image reference.

  • image_file – File object to write data to.

Raises:

exception.ImageRefValidationFailed.

Raises:

exception.ImageDownloadFailed.

abstract show(image_href)[source]

Get dictionary of image properties.

Parameters:

image_href – Image reference.

Raises:

exception.ImageRefValidationFailed.

Returns:

dictionary of image properties. It has three of them: ‘size’, ‘updated_at’ and ‘properties’. ‘updated_at’ attribute is a naive UTC datetime object.

abstract validate_href(image_href)[source]

Validate image reference.

Parameters:

image_href – Image reference.

Raises:

exception.ImageRefValidationFailed.

Returns:

Information needed to further operate with an image.

class ironic.common.image_service.FileImageService[source]

Bases: BaseImageService

Provides retrieval of disk images available locally on the conductor.

download(image_href, image_file)[source]

Downloads image to specified location.

Parameters:
  • image_href – Image reference.

  • image_file – File object to write data to.

Raises:

exception.ImageRefValidationFailed if source image file doesn’t exist.

Raises:

exception.ImageDownloadFailed if exceptions were raised while writing to file or creating hard link.

show(image_href)[source]

Get dictionary of image properties.

Parameters:

image_href – Image reference.

Raises:

exception.ImageRefValidationFailed if image file specified doesn’t exist.

Returns:

dictionary of image properties. It has three of them: ‘size’, ‘updated_at’ and ‘properties’. ‘updated_at’ attribute is a naive UTC datetime object.

validate_href(image_href)[source]

Validate local image reference.

Parameters:

image_href – Image reference.

Raises:

exception.ImageRefValidationFailed if source image file doesn’t exist, is in a blocked path, or is not in an allowed path.

Returns:

Path to image file if it exists and is allowed.

class ironic.common.image_service.HttpImageService[source]

Bases: BaseImageService

Provides retrieval of disk images using HTTP.

download(image_href, image_file)[source]

Downloads image to specified location.

Parameters:
  • image_href – Image reference.

  • image_file – File object to write data to.

Raises:

exception.ImageRefValidationFailed if GET request returned response code not equal to 200.

Raises:

exception.ImageDownloadFailed if: * IOError happened during file write; * GET request failed.

static gen_auth_from_conf_user_pass(image_href)[source]

This function is used to pass the credentials to the chosen

credential verifier and in case the verification is successful generate the compatible authentication object that will be used with the request(s). This function handles the authentication object generation for authentication strategies that are username+password based. Credentials are collected from the oslo.config framework.

Parameters:

image_href – href of the image that is being acted upon

Returns:

Authentication object used directly by the request library

Return type:

requests.auth.HTTPBasicAuth

static get(image_href)[source]

Downloads content and returns the response text.

Parameters:

image_href – Image reference.

Raises:

exception.ImageRefValidationFailed if GET request returned response code not equal to 200.

Raises:

exception.ImageDownloadFailed if: * IOError happened during file write; * GET request failed.

show(image_href)[source]

Get dictionary of image properties.

Parameters:

image_href – Image reference.

Raises:

exception.ImageRefValidationFailed if: * HEAD request failed; * HEAD request returned response code not equal to 200; * Content-Length header not found in response to HEAD request.

Returns:

dictionary of image properties. It has three of them: ‘size’, ‘updated_at’ and ‘properties’. ‘updated_at’ attribute is a naive UTC datetime object.

validate_href(image_href, secret=False)[source]

Validate HTTP image reference.

Parameters:
  • image_href – Image reference.

  • secret – Specify if image_href being validated should not be shown in exception message.

Raises:

exception.ImageRefValidationFailed if HEAD request failed or returned response code not equal to 200.

Raises:

exception.ImageRefIsARedirect if the supplied URL is a redirect to a different URL. The caller may be able to handle this.

Returns:

Response to HEAD request.

static verify_basic_auth_cred_format(image_href, user=None, password=None)[source]

Verify basic auth credentials used for image head request.

Parameters:
  • user – auth username

  • password – auth password

Raises:

exception.ImageRefValidationFailed if the credentials are not present

ironic.common.image_service.get_image_service(image_href, client=None, context=None)[source]

Get image service instance to download the image.

Parameters:
  • image_href – String containing href to get image service for.

  • client – Glance client to be used for download, used only if image_href is Glance href.

  • context – request context, used only if image_href is Glance href.

Raises:

exception.ImageRefValidationFailed if no image service can handle specified href.

Returns:

Instance of an image service class that is able to download specified image.

ironic.common.image_service.is_host_auth_permitted(image_href)[source]

Check if credentials should be sent to the host in image_href.

When [deploy]image_server_auth_hosts is configured, the image URL’s hostname must match an entry in the list for credentials to be sent.

When [deploy]image_server_auth_hosts is not configured, the behavior depends on [deploy]image_server_auth_permit_unknown_hosts:

  • True (default): credentials are sent to all hosts, preserving backwards-compatible behavior.

  • False: credentials are not sent to any host unless it is listed in image_server_auth_hosts.

Schemes which do not transmit credentials to a remote host, such as file:// and bare references without a scheme (e.g. a Glance image UUID), are always permitted. Remote schemes which may carry credentials, namely http, https and oci, are subject to host filtering.

Entries in the list may be exact hostnames or domain suffixes prefixed with a dot. For example, .example.com matches images.example.com and backup.example.com but does not match the bare example.com.

Parameters:

image_href – URL of the image being accessed.

Returns:

True if credentials may be sent, False otherwise.