Created
October 15, 2014 20:38
-
-
Save nelsnelson/542a6656791b937774bc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
198 def get_image_metadata(context, image_api, image_id_or_uri, instance): | |
199 image_system_meta = {} | |
200 | |
201 # Get the system metadata from the instance | |
202 system_meta = utils.instance_sys_meta(instance) | |
203 | |
204 # In case of boot from volume, image_id_or_uri may be None | |
205 if image_id_or_uri is not None: | |
206 # It is only safe to use cached image metadata when the requested image | |
207 # is the same as the instance's image. | |
208 if image_id_or_uri == instance.image_ref: | |
209 cached_image = utils.get_image_from_system_metadata(system_meta) | |
210 | |
211 # If the instance has inheritable properties, but no other | |
212 # image metadata cached in system metadata, we will get a | |
213 # dictionary with only the inheritable properties. In that case, | |
214 # the image still needs to be pulled from glance. | |
215 if cached_image and \ | |
216 ('properties' not in cached_image or len(cached_image) > 1): | |
217 return cached_image | |
218 | |
219 # If the base image is still available, get its metadata | |
220 try: | |
221 image = image_api.get(context, image_id_or_uri) | |
222 except (exception.ImageNotAuthorized, | |
223 exception.ImageNotFound, | |
224 exception.Invalid) as e: | |
225 LOG.warning(_LW("Can't access image %(image_id)s: %(error)s"), | |
226 {"image_id": image_id_or_uri, "error": e}, | |
227 instance=instance) | |
228 else: | |
229 flavor = flavors.extract_flavor(instance) | |
230 image_system_meta = utils.get_system_metadata_from_image(image, | |
231 flavor) | |
232 | |
233 # Merge the metadata from the instance with the image's, if any | |
234 system_meta.update(image_system_meta) | |
235 | |
236 # Convert the system metadata to image metadata | |
237 return utils.get_image_from_system_metadata(system_meta) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment