'Add trunk details to a port.'

@staticmethod
@resource_extend.extends([port_def.COLLECTION_NAME])
def _extend_port_trunk_details(port_res, port_db):

    if port_db.trunk_port:
        subports = {x.port_id: {'segmentation_id': x.segmentation_id, 'segmentation_type': x.segmentation_type, 'port_id': x.port_id} for x in port_db.trunk_port.sub_ports}
        core_plugin = directory.get_plugin()
        ports = core_plugin.get_ports(context.get_admin_context(), filters={'id': subports})
        for port in ports:
            subports[port['id']]['mac_address'] = port['mac_address']
        trunk_details = {'trunk_id': port_db.trunk_port.id, 'sub_ports': [x for x in subports.values()]}
        port_res['trunk_details'] = trunk_details
    return port_res
