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

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

    vifs = objects.VirtualInterfaceList.get_by_instance_uuid(context, instance['uuid'])
    metadata = []
    for vif in vifs:
        if (('tag' in vif) and vif.tag):
            device = objects.NetworkInterfaceMetadata(mac=vif.address, bus=objects.PCIDeviceBus(), tags=[vif.tag])
            metadata.append(device)
    block_device_mapping = virt_driver.block_device_info_get_mapping(block_device_info)
    if block_device_mapping:
        bdms = objects.BlockDeviceMappingList.get_by_instance_uuid(context, instance['uuid'])
        for bdm in bdms:
            if (('tag' in bdm) and bdm.tag):
                metadata.extend(self._prepare_disk_metadata(bdm))
    if metadata:
        return objects.InstanceDeviceMetadata(devices=metadata)
