ironic.common.checksum_utils module¶
- class ironic.common.checksum_utils.TransferHelper(response, checksum_algo, expected_checksum)[source]¶
Bases:
object
- property bytes_transferred¶
Property value to return the number of bytes transferred.
- property checksum_matches¶
Verifies the checksum matches and returns True/False.
- property content_length¶
Property value to return the server indicated length.
- ironic.common.checksum_utils.compute_image_checksum(image_path, algorithm='md5')[source]¶
Compute checksum by given image path and algorithm.
- Parameters:
image_path – The path to the file to undergo checksum calculation.
algorithm – The checksum algorithm to utilize. Defaults to ‘md5’ due to historical support reasons in Ironic.
- Returns:
The calculated checksum value.
- Raises:
ValueError when the checksum algorithm is not supported by the system.
- ironic.common.checksum_utils.get_checksum_and_algo(instance_info)[source]¶
Get and return the image checksum and algo.
- Parameters:
instance_info – The node instance info, or newly updated/generated instance_info value.
- Returns:
A tuple containing two values, a checksum and algorithm, if available.
- ironic.common.checksum_utils.get_checksum_from_url(checksum, image_source)[source]¶
Gets a checksum value based upon a remote checksum URL file.
- Parameters:
checksum – The URL to the checksum URL content.
image_soource – The image source utilized to match with the contents of the URL payload file.
- Raises:
ImageDownloadFailed when the checksum file cannot be accessed or cannot be parsed.
- ironic.common.checksum_utils.is_checksum_url(checksum)[source]¶
Identify if checksum is not a url.
- Parameters:
checksum – The user supplied checksum value.
- Returns:
True if the checksum is a url, otherwise False.
- Raises:
ImageChecksumURLNotSupported should the conductor have this support disabled.
- ironic.common.checksum_utils.validate_checksum(path, checksum, checksum_algo=None)[source]¶
Validate image checksum.
- Parameters:
path – File path in the form of a string to calculate a checksum which is compared to the checksum field.
checksum – The supplied checksum value, a string, which will be compared to the file.
checksum_algo – The checksum type of the algorithm.
- Raises:
ImageChecksumError if the supplied data cannot be parsed or if the supplied value does not match the supplied checksum value.
- ironic.common.checksum_utils.validate_text_checksum(payload, digest)[source]¶
Compares the checksum of a payload versus the digest.
The purpose of this method is to take the payload string data, and compare it to the digest value of the supplied input. The use of this is to validate the the data in cases where we have data and need to compare it. Useful in API responses, such as those from an OCI Container Registry.
- Parameters:
payload – The supplied string with an encode method.
digest – The checksum value in digest form of algorithm:checksum.
- Raises:
ImageChecksumError when the response payload does not match the supplied digest.