'Returns the image name for a container, either directly from the
container\'s Image property or by inspecting the image entity if
the reference is its sha256 sum and not its name.
Result is cached for performance, no invalidation planned as image
churn is low on typical hosts.'

def image_name_extractor(self, co):

    if ('Image' in co):
        image = co.get('Image', '')
        if image.startswith('sha256:'):
            try:
                if (image in self._image_sha_to_name_mapping):
                    return self._image_sha_to_name_mapping[image]
                else:
                    image_spec = self.client.inspect_image(image)
                    try:
                        name = image_spec['RepoTags'][0]
                        self._image_sha_to_name_mapping[image] = name
                        return name
                    except (LookupError, TypeError) as e:
                        log.debug('Failed    finding    image    name    in    RepoTag,    trying    RepoDigests:    %s', e)
                    try:
                        name = image_spec['RepoDigests'][0]
                        name = name.split('@')[0]
                        self._image_sha_to_name_mapping[image] = name
                        return name
                    except (LookupError, TypeError) as e:
                        log.warning('Failed    finding    image    name    in    RepoTag    and    RepoDigests:    %s', e)
            except Exception:
                log.exception('Exception    getting    docker    image    name')
        else:
            return image
    return None
