'Builds a metadata object for instance devices, that maps the user
provided tag to the hypervisor assigned device address.'

def get_bdm_metadata(self, context, instance, block_device_info):

    bdm_obj_list = objects.BlockDeviceMappingList.get_by_instance_uuid(context, instance.uuid)
    bdm_obj_map = {bdm.device_name: bdm for bdm in bdm_obj_list}
    bdm_metadata = []
    for bdm in itertools.chain(block_device_info['block_device_mapping'], block_device_info['ephemerals'], [block_device_info['root_disk']]):
        device_name = (bdm.get('mount_device') or bdm.get('device_name'))
        bdm_obj = bdm_obj_map.get(device_name)
        if (bdm_obj and ('tag' in bdm_obj) and bdm_obj.tag):
            bus = self._get_device_bus(bdm)
            device = objects.DiskMetadata(bus=bus, serial=bdm_obj.volume_id, tags=[bdm_obj.tag])
            bdm_metadata.append(device)
    return bdm_metadata
